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
27
28
29
30
31
32





33
34
35
36
37
38
	fi

	mv new "tcc-${tcc_version}.tar.bz2"

	bzip2 -dc "tcc-${tcc_version}.tar.bz2" | tar -xf -

	rm -f "tcc-${tcc_version}.tar.bz2"






	rm -rf ../tcc
	mkdir ../tcc || exit 1
	mv */* ../tcc/
)
rm -rf __TMP__







>
>
>
>
>






26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	fi

	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 version [e03734effa].



































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 <<EOF
 Binary  directory   $bindir
 TinyCC directory    $tccdir
--- tcc-0.9.26.orig/tcc.h	2013-02-15 08:24:00.000000000 -0600
+++ tcc-0.9.26-1tcl/tcc.h	2014-05-01 19:50:24.973630534 -0500
@@ -23,6 +23,9 @@
 
 #define _GNU_SOURCE
 #include "config.h"
+#ifdef HAVE_TCL_H
+#  include <tcl.h>
+#endif
 
 #ifdef CONFIG_TCCBOOT
 #include "tccboot.h"

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











































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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);