Check-in [08662daa7c]
Overview
Comment:Added start of initial patches to TCC needed for integration with Tcl
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 08662daa7c360c3e188d4bfb06a57658e4ed850a
User & Date: rkeene on 2014-05-02 00:54:04
Other Links: manifest | tags
Context
2014-05-02
01:17
More work towards supporting Tcl I/O from TCC check-in: eebb3855d6 user: rkeene tags: trunk
00:54
Added start of initial patches to TCC needed for integration with Tcl check-in: 08662daa7c user: rkeene tags: trunk
2014-05-01
23:50
Wrapping some Tcl-specific changes to TCC into TclTCC check-in: d6a2d38950 user: rkeene tags: trunk
Changes

Modified build/pre.sh from [a68c94db4c] to [a84ae705c9].

    26     26   	fi
    27     27   
    28     28   	mv new "tcc-${tcc_version}.tar.bz2"
    29     29   
    30     30   	bzip2 -dc "tcc-${tcc_version}.tar.bz2" | tar -xf -
    31     31   
    32     32   	rm -f "tcc-${tcc_version}.tar.bz2"
           33  +
           34  +	## Apply patches
           35  +	for patchfile in ../build/tcc-patches/${tcc_version}/*.diff; do
           36  +		( cd * && patch -p1 ) < "${patchfile}"
           37  +	done
    33     38   
    34     39   	rm -rf ../tcc
    35     40   	mkdir ../tcc || exit 1
    36     41   	mv */* ../tcc/
    37     42   )
    38     43   rm -rf __TMP__

Added build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff version [e03734effa].

            1  +--- tcc-0.9.26.orig/configure	2013-02-15 08:24:00.000000000 -0600
            2  ++++ tcc-0.9.26-1tcl/configure	2014-05-01 19:50:10.103740647 -0500
            3  +@@ -43,6 +43,7 @@
            4  + tcc_libpaths=""
            5  + tcc_crtprefix=""
            6  + tcc_elfinterp=""
            7  ++tcc_tcl_path=""
            8  + tcc_lddir=
            9  + confvars=
           10  + 
           11  +@@ -154,6 +155,8 @@
           12  +   ;;
           13  +   --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
           14  +   ;;
           15  ++  --with-tcl=*) tcc_tcl_path=`echo $opt | cut -d '=' -f 2-`
           16  ++  ;;
           17  +   --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
           18  +   ;;
           19  +   --enable-gprof) gprof="yes"
           20  +@@ -278,6 +281,7 @@
           21  +   --libpaths=...           specify system library paths, colon separated
           22  +   --crtprefix=...          specify locations of crt?.o, colon separated
           23  +   --elfinterp=...          specify elf interpreter
           24  ++  --with-tcl=...           specify path to Tcl
           25  + EOF
           26  + #echo "NOTE: The object files are build at the place where configure is launched"
           27  + exit 1
           28  +@@ -339,6 +343,25 @@
           29  +   esac
           30  + fi
           31  + 
           32  ++print_tcl_defs() {
           33  ++	(
           34  ++		tclConfig="$1"
           35  ++		. "${tclConfig}"
           36  ++		LDFLAGS="$LDFLAGS $TCL_LIB_SPEC $TCL_LIBS"
           37  ++		CFLAGS="$CFLAGS $TCL_INCLUDE_SPEC -DHAVE_TCL_H=1"
           38  ++		set | egrep '^(CFLAGS|LDFLAGS)='
           39  ++	)
           40  ++}
           41  ++
           42  ++if [ -n "${tcc_tcl_path}" ]; then
           43  ++	for tcc_tcl_path_file in ${tcc_tcl_path}/{,lib,lib64}/tclConfig.sh; do
           44  ++		if [ -f "${tcc_tcl_path_file}" ]; then
           45  ++			eval `print_tcl_defs "${tcc_tcl_path_file}"`
           46  ++			break
           47  ++		fi
           48  ++	done
           49  ++fi
           50  ++
           51  + cat <<EOF
           52  + Binary  directory   $bindir
           53  + TinyCC directory    $tccdir
           54  +--- tcc-0.9.26.orig/tcc.h	2013-02-15 08:24:00.000000000 -0600
           55  ++++ tcc-0.9.26-1tcl/tcc.h	2014-05-01 19:50:24.973630534 -0500
           56  +@@ -23,6 +23,9 @@
           57  + 
           58  + #define _GNU_SOURCE
           59  + #include "config.h"
           60  ++#ifdef HAVE_TCL_H
           61  ++#  include <tcl.h>
           62  ++#endif
           63  + 
           64  + #ifdef CONFIG_TCCBOOT
           65  + #include "tccboot.h"

