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 | 1061 | #else |
| 1062 | 1062 | tcc_set_lib_path(s, CONFIG_TCCDIR); |
| 1063 | 1063 | #endif |
| 1064 | − s->output_type = 0; | |
| 1064 | + | |
| 1065 | 1065 | preprocess_new(); |
| 1066 | 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 | 1230 | tcc_cleanup(); |
| 1231 | 1231 | |
| 1232 | − /* close a preprocessor output */ | |
| 1233 | − if (s1->ppfp && s1->ppfp != stdout) | |
| 1234 | − fclose(s1->ppfp); | |
| 1235 | − | |
| 1236 | 1232 | /* free all sections */ |
| 1237 | 1233 | for(i = 1; i < s1->nb_sections; i++) |
| 1238 | 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 | 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 | 1608 | if (!s->nostdinc) { |
| 1623 | 1609 | /* default include paths */ |
| 1624 | 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 | 2275 | s->print_search_dirs = 1; |
| 2290 | 2276 | break; |
| 2291 | 2277 | case TCC_OPTION_run: |
| 2278 | +#ifndef TCC_IS_NATIVE | |
| 2279 | + tcc_error("-run is not available in a cross compiler"); | |
| 2280 | +#endif | |
| 2292 | 2281 | if (s->output_type) |
| 2293 | 2282 | tcc_warning("-run: some compiler action already specified (%d)", s->output_type); |
| 2294 | 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 | 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 | 2390 | tcc_set_linker(s, (const char *)pas->linker_arg.data); |
| 2402 | 2391 | |
| 2403 | 2392 | if (is_allocated) { |
| @@ -223,9 +223,7 @@ static char *default_outputfile(TCCState *s, const char *first_file) · 222 unmodified lines | ||
| 223 | 223 | strcpy(ext, ".exe"); |
| 224 | 224 | else |
| 225 | 225 | #endif |
| 226 | − if (( (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) || | |
| 227 | − (s->output_type == TCC_OUTPUT_PREPROCESS) ) | |
| 228 | − && *ext) | |
| 226 | + if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r && *ext) | |
| 229 | 227 | strcpy(ext, ".o"); |
| 230 | 228 | else |
| 231 | 229 | strcpy(buf, "a.out"); |
| @@ -252,6 +250,7 @@ int main(int argc, char **argv) · 20 unmodified lines | ||
| 252 | 250 | TCCState *s; |
| 253 | 251 | int ret, optind, i; |
| 254 | 252 | int64_t start_time = 0; |
| 253 | + const char *first_file = NULL; | |
| 255 | 254 | |
| 256 | 255 | s = tcc_new(); |
| 257 | 256 | |
| @@ -290,13 +289,22 @@ int main(int argc, char **argv) · 32 unmodified lines | ||
| 290 | 289 | if (s->nb_libraries != 0) |
| 291 | 290 | tcc_error("cannot specify libraries with -c"); |
| 292 | 291 | /* accepts only a single input file */ |
| 293 | − if ((s->nb_files != 1) && s->outfile) { | |
| 294 | − tcc_error("cannot specify multiple files with -c and -o"); | |
| 295 | − } | |
| 292 | + if (s->nb_files != 1) | |
| 293 | + tcc_error("cannot specify multiple files with -c"); | |
| 296 | 294 | } |
| 297 | 295 | |
| 298 | 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 | 308 | /* compile or add each files or library */ |
| 301 | 309 | for(i = ret = 0; i < s->nb_files && ret == 0; i++) { |
| 302 | 310 | int filetype = *(unsigned char *)s->files[i]; |
| @@ -312,27 +320,10 @@ int main(int argc, char **argv) · 9 unmodified lines | ||
| 312 | 320 | } else { |
| 313 | 321 | if (1 == s->verbose) |
| 314 | 322 | printf("-> %s\n", filename); |
| 315 | − if (!s->outfile) | |
| 316 | − s->outfile = default_outputfile(s, filename); | |
| 317 | 323 | if (tcc_add_file(s, filename, filetype) < 0) |
| 318 | 324 | ret = 1; |
| 319 | − else | |
| 320 | − if (s->output_type == TCC_OUTPUT_OBJ) { | |
| 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 | − } | |
| 325 | + if (!first_file) | |
| 326 | + first_file = filename; | |
| 336 | 327 | } |
| 337 | 328 | } |
| 338 | 329 | |
| @@ -340,14 +331,10 @@ int main(int argc, char **argv) · 1 unmodified line | ||
| 340 | 331 | if (s->output_type == TCC_OUTPUT_MEMORY) { |
| 341 | 332 | #ifdef TCC_IS_NATIVE |
| 342 | 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 | 334 | #endif |
| 347 | − } else | |
| 348 | − if (s->output_type == TCC_OUTPUT_EXE || | |
| 349 | − s->output_type == TCC_OUTPUT_DLL) | |
| 350 | − { | |
| 335 | + } else { | |
| 336 | + if (!s->outfile) | |
| 337 | + s->outfile = default_outputfile(s, first_file); | |
| 351 | 338 | ret = !!tcc_output_file(s, s->outfile); |
| 352 | 339 | if (s->gen_deps && !ret) |
| 353 | 340 | gen_makedeps(s, s->outfile, s->deps_outfile); |