| @@ -111,6 +111,13 @@ static void tcc_set_lib_path_w32(TCCState *s) · 110 unmodified lines |
| 111 | 111 | tcc_set_lib_path(s, path); |
| 112 | 112 | } |
| 113 | 113 | |
| 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 | + |
| 114 | 121 | #ifndef CONFIG_TCC_STATIC |
| 115 | 122 | void dlclose(void *p) |
| 116 | 123 | { |
| @@ -159,11 +166,18 @@ PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s) · 42 unmodified lines |
| 159 | 166 | return buf; |
| 160 | 167 | } |
| 161 | 168 | |
| 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 | + |
| 162 | 176 | /* extract the basename of a file */ |
| 163 | 177 | PUB_FUNC char *tcc_basename(const char *name) |
| 164 | 178 | { |
| 165 | 179 | char *p = strchr(name, 0); |
| 166 | | − while (p > name && !IS_PATHSEP(p[-1])) |
| 180 | + while (p > name && !IS_DIRSEP(p[-1])) |
| 167 | 181 | --p; |
| 168 | 182 | return p; |
| 169 | 183 | } |
| @@ -293,39 +307,37 @@ PUB_FUNC void dynarray_reset(void *pp, int *n) · 123 unmodified lines |
| 293 | 307 | } |
| 294 | 308 | |
| 295 | 309 | /* 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) |
| 298 | 311 | { |
| 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; |
| 305 | 313 | 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; |
| 316 | 336 | } |
| 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]); |
| 329 | 341 | } |
| 330 | 342 | |
| 331 | 343 | /********************************************************/ |
| @@ -994,27 +1006,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 662 unmodified lines |
| 994 | 1006 | |
| 995 | 1007 | #ifndef TCC_TARGET_PE |
| 996 | 1008 | /* 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); |
| 1018 | 1010 | #endif |
| 1019 | 1011 | |
| 1020 | 1012 | /* no section zero */ |
| @@ -1101,21 +1093,15 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 80 unmodified lines |
| 1101 | 1093 | tcc_free(s1); |
| 1102 | 1094 | } |
| 1103 | 1095 | |
| 1104 | | −LIBTCCAPI int tcc_add_include_path(TCCState *s1, const char *pathname) |
| 1096 | +LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) |
| 1105 | 1097 | { |
| 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); |
| 1110 | 1099 | return 0; |
| 1111 | 1100 | } |
| 1112 | 1101 | |
| 1113 | | −LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s1, const char *pathname) |
| 1102 | +LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) |
| 1114 | 1103 | { |
| 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); |
| 1119 | 1105 | return 0; |
| 1120 | 1106 | } |
| 1121 | 1107 | |
| @@ -1252,10 +1238,7 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) · 130 unmodified lines |
| 1252 | 1238 | |
| 1253 | 1239 | LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname) |
| 1254 | 1240 | { |
| 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); |
| 1259 | 1242 | return 0; |
| 1260 | 1243 | } |
| 1261 | 1244 | |
| @@ -1318,37 +1301,12 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) · 56 unmodified lines |
| 1318 | 1301 | |
| 1319 | 1302 | LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) |
| 1320 | 1303 | { |
| 1321 | | − char buf[1024]; |
| 1322 | | − |
| 1323 | 1304 | s->output_type = output_type; |
| 1324 | 1305 | |
| 1325 | 1306 | if (!s->nostdinc) { |
| 1326 | 1307 | /* default include paths */ |
| 1327 | 1308 | /* -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); |
| 1352 | 1310 | } |
| 1353 | 1311 | |
| 1354 | 1312 | /* 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 |
| 1381 | 1339 | } |
| 1382 | 1340 | |
| 1383 | 1341 | /* 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 |
| 1385 | 1348 | if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && |
| 1386 | 1349 | !s->nostdlib) { |
| 1387 | 1350 | if (output_type != TCC_OUTPUT_DLL) |
| @@ -1389,20 +1352,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 1 unmodified line |
| 1389 | 1352 | tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o"); |
| 1390 | 1353 | } |
| 1391 | 1354 | #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 | | − |
| 1406 | 1355 | return 0; |
| 1407 | 1356 | } |
| 1408 | 1357 | |