Index: build/pre.sh ================================================================== --- build/pre.sh +++ build/pre.sh @@ -28,11 +28,16 @@ mv new "tcc-${tcc_version}.tar.bz2" bzip2 -dc "tcc-${tcc_version}.tar.bz2" | tar -xf - rm -f "tcc-${tcc_version}.tar.bz2" + + ## Apply patches + for patchfile in ../build/tcc-patches/${tcc_version}/*.diff; do + ( cd * && patch -p1 ) < "${patchfile}" + done rm -rf ../tcc mkdir ../tcc || exit 1 mv */* ../tcc/ ) rm -rf __TMP__ ADDED build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff ================================================================== --- build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff +++ build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff @@ -0,0 +1,65 @@ +--- tcc-0.9.26.orig/configure 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tcl/configure 2014-05-01 19:50:10.103740647 -0500 +@@ -43,6 +43,7 @@ + tcc_libpaths="" + tcc_crtprefix="" + tcc_elfinterp="" ++tcc_tcl_path="" + tcc_lddir= + confvars= + +@@ -154,6 +155,8 @@ + ;; + --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2` + ;; ++ --with-tcl=*) tcc_tcl_path=`echo $opt | cut -d '=' -f 2-` ++ ;; + --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` + ;; + --enable-gprof) gprof="yes" +@@ -278,6 +281,7 @@ + --libpaths=... specify system library paths, colon separated + --crtprefix=... specify locations of crt?.o, colon separated + --elfinterp=... specify elf interpreter ++ --with-tcl=... specify path to Tcl + EOF + #echo "NOTE: The object files are build at the place where configure is launched" + exit 1 +@@ -339,6 +343,25 @@ + esac + fi + ++print_tcl_defs() { ++ ( ++ tclConfig="$1" ++ . "${tclConfig}" ++ LDFLAGS="$LDFLAGS $TCL_LIB_SPEC $TCL_LIBS" ++ CFLAGS="$CFLAGS $TCL_INCLUDE_SPEC -DHAVE_TCL_H=1" ++ set | egrep '^(CFLAGS|LDFLAGS)=' ++ ) ++} ++ ++if [ -n "${tcc_tcl_path}" ]; then ++ for tcc_tcl_path_file in ${tcc_tcl_path}/{,lib,lib64}/tclConfig.sh; do ++ if [ -f "${tcc_tcl_path_file}" ]; then ++ eval `print_tcl_defs "${tcc_tcl_path_file}"` ++ break ++ fi ++ done ++fi ++ + cat < ++#endif + + #ifdef CONFIG_TCCBOOT + #include "tccboot.h" ADDED build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff ================================================================== --- build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff +++ build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff @@ -0,0 +1,117 @@ +diff -uNr tcc-0.9.26.orig/libtcc.c tcc-0.9.26-1tclio/libtcc.c +--- tcc-0.9.26.orig/libtcc.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/libtcc.c 2014-05-01 19:32:19.383657630 -0500 +@@ -669,7 +669,7 @@ + bf->line_num = 1; + bf->ifndef_macro = 0; + bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; +- bf->fd = -1; ++ bf->fd = NULL; + bf->prev = file; + file = bf; + } +@@ -677,26 +677,35 @@ + ST_FUNC void tcc_close(void) + { + BufferedFile *bf = file; +- if (bf->fd > 0) { +- close(bf->fd); ++ if (bf->fd != NULL) { ++ Tcl_Close(NULL,bf->fd); + total_lines += bf->line_num; + } + file = bf->prev; + tcc_free(bf); + } + +-ST_FUNC int tcc_open(TCCState *s1, const char *filename) ++ST_FUNC Tcl_Channel tcc_open(TCCState *s1, const char *filename) + { +- int fd; +- if (strcmp(filename, "-") == 0) +- fd = 0, filename = "stdin"; +- else +- fd = open(filename, O_RDONLY | O_BINARY); +- if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3) +- printf("%s %*s%s\n", fd < 0 ? "nf":"->", ++ Tcl_Channel fd; ++ Tcl_Obj *path; ++ ++ if (strcmp(filename, "-") == 0) { ++ fd = Tcl_GetStdChannel(TCL_STDIN); ++ filename = "stdin"; ++ } else { ++ path = Tcl_NewStringObj(filename,-1); ++ Tcl_IncrRefCount(path); ++ fd = Tcl_FSOpenFileChannel(NULL,path, "r", 0); ++ Tcl_DecrRefCount(path); ++ } ++ ++ if ((s1->verbose == 2 && fd != NULL) || s1->verbose == 3) ++ printf("%s %*s%s\n", fd == NULL ? "nf":"->", + (int)(s1->include_stack_ptr - s1->include_stack), "", filename); +- if (fd < 0) +- return -1; ++ if (fd == NULL) { ++ return NULL; ++ } + + tcc_open_bf(s1, filename, 0); + file->fd = fd; +@@ -1099,7 +1108,8 @@ + { + const char *ext; + ElfW(Ehdr) ehdr; +- int fd, ret, size; ++ int ret, size; ++ Tcl_Channel ret_chan, fd; + + /* find source file type with extension */ + ext = tcc_fileextension(filename); +@@ -1113,11 +1123,11 @@ + #endif + + /* open the file */ +- ret = tcc_open(s1, filename); +- if (ret < 0) { ++ ret_chan = tcc_open(s1, filename); ++ if (ret_chan == NULL) { + if (flags & AFF_PRINT_ERROR) + tcc_error_noabort("file '%s' not found", filename); +- return ret; ++ return -1; + } + + /* update target deps */ +@@ -1151,8 +1161,8 @@ + + fd = file->fd; + /* assume executable format: auto guess file type */ +- size = read(fd, &ehdr, sizeof(ehdr)); +- lseek(fd, 0, SEEK_SET); ++ size = Tcl_Read(fd, (unsigned char *)&ehdr, sizeof(ehdr)); ++ Tcl_Seek(fd, 0, SEEK_SET); + if (size <= 0) { + tcc_error_noabort("could not read header"); + goto the_end; +diff -uNr tcc-0.9.26.orig/tcc.h tcc-0.9.26-1tclio/tcc.h +--- tcc-0.9.26.orig/tcc.h 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/tcc.h 2014-05-01 19:26:10.847265869 -0500 +@@ -429,7 +429,7 @@ + typedef struct BufferedFile { + uint8_t *buf_ptr; + uint8_t *buf_end; +- int fd; ++ Tcl_Channel fd; + struct BufferedFile *prev; + int line_num; /* current line number - here to simplify code */ + int ifndef_macro; /* #ifndef macro / #endif search */ +@@ -1045,7 +1045,7 @@ + ST_FUNC Sym *global_identifier_push(int v, int t, int c); + + ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen); +-ST_FUNC int tcc_open(TCCState *s1, const char *filename); ++ST_FUNC Tcl_Channel tcc_open(TCCState *s1, const char *filename); + ST_FUNC void tcc_close(void); + + ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);