copy & paste coding, twisted control flow This reverts commit a13f183e4c2c4b4d1d40e142b57a4298672dfd2c. Also, set linker args for DLLs also.
Unified · Split
| @@ -1061,7 +1061,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 1060 unmodified lines | |||
| 1061 | #else | 1061 | #else |
| 1062 | tcc_set_lib_path(s, CONFIG_TCCDIR); | 1062 | tcc_set_lib_path(s, CONFIG_TCCDIR); |
| 1063 | #endif | 1063 | #endif |
| 1064 | s->output_type = 0; | 1064 | |
| 1065 | preprocess_new(); | 1065 | preprocess_new(); |
| 1066 | s->include_stack_ptr = s->include_stack; | 1066 | s->include_stack_ptr = s->include_stack; |
| 1067 | 1067 | ||
| @@ -1229,10 +1229,6 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 161 unmodified lines | |||
| 1229 | 1229 | ||
| 1230 | tcc_cleanup(); | 1230 | tcc_cleanup(); |
| 1231 | 1231 | ||
| 1232 | /* close a preprocessor output */ | ||
| 1233 | if (s1->ppfp && s1->ppfp != stdout) | ||
| 1234 | fclose(s1->ppfp); | ||
| 1235 | |||
| 1236 | /* free all sections */ | 1232 | /* free all sections */ |
| 1237 | for(i = 1; i < s1->nb_sections; i++) | 1233 | for(i = 1; i < s1->nb_sections; i++) |
| 1238 | free_section(s1->sections[i]); | 1234 | free_section(s1->sections[i]); |
| @@ -1609,16 +1605,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 370 unmodified lines | |||
| 1609 | { | 1605 | { |
| 1610 | s->output_type = output_type; | 1606 | s->output_type = output_type; |
| 1611 | 1607 | ||
| 1612 | if (s->output_type == TCC_OUTPUT_PREPROCESS) { | ||
| 1613 | if (!s->outfile) { | ||
| 1614 | s->ppfp = stdout; | ||
| 1615 | } else { | ||
| 1616 | s->ppfp = fopen(s->outfile, "w"); | ||
| 1617 | if (!s->ppfp) | ||
| 1618 | tcc_error("could not write '%s'", s->outfile); | ||
| 1619 | } | ||
| 1620 | } | ||
| 1621 | |||
| 1622 | if (!s->nostdinc) { | 1608 | if (!s->nostdinc) { |
| 1623 | /* default include paths */ | 1609 | /* default include paths */ |
| 1624 | /* -isystem paths have already been handled */ | 1610 | /* -isystem paths have already been handled */ |
| @@ -2289,6 +2275,9 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) · 664 unmodified lines | |||
| 2289 | s->print_search_dirs = 1; | 2275 | s->print_search_dirs = 1; |
| 2290 | break; | 2276 | break; |
| 2291 | case TCC_OPTION_run: | 2277 | case TCC_OPTION_run: |
| 2278 | #ifndef TCC_IS_NATIVE | ||
| 2279 | tcc_error("-run is not available in a cross compiler"); | ||
| 2280 | #endif | ||
| 2292 | if (s->output_type) | 2281 | if (s->output_type) |
| 2293 | tcc_warning("-run: some compiler action already specified (%d)", s->output_type); | 2282 | tcc_warning("-run: some compiler action already specified (%d)", s->output_type); |
| 2294 | s->output_type = TCC_OUTPUT_MEMORY; | 2283 | s->output_type = TCC_OUTPUT_MEMORY; |
| @@ -2397,7 +2386,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 102 unmodified lines | |||
| 2397 | s->nb_libraries++; | 2386 | s->nb_libraries++; |
| 2398 | } | 2387 | } |
| 2399 | 2388 | ||
| 2400 | if (s->output_type == TCC_OUTPUT_EXE) | 2389 | if (s->output_type == TCC_OUTPUT_EXE || s->output_type == TCC_OUTPUT_DLL) |
| 2401 | tcc_set_linker(s, (const char *)pas->linker_arg.data); | 2390 | tcc_set_linker(s, (const char *)pas->linker_arg.data); |
| 2402 | 2391 | ||
| 2403 | if (is_allocated) { | 2392 | if (is_allocated) { |
| @@ -223,9 +223,7 @@ static char *default_outputfile(TCCState *s, const char *first_file) · 222 unmodified lines | |||
| 223 | strcpy(ext, ".exe"); | 223 | strcpy(ext, ".exe"); |
| 224 | else | 224 | else |
| 225 | #endif | 225 | #endif |
| 226 | if (( (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) || | 226 | if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r && *ext) |
| 227 | (s->output_type == TCC_OUTPUT_PREPROCESS) ) | ||
| 228 | && *ext) | ||
| 229 | strcpy(ext, ".o"); | 227 | strcpy(ext, ".o"); |
| 230 | else | 228 | else |
| 231 | strcpy(buf, "a.out"); | 229 | strcpy(buf, "a.out"); |
| @@ -252,6 +250,7 @@ int main(int argc, char **argv) · 20 unmodified lines | |||
| 252 | TCCState *s; | 250 | TCCState *s; |
| 253 | int ret, optind, i; | 251 | int ret, optind, i; |
| 254 | int64_t start_time = 0; | 252 | int64_t start_time = 0; |
| 253 | const char *first_file = NULL; | ||
| 255 | 254 | ||
| 256 | s = tcc_new(); | 255 | s = tcc_new(); |
| 257 | 256 | ||
| @@ -290,13 +289,22 @@ int main(int argc, char **argv) · 32 unmodified lines | |||
| 290 | if (s->nb_libraries != 0) | 289 | if (s->nb_libraries != 0) |
| 291 | tcc_error("cannot specify libraries with -c"); | 290 | tcc_error("cannot specify libraries with -c"); |
| 292 | /* accepts only a single input file */ | 291 | /* accepts only a single input file */ |
| 293 | if ((s->nb_files != 1) && s->outfile) { | 292 | if (s->nb_files != 1) |
| 294 | tcc_error("cannot specify multiple files with -c and -o"); | 293 | tcc_error("cannot specify multiple files with -c"); |
| 295 | } | ||
| 296 | } | 294 | } |
| 297 | 295 | ||
| 298 | tcc_set_output_type(s, s->output_type); | 296 | tcc_set_output_type(s, s->output_type); |
| 299 | 297 | ||
| 298 | if (s->output_type == TCC_OUTPUT_PREPROCESS) { | ||
| 299 | if (!s->outfile) { | ||
| 300 | s->ppfp = stdout; | ||
| 301 | } else { | ||
| 302 | s->ppfp = fopen(s->outfile, "w"); | ||
| 303 | if (!s->ppfp) | ||
| 304 | tcc_error("could not write '%s'", s->outfile); | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 300 | /* compile or add each files or library */ | 308 | /* compile or add each files or library */ |
| 301 | for(i = ret = 0; i < s->nb_files && ret == 0; i++) { | 309 | for(i = ret = 0; i < s->nb_files && ret == 0; i++) { |
| 302 | int filetype = *(unsigned char *)s->files[i]; | 310 | int filetype = *(unsigned char *)s->files[i]; |
| @@ -312,27 +320,10 @@ int main(int argc, char **argv) · 9 unmodified lines | |||
| 312 | } else { | 320 | } else { |
| 313 | if (1 == s->verbose) | 321 | if (1 == s->verbose) |
| 314 | printf("-> %s\n", filename); | 322 | printf("-> %s\n", filename); |
| 315 | if (!s->outfile) | ||
| 316 | s->outfile = default_outputfile(s, filename); | ||
| 317 | if (tcc_add_file(s, filename, filetype) < 0) | 323 | if (tcc_add_file(s, filename, filetype) < 0) |
| 318 | ret = 1; | 324 | ret = 1; |
| 319 | else | 325 | if (!first_file) |
| 320 | if (s->output_type == TCC_OUTPUT_OBJ) { | 326 | first_file = filename; |
| 321 | ret = !!tcc_output_file(s, s->outfile); | ||
| 322 | if (s->gen_deps && !ret) | ||
| 323 | gen_makedeps(s, s->outfile, s->deps_outfile); | ||
| 324 | if (!ret) { | ||
| 325 | if ((i+1) < s->nb_files) { | ||
| 326 | tcc_delete(s); | ||
| 327 | s = tcc_new(); | ||
| 328 | tcc_parse_args(s, argc - 1, argv + 1); | ||
| 329 | tcc_set_environment(s); | ||
| 330 | if (s->output_type != TCC_OUTPUT_OBJ) | ||
| 331 | tcc_error("internal error"); | ||
| 332 | tcc_set_output_type(s, s->output_type); | ||
| 333 | } | ||
| 334 | } | ||
| 335 | } | ||
| 336 | } | 327 | } |
| 337 | } | 328 | } |
| 338 | 329 | ||
| @@ -340,14 +331,10 @@ int main(int argc, char **argv) · 1 unmodified line | |||
| 340 | if (s->output_type == TCC_OUTPUT_MEMORY) { | 331 | if (s->output_type == TCC_OUTPUT_MEMORY) { |
| 341 | #ifdef TCC_IS_NATIVE | 332 | #ifdef TCC_IS_NATIVE |
| 342 | ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind); | 333 | ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind); |
| 343 | #else | ||
| 344 | tcc_error_noabort("-run is not available in a cross compiler"); | ||
| 345 | ret = 1; | ||
| 346 | #endif | 334 | #endif |
| 347 | } else | 335 | } else { |
| 348 | if (s->output_type == TCC_OUTPUT_EXE || | 336 | if (!s->outfile) |
| 349 | s->output_type == TCC_OUTPUT_DLL) | 337 | s->outfile = default_outputfile(s, first_file); |
| 350 | { | ||
| 351 | ret = !!tcc_output_file(s, s->outfile); | 338 | ret = !!tcc_output_file(s, s->outfile); |
| 352 | if (s->gen_deps && !ret) | 339 | if (s->gen_deps && !ret) |
| 353 | gen_makedeps(s, s->outfile, s->deps_outfile); | 340 | gen_makedeps(s, s->outfile, s->deps_outfile); |