History

Accept colon separated paths with -L and -I

This allows passing colon separated paths to tcc_add_library_path tcc_add_sysinclude_path tcc_add_include_path Also there are new configure variables CONFIG_TCC_LIBPATH CONFIG_TCC_SYSINCLUDE_PATHS which define the lib/sysinclude paths all in one and can be overridden from configure/make For TCC_TARGET_PE semicolons (;) are used as separators Also, \b in the path string is replaced by s->tcc_lib_path (CONFIG_TCCDIR rsp. -B option)

grischka committed 15 years ago

Commit df9cce21 parent 626a9075 files · +111 −132Browse files

Unified · Split

5 files
  1. Makefile +8 −3
  2. libtcc.c +56 −107
  3. tcc.h +35 −12
  4. tccelf.c +3 −10
  5. tccgen.c +9 −0
Makefile+8−3
@@ -159,10 +159,15 @@ tcc$(EXESUF): tcc.o $(LIBTCC) · 158 unmodified lines
159159 %-tcc$(EXESUF):
160160 $(CC) -o $@ tcc.c -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
161161
162−$(I386_CROSS): DEFINES = -DTCC_TARGET_I386 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
162+$(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
163+ -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
163164 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
164−$(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -DCONFIG_TCC_CROSSLIB="\"lib/32\""
165−$(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -DCONFIG_TCC_CROSSLIB="\"lib/64\""
165+$(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
166+ -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
167+ -DCONFIG_TCC_LIBPATH="\"\b/lib/32;\b/lib\""
168+$(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
169+ -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
170+ -DCONFIG_TCC_LIBPATH="\"\b/lib/64;\b/lib\""
166171 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
167172 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
168173 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
libtcc.c+56−107
@@ -111,6 +111,13 @@ static void tcc_set_lib_path_w32(TCCState *s) · 110 unmodified lines
111111 tcc_set_lib_path(s, path);
112112 }
113113
114+static void tcc_add_systemdir(TCCState *s)
115+{
116+ char buf[1000];
117+ GetSystemDirectory(buf, sizeof buf);
118+ tcc_add_library_path(s, buf);
119+}
120+
114121 #ifndef CONFIG_TCC_STATIC
115122 void dlclose(void *p)
116123 {
@@ -159,11 +166,18 @@ PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s) · 42 unmodified lines
159166 return buf;
160167 }
161168
169+PUB_FUNC char *pstrncpy(char *out, const char *in, size_t num)
170+{
171+ memcpy(out, in, num);
172+ out[num] = '\0';
173+ return out;
174+}
175+
162176 /* extract the basename of a file */
163177 PUB_FUNC char *tcc_basename(const char *name)
164178 {
165179 char *p = strchr(name, 0);
166− while (p > name && !IS_PATHSEP(p[-1]))
180+ while (p > name && !IS_DIRSEP(p[-1]))
167181 --p;
168182 return p;
169183 }
@@ -293,39 +307,37 @@ PUB_FUNC void dynarray_reset(void *pp, int *n) · 123 unmodified lines
293307 }
294308
295309 /* out must not point to a valid dynarray since a new one is created */
296−PUB_FUNC int tcc_split_path(const char *in, const char * const *prefixs,
297− int nb_prefixs, char ***out)
310+static void tcc_split_path(TCCState *s, void ***p_ary, int *p_nb_ary, const char *in)
298311 {
299− int i, nb_comps = 0;
300− char *path;
301− const char *end;
302− size_t size;
303−
304− *out = NULL;
312+ const char *p;
305313 do {
306− end = in;
307− while (*end && *end != ':')
308− ++end;
309− for (i = 0; i < nb_prefixs; i++) {
310− size = (strlen(prefixs[i]) + 1) * sizeof(char)
311− + (end - in);
312− path = tcc_malloc(size);
313− pstrcpy(path, size, prefixs[i]);
314− pstrcat(path, size, in);
315− dynarray_add((void ***) out, &nb_comps, path);
314+ const char *r = NULL;
315+ int c;
316+ CString str;
317+
318+ cstr_new(&str);
319+ for (p = in;;) {
320+ if (r) {
321+ if ((c = *r++) == 0) {
322+ r = NULL;
323+ continue;
324+ }
325+ } else if ((c = *p++) == 0) {
326+ ;
327+ } else if (c == PATHSEP) {
328+ c = 0;
329+ } else if (c == '\b') {
330+ r = s->tcc_lib_path;
331+ continue;
332+ }
333+ cstr_ccat(&str, c);
334+ if (0 == c)
335+ break;
316336 }
317− in = end + 1;
318− } while (*end);
319− return nb_comps;
320−}
321−
322−/* we use our own 'finite' function to avoid potential problems with
323− non standard math libs */
324−/* XXX: endianness dependent */
325−ST_FUNC int ieee_finite(double d)
326−{
327− int *p = (int *)&d;
328− return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31;
337+ //printf("path: %s\n", (char*)str.data);
338+ dynarray_add(p_ary, p_nb_ary, str.data);
339+ in = p;
340+ } while (p[-1]);
329341 }
330342
331343 /********************************************************/
@@ -994,27 +1006,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 662 unmodified lines
9941006
9951007 #ifndef TCC_TARGET_PE
9961008 /* default library paths */
997− tcc_add_library_path(s, CONFIG_TCC_CRT_PREFIX);
998− tcc_add_library_path(s, CONFIG_SYSROOT CONFIG_TCC_LDDIR);
999− tcc_add_library_path(s, CONFIG_SYSROOT "/usr/local"CONFIG_TCC_LDDIR);
1000−#ifdef CONFIG_TCC_EXTRA_LDDIR
1001− {
1002− int i, nb_extra_lddirs, nb_prefixs;
1003− char **extra_lddirs;
1004− char extra_lddir_str[] = CONFIG_TCC_EXTRA_LDDIR;
1005− const char lddir_prefix1[] = CONFIG_SYSROOT;
1006− const char lddir_prefix2[] = CONFIG_SYSROOT "/usr/local";
1007− const char * const lddir_prefixs[] = {lddir_prefix1, lddir_prefix2};
1008−
1009− nb_prefixs = sizeof lddir_prefixs / sizeof *lddir_prefixs;
1010− nb_extra_lddirs = tcc_split_path(CONFIG_TCC_EXTRA_LDDIR,
1011− lddir_prefixs, nb_prefixs,
1012− &extra_lddirs);
1013− for (i = 0; i < nb_extra_lddirs; i++)
1014− tcc_add_library_path(s, extra_lddirs[i]);
1015− dynarray_reset(&extra_lddirs, &nb_extra_lddirs);
1016− }
1017−#endif
1009+ tcc_add_library_path(s, CONFIG_TCC_LIBPATH);
10181010 #endif
10191011
10201012 /* no section zero */
@@ -1101,21 +1093,15 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 80 unmodified lines
11011093 tcc_free(s1);
11021094 }
11031095
1104−LIBTCCAPI int tcc_add_include_path(TCCState *s1, const char *pathname)
1096+LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
11051097 {
1106− char *pathname1;
1107−
1108− pathname1 = tcc_strdup(pathname);
1109− dynarray_add((void ***)&s1->include_paths, &s1->nb_include_paths, pathname1);
1098+ tcc_split_path(s, (void ***)&s->include_paths, &s->nb_include_paths, pathname);
11101099 return 0;
11111100 }
11121101
1113−LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s1, const char *pathname)
1102+LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname)
11141103 {
1115− char *pathname1;
1116−
1117− pathname1 = tcc_strdup(pathname);
1118− dynarray_add((void ***)&s1->sysinclude_paths, &s1->nb_sysinclude_paths, pathname1);
1104+ tcc_split_path(s, (void ***)&s->sysinclude_paths, &s->nb_sysinclude_paths, pathname);
11191105 return 0;
11201106 }
11211107
@@ -1252,10 +1238,7 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) · 130 unmodified lines
12521238
12531239 LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
12541240 {
1255− char *pathname1;
1256−
1257− pathname1 = tcc_strdup(pathname);
1258− dynarray_add((void ***)&s->library_paths, &s->nb_library_paths, pathname1);
1241+ tcc_split_path(s, (void ***)&s->library_paths, &s->nb_library_paths, pathname);
12591242 return 0;
12601243 }
12611244
@@ -1318,37 +1301,12 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) · 56 unmodified lines
13181301
13191302 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
13201303 {
1321− char buf[1024];
1322−
13231304 s->output_type = output_type;
13241305
13251306 if (!s->nostdinc) {
13261307 /* default include paths */
13271308 /* -isystem paths have already been handled */
1328−#ifndef TCC_TARGET_PE
1329− {
1330− int i, nb_extra_incdirs, nb_prefixs;
1331− char **extra_incdirs;
1332− const char incdir_prefix1[] = CONFIG_SYSROOT "/usr/local/include";
1333− const char incdir_prefix2[] = CONFIG_SYSROOT "/usr/include";
1334− const char * const incdir_prefixs[] = {incdir_prefix1,
1335− incdir_prefix2};
1336−
1337− nb_prefixs = sizeof incdir_prefixs / sizeof *incdir_prefixs;
1338− nb_extra_incdirs = tcc_split_path(CONFIG_TCC_INCSUBDIR,
1339− incdir_prefixs, nb_prefixs,
1340− &extra_incdirs);
1341− for (i = 0; i < nb_extra_incdirs; i++)
1342− tcc_add_sysinclude_path(s, extra_incdirs[i]);
1343− dynarray_reset(&extra_incdirs, &nb_extra_incdirs);
1344− }
1345−#endif
1346− snprintf(buf, sizeof(buf), "%s/include", s->tcc_lib_path);
1347− tcc_add_sysinclude_path(s, buf);
1348−#ifdef TCC_TARGET_PE
1349− snprintf(buf, sizeof(buf), "%s/include/winapi", s->tcc_lib_path);
1350− tcc_add_sysinclude_path(s, buf);
1351−#endif
1309+ tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDE_PATHS);
13521310 }
13531311
13541312 /* if bound checking, then add corresponding sections */
@@ -1381,7 +1339,12 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 26 unmodified lines
13811339 }
13821340
13831341 /* add libc crt1/crti objects */
1384−#ifndef TCC_TARGET_PE
1342+#ifdef TCC_TARGET_PE
1343+ tcc_add_library_path(s, CONFIG_TCC_LIBPATH);
1344+# ifdef _WIN32
1345+ tcc_add_systemdir(s);
1346+# endif
1347+#else
13851348 if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) &&
13861349 !s->nostdlib) {
13871350 if (output_type != TCC_OUTPUT_DLL)
@@ -1389,20 +1352,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 1 unmodified line
13891352 tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o");
13901353 }
13911354 #endif
1392−
1393−#ifdef TCC_TARGET_PE
1394−#ifdef CONFIG_TCC_CROSSLIB
1395− snprintf(buf, sizeof(buf), "%s/" CONFIG_TCC_CROSSLIB, s->tcc_lib_path);
1396− tcc_add_library_path(s, buf);
1397−#endif
1398− snprintf(buf, sizeof(buf), "%s/lib", s->tcc_lib_path);
1399− tcc_add_library_path(s, buf);
1400−#ifdef _WIN32
1401− if (GetSystemDirectory(buf, sizeof buf))
1402− tcc_add_library_path(s, buf);
1403−#endif
1404−#endif
1405−
14061355 return 0;
14071356 }
14081357
tcc.h+35−12
@@ -139,9 +139,6 @@ · 138 unmodified lines
139139 #define true 1
140140 typedef int BOOL;
141141
142−/* path to find crt1.o, crti.o and crtn.o. Only needed when generating
143− executables or dlls */
144−
145142 #ifndef CONFIG_TCC_LDDIR
146143 #if defined(TCC_TARGET_X86_64_CENTOS)
147144 #define CONFIG_TCC_LDDIR "/lib64"
@@ -149,9 +146,29 @@ typedef int BOOL; · 1 unmodified line
149146 #define CONFIG_TCC_LDDIR "/lib"
150147 #endif
151148 #endif
152−#define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR
153−#ifndef CONFIG_TCC_INCSUBDIR
154− #define CONFIG_TCC_INCSUBDIR ""
149+
150+/* path to find crt1.o, crti.o and crtn.o */
151+#ifndef CONFIG_TCC_CRT_PREFIX
152+# define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR
153+#endif
154+
155+#ifndef CONFIG_TCC_SYSINCLUDE_PATHS
156+# ifdef TCC_TARGET_PE
157+# define CONFIG_TCC_SYSINCLUDE_PATHS "\b/include;\b/include/winapi"
158+# else
159+# define CONFIG_TCC_SYSINCLUDE_PATHS "/usr/local/include:/usr/include:\b/include"
160+# endif
161+#endif
162+
163+#ifndef CONFIG_TCC_LIBPATH
164+# ifdef TCC_TARGET_PE
165+# define CONFIG_TCC_LIBPATH "\b/lib"
166+# else
167+# define CONFIG_TCC_LIBPATH \
168+ CONFIG_TCC_CRT_PREFIX \
169+ ":" CONFIG_SYSROOT CONFIG_TCC_LDDIR \
170+ ":" CONFIG_SYSROOT "/usr/local" CONFIG_TCC_LDDIR
171+# endif
155172 #endif
156173
157174 #define INCLUDE_STACK_SIZE 32
@@ -843,15 +860,21 @@ extern long double strtold (const char *__nptr, char **__endptr); · 685 unmodified lines
843860 #endif
844861
845862 #ifdef _WIN32
846−#define IS_PATHSEP(c) (c == '/' || c == '\\')
847−#define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2])))
863+#define IS_DIRSEP(c) (c == '/' || c == '\\')
864+#define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
848865 #define PATHCMP stricmp
849866 #else
850−#define IS_PATHSEP(c) (c == '/')
851−#define IS_ABSPATH(p) IS_PATHSEP(p[0])
867+#define IS_DIRSEP(c) (c == '/')
868+#define IS_ABSPATH(p) IS_DIRSEP(p[0])
852869 #define PATHCMP strcmp
853870 #endif
854871
872+#ifdef TCC_TARGET_PE
873+#define PATHSEP ';'
874+#else
875+#define PATHSEP ':'
876+#endif
877+
855878 /* space exlcuding newline */
856879 static inline int is_space(int ch)
857880 {
@@ -912,6 +935,7 @@ ST_DATA void *rt_prog_main; · 54 unmodified lines
912935 /* public functions currently used by the tcc main function */
913936 PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
914937 PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
938+PUB_FUNC char *pstrncpy(char *out, const char *in, size_t num);
915939 PUB_FUNC char *tcc_basename(const char *name);
916940 PUB_FUNC char *tcc_fileextension (const char *name);
917941 PUB_FUNC void tcc_free(void *ptr);
@@ -970,8 +994,6 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value); · 52 unmodified lines
970994 PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
971995 PUB_FUNC void set_num_callers(int n);
972996
973−ST_FUNC int ieee_finite(double d);
974−
975997 /* ------------ tccpp.c ------------ */
976998
977999 ST_DATA struct BufferedFile *file;
@@ -1066,6 +1088,7 @@ ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc · 88 unmodified lines
10661088 ST_DATA char *funcname;
10671089
10681090 ST_INLN int is_float(int t);
1091+ST_FUNC int ieee_finite(double d);
10691092 ST_FUNC void test_lvalue(void);
10701093 ST_FUNC void swap(int *p, int *q);
10711094 ST_FUNC void vpushi(int v);
tccelf.c+3−10
@@ -2857,13 +2857,6 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 2856 unmodified lines
28572857 return c;
28582858 }
28592859
2860−char *tcc_strcpy_part(char *out, const char *in, size_t num)
2861−{
2862− memcpy(out, in, num);
2863− out[num] = '\0';
2864− return out;
2865−}
2866−
28672860 /*
28682861 * Extract the library name from the file name
28692862 * Return 0 if the file isn't a library
@@ -2886,20 +2879,20 @@ static int filename_to_libname(TCCState *s1, const char filename[], char libname · 16 unmodified lines
28862879 #ifdef TCC_TARGET_PE
28872880 if (!strcmp(ext, ".def")) {
28882881 size_t len = ext - filename;
2889− tcc_strcpy_part(libname, filename, len);
2882+ pstrncpy(libname, filename, len);
28902883 return 1;
28912884 }
28922885 #else
28932886 if (libprefix && (!strcmp(ext, ".so"))) {
28942887 size_t len = ext - filename - 3;
2895− tcc_strcpy_part(libname, filename + 3, len);
2888+ pstrncpy(libname, filename + 3, len);
28962889 return 1;
28972890 }
28982891 #endif
28992892 } else {
29002893 if (libprefix && (!strcmp(ext, ".a"))) {
29012894 size_t len = ext - filename - 3;
2902− tcc_strcpy_part(libname, filename + 3, len);
2895+ pstrncpy(libname, filename + 3, len);
29032896 return 1;
29042897 }
29052898 }
tccgen.c+9−0
@@ -90,6 +90,15 @@ ST_INLN int is_float(int t) · 89 unmodified lines
9090 return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
9191 }
9292
93+/* we use our own 'finite' function to avoid potential problems with
94+ non standard math libs */
95+/* XXX: endianness dependent */
96+ST_FUNC int ieee_finite(double d)
97+{
98+ int *p = (int *)&d;
99+ return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31;
100+}
101+
93102 ST_FUNC void test_lvalue(void)
94103 {
95104 if (!(vtop->r & VT_LVAL))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t