Added build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff version [cee6b5e440].

            1  +diff -uNr tcc-0.9.26.orig/libtcc.c tcc-0.9.26-1tclio/libtcc.c
            2  +--- tcc-0.9.26.orig/libtcc.c	2013-02-15 08:24:00.000000000 -0600
            3  ++++ tcc-0.9.26-1tclio/libtcc.c	2014-05-01 19:32:19.383657630 -0500
            4  +@@ -669,7 +669,7 @@
            5  +     bf->line_num = 1;
            6  +     bf->ifndef_macro = 0;
            7  +     bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
            8  +-    bf->fd = -1;
            9  ++    bf->fd = NULL;
           10  +     bf->prev = file;
           11  +     file = bf;
           12  + }
           13  +@@ -677,26 +677,35 @@
           14  + ST_FUNC void tcc_close(void)
           15  + {
           16  +     BufferedFile *bf = file;
           17  +-    if (bf->fd > 0) {
           18  +-        close(bf->fd);
           19  ++    if (bf->fd != NULL) {
           20  ++        Tcl_Close(NULL,bf->fd);
           21  +         total_lines += bf->line_num;
           22  +     }
           23  +     file = bf->prev;
           24  +     tcc_free(bf);
           25  + }
           26  + 
           27  +-ST_FUNC int tcc_open(TCCState *s1, const char *filename)
           28  ++ST_FUNC Tcl_Channel tcc_open(TCCState *s1, const char *filename)
           29  + {
           30  +-    int fd;
           31  +-    if (strcmp(filename, "-") == 0)
           32  +-        fd = 0, filename = "stdin";
           33  +-    else
           34  +-        fd = open(filename, O_RDONLY | O_BINARY);
           35  +-    if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
           36  +-        printf("%s %*s%s\n", fd < 0 ? "nf":"->",
           37  ++    Tcl_Channel fd;
           38  ++    Tcl_Obj *path;
           39  ++
           40  ++    if (strcmp(filename, "-") == 0) {
           41  ++        fd = Tcl_GetStdChannel(TCL_STDIN);
           42  ++        filename = "stdin";
           43  ++    } else {
           44  ++        path = Tcl_NewStringObj(filename,-1);
           45  ++        Tcl_IncrRefCount(path);
           46  ++        fd = Tcl_FSOpenFileChannel(NULL,path, "r", 0);
           47  ++        Tcl_DecrRefCount(path);
           48  ++    }
           49  ++
           50  ++    if ((s1->verbose == 2 && fd != NULL) || s1->verbose == 3)
           51  ++        printf("%s %*s%s\n", fd == NULL ? "nf":"->",
           52  +                (int)(s1->include_stack_ptr - s1->include_stack), "", filename);
           53  +-    if (fd < 0)
           54  +-        return -1;
           55  ++    if (fd == NULL) {
           56  ++        return NULL;
           57  ++    }
           58  + 
           59  +     tcc_open_bf(s1, filename, 0);
           60  +     file->fd = fd;
           61  +@@ -1099,7 +1108,8 @@
           62  + {
           63  +     const char *ext;
           64  +     ElfW(Ehdr) ehdr;
           65  +-    int fd, ret, size;
           66  ++    int ret, size;
           67  ++    Tcl_Channel ret_chan, fd;
           68  + 
           69  +     /* find source file type with extension */
           70  +     ext = tcc_fileextension(filename);
           71  +@@ -1113,11 +1123,11 @@
           72  + #endif
           73  + 
           74  +     /* open the file */
           75  +-    ret = tcc_open(s1, filename);
           76  +-    if (ret < 0) {
           77  ++    ret_chan = tcc_open(s1, filename);
           78  ++    if (ret_chan == NULL) {
           79  +         if (flags & AFF_PRINT_ERROR)
           80  +             tcc_error_noabort("file '%s' not found", filename);
           81  +-        return ret;
           82  ++        return -1;
           83  +     }
           84  + 
           85  +     /* update target deps */
           86  +@@ -1151,8 +1161,8 @@
           87  + 
           88  +     fd = file->fd;
           89  +     /* assume executable format: auto guess file type */
           90  +-    size = read(fd, &ehdr, sizeof(ehdr));
           91  +-    lseek(fd, 0, SEEK_SET);
           92  ++    size = Tcl_Read(fd, (unsigned char *)&ehdr, sizeof(ehdr));
           93  ++    Tcl_Seek(fd, 0, SEEK_SET);
           94  +     if (size <= 0) {
           95  +         tcc_error_noabort("could not read header");
           96  +         goto the_end;
           97  +diff -uNr tcc-0.9.26.orig/tcc.h tcc-0.9.26-1tclio/tcc.h
           98  +--- tcc-0.9.26.orig/tcc.h	2013-02-15 08:24:00.000000000 -0600
           99  ++++ tcc-0.9.26-1tclio/tcc.h	2014-05-01 19:26:10.847265869 -0500
          100  +@@ -429,7 +429,7 @@
          101  + typedef struct BufferedFile {
          102  +     uint8_t *buf_ptr;
          103  +     uint8_t *buf_end;
          104  +-    int fd;
          105  ++    Tcl_Channel fd;
          106  +     struct BufferedFile *prev;
          107  +     int line_num;    /* current line number - here to simplify code */
          108  +     int ifndef_macro;  /* #ifndef macro / #endif search */
          109  +@@ -1045,7 +1045,7 @@
          110  + ST_FUNC Sym *global_identifier_push(int v, int t, int c);
          111  + 
          112  + ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
          113  +-ST_FUNC int tcc_open(TCCState *s1, const char *filename);
          114  ++ST_FUNC Tcl_Channel tcc_open(TCCState *s1, const char *filename);
          115  + ST_FUNC void tcc_close(void);
          116  + 
          117  + ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);