Unified · Split
| @@ -1065,12 +1065,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 1064 unmodified lines | ||
| 1065 | 1065 | dynarray_reset(&s1->include_paths, &s1->nb_include_paths); |
| 1066 | 1066 | dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); |
| 1067 | 1067 | |
| 1068 | − tcc_free(s1->tcc_lib_path); | |
| 1069 | − | |
| 1070 | − dynarray_reset(&s1->input_files, &s1->nb_input_files); | |
| 1071 | − dynarray_reset(&s1->input_libs, &s1->nb_input_libs); | |
| 1072 | 1068 | dynarray_reset(&s1->target_deps, &s1->nb_target_deps); |
| 1073 | 1069 | |
| 1070 | + tcc_free(s1->tcc_lib_path); | |
| 1071 | + | |
| 1074 | 1072 | #ifdef HAVE_SELINUX |
| 1075 | 1073 | munmap (s1->write_mem, s1->mem_size); |
| 1076 | 1074 | munmap (s1->runtime_mem, s1->mem_size); |
| @@ -1215,7 +1213,6 @@ the_end: · 138 unmodified lines | ||
| 1215 | 1213 | |
| 1216 | 1214 | LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename) |
| 1217 | 1215 | { |
| 1218 | − dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename)); | |
| 1219 | 1216 | if (s->output_type == TCC_OUTPUT_PREPROCESS) |
| 1220 | 1217 | return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS); |
| 1221 | 1218 | else |
| @@ -1250,8 +1247,6 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 28 unmodified lines | ||
| 1250 | 1247 | char buf[1024]; |
| 1251 | 1248 | int i; |
| 1252 | 1249 | |
| 1253 | − dynarray_add((void ***)&s->input_libs, &s->nb_input_libs, tcc_strdup(libraryname)); | |
| 1254 | − | |
| 1255 | 1250 | /* first we look for the dynamic library if not static linking */ |
| 1256 | 1251 | if (!s->static_link) { |
| 1257 | 1252 | #ifdef TCC_TARGET_PE |
| @@ -1608,17 +1603,16 @@ PUB_FUNC void set_num_callers(int n) · 350 unmodified lines | ||
| 1608 | 1603 | } |
| 1609 | 1604 | |
| 1610 | 1605 | |
| 1611 | −LIBTCCAPI const char *tcc_default_target(TCCState *s) | |
| 1606 | +PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file) | |
| 1612 | 1607 | { |
| 1613 | − /* FIXME will break in multithreaded case */ | |
| 1614 | − static char outfile_default[1024]; | |
| 1615 | − | |
| 1608 | + char buf[1024]; | |
| 1616 | 1609 | char *ext; |
| 1617 | − const char *name = | |
| 1618 | − strcmp(s->input_files[0], "-") == 0 ? "a" | |
| 1619 | − : tcc_basename(s->input_files[0]); | |
| 1620 | − pstrcpy(outfile_default, sizeof(outfile_default), name); | |
| 1621 | − ext = tcc_fileextension(outfile_default); | |
| 1610 | + const char *name = "a"; | |
| 1611 | + | |
| 1612 | + if (default_file && strcmp(default_file, "-")) | |
| 1613 | + name = tcc_basename(default_file); | |
| 1614 | + pstrcpy(buf, sizeof(buf), name); | |
| 1615 | + ext = tcc_fileextension(buf); | |
| 1622 | 1616 | #ifdef TCC_TARGET_PE |
| 1623 | 1617 | if (s->output_type == TCC_OUTPUT_DLL) |
| 1624 | 1618 | strcpy(ext, ".dll"); |
| @@ -1632,21 +1626,18 @@ LIBTCCAPI const char *tcc_default_target(TCCState *s) · 7 unmodified lines | ||
| 1632 | 1626 | && *ext) |
| 1633 | 1627 | strcpy(ext, ".o"); |
| 1634 | 1628 | else |
| 1635 | − pstrcpy(outfile_default, sizeof(outfile_default), "a.out"); | |
| 1629 | + pstrcpy(buf, sizeof(buf), "a.out"); | |
| 1636 | 1630 | |
| 1637 | − return outfile_default; | |
| 1631 | + return tcc_strdup(buf); | |
| 1638 | 1632 | } |
| 1639 | 1633 | |
| 1640 | 1634 | |
| 1641 | −LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename) | |
| 1635 | +PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename) | |
| 1642 | 1636 | { |
| 1643 | 1637 | FILE *depout; |
| 1644 | 1638 | char buf[1024], *ext; |
| 1645 | 1639 | int i; |
| 1646 | 1640 | |
| 1647 | − if (!target) | |
| 1648 | − target = tcc_default_target(s); | |
| 1649 | − | |
| 1650 | 1641 | if (!filename) { |
| 1651 | 1642 | /* compute filename automatically |
| 1652 | 1643 | * dir/file.o -> dir/file.d */ |
| @@ -103,20 +103,6 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); · 102 unmodified lines | ||
| 103 | 103 | /* set CONFIG_TCCDIR at runtime */ |
| 104 | 104 | LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path); |
| 105 | 105 | |
| 106 | − | |
| 107 | −/*****************************/ | |
| 108 | −/* Miscellaneous */ | |
| 109 | − | |
| 110 | −/* Get default target filename for this compilation */ | |
| 111 | −LIBTCCAPI const char *tcc_default_target(TCCState *s); | |
| 112 | − | |
| 113 | −/* Generate make dependencies for target and store them into file | |
| 114 | − * | |
| 115 | − * !target - use default target name | |
| 116 | − * !filename - use (target.o -> target.d) | |
| 117 | − */ | |
| 118 | −LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename); | |
| 119 | − | |
| 120 | 106 | #ifdef __cplusplus |
| 121 | 107 | } |
| 122 | 108 | #endif |
| @@ -30,7 +30,7 @@ static int multiple_files; · 29 unmodified lines | ||
| 30 | 30 | static int print_search_dirs; |
| 31 | 31 | static int output_type; |
| 32 | 32 | static int reloc_output; |
| 33 | −static const char *outfile; | |
| 33 | +static char *outfile; | |
| 34 | 34 | static int do_bench = 0; |
| 35 | 35 | static int gen_deps; |
| 36 | 36 | static const char *deps_outfile; |
| @@ -397,7 +397,7 @@ static int parse_args(TCCState *s, int argc, char **argv) · 360 unmodified lines | ||
| 397 | 397 | break; |
| 398 | 398 | case TCC_OPTION_o: |
| 399 | 399 | multiple_files = 1; |
| 400 | − outfile = optarg; | |
| 400 | + outfile = tcc_strdup(optarg); | |
| 401 | 401 | break; |
| 402 | 402 | case TCC_OPTION_r: |
| 403 | 403 | /* generate a .o merging several output files */ |
| @@ -488,6 +488,7 @@ int main(int argc, char **argv) · 84 unmodified lines | ||
| 488 | 488 | TCCState *s; |
| 489 | 489 | int nb_objfiles, ret, optind; |
| 490 | 490 | int64_t start_time = 0; |
| 491 | + const char *default_file = NULL; | |
| 491 | 492 | |
| 492 | 493 | s = tcc_new(); |
| 493 | 494 | |
| @@ -541,7 +542,6 @@ int main(int argc, char **argv) · 47 unmodified lines | ||
| 541 | 542 | error("cannot specify libraries with -c"); |
| 542 | 543 | } |
| 543 | 544 | |
| 544 | − | |
| 545 | 545 | if (output_type == TCC_OUTPUT_PREPROCESS) { |
| 546 | 546 | if (!outfile) { |
| 547 | 547 | s->outfile = stdout; |
| @@ -574,6 +574,8 @@ int main(int argc, char **argv) · 26 unmodified lines | ||
| 574 | 574 | printf("-> %s\n", filename); |
| 575 | 575 | if (tcc_add_file(s, filename) < 0) |
| 576 | 576 | ret = 1; |
| 577 | + if (!default_file) | |
| 578 | + default_file = filename; | |
| 577 | 579 | } |
| 578 | 580 | } |
| 579 | 581 | |
| @@ -584,17 +586,15 @@ int main(int argc, char **argv) · 4 unmodified lines | ||
| 584 | 586 | if (do_bench) |
| 585 | 587 | tcc_print_stats(s, getclock_us() - start_time); |
| 586 | 588 | |
| 587 | − if (s->output_type == TCC_OUTPUT_MEMORY) | |
| 589 | + if (s->output_type == TCC_OUTPUT_MEMORY) { | |
| 588 | 590 | ret = tcc_run(s, argc - optind, argv + optind); |
| 589 | − else { | |
| 590 | − if (s->output_type == TCC_OUTPUT_PREPROCESS) { | |
| 591 | − if (outfile) | |
| 592 | − fclose(s->outfile); | |
| 593 | − } else { | |
| 594 | − ret = tcc_output_file(s, outfile ? outfile : tcc_default_target(s)); | |
| 595 | − ret = ret ? 1 : 0; | |
| 596 | − } | |
| 597 | − | |
| 591 | + } else if (s->output_type == TCC_OUTPUT_PREPROCESS) { | |
| 592 | + if (s->outfile) | |
| 593 | + fclose(s->outfile); | |
| 594 | + } else { | |
| 595 | + if (!outfile) | |
| 596 | + outfile = tcc_default_target(s, default_file); | |
| 597 | + ret = !!tcc_output_file(s, outfile); | |
| 598 | 598 | /* dump collected dependencies */ |
| 599 | 599 | if (gen_deps && !ret) |
| 600 | 600 | tcc_gen_makedeps(s, outfile, deps_outfile); |
| @@ -602,6 +602,7 @@ int main(int argc, char **argv) · 1 unmodified line | ||
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | tcc_delete(s); |
| 605 | + tcc_free(outfile); | |
| 605 | 606 | |
| 606 | 607 | #ifdef MEM_DEBUG |
| 607 | 608 | if (do_bench) { |
| @@ -580,12 +580,6 @@ struct TCCState { · 579 unmodified lines | ||
| 580 | 580 | /* output file for preprocessing */ |
| 581 | 581 | FILE *outfile; |
| 582 | 582 | |
| 583 | − /* input files and libraries for this compilation */ | |
| 584 | − char **input_files; | |
| 585 | − int nb_input_files; | |
| 586 | − char **input_libs; | |
| 587 | − int nb_input_libs; | |
| 588 | − | |
| 589 | 583 | /* automatically collected dependencies for this compilation */ |
| 590 | 584 | char **target_deps; |
| 591 | 585 | int nb_target_deps; |
| @@ -1023,6 +1017,9 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value); · 431 unmodified lines | ||
| 1023 | 1017 | PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time); |
| 1024 | 1018 | PUB_FUNC void set_num_callers(int n); |
| 1025 | 1019 | |
| 1020 | +PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file); | |
| 1021 | +PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename); | |
| 1022 | + | |
| 1026 | 1023 | /* ------------ tccpp.c ------------ */ |
| 1027 | 1024 | |
| 1028 | 1025 | ST_DATA struct BufferedFile *file; |