History

libtcc: cleanup the 'gen_makedeps' stuff

grischka committed 15 years ago

Commit e6f3bf71 parent 39a07cc4 files · +30 −55Browse files

Unified · Split

4 files
  1. libtcc.c +13 −22
  2. libtcc.h +0 −14
  3. tcc.c +14 −13
  4. tcc.h +3 −6
libtcc.c+13−22
@@ -1065,12 +1065,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 1064 unmodified lines
10651065 dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
10661066 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
10671067
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);
10721068 dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
10731069
1070+ tcc_free(s1->tcc_lib_path);
1071+
10741072 #ifdef HAVE_SELINUX
10751073 munmap (s1->write_mem, s1->mem_size);
10761074 munmap (s1->runtime_mem, s1->mem_size);
@@ -1215,7 +1213,6 @@ the_end: · 138 unmodified lines
12151213
12161214 LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
12171215 {
1218− dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename));
12191216 if (s->output_type == TCC_OUTPUT_PREPROCESS)
12201217 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
12211218 else
@@ -1250,8 +1247,6 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 28 unmodified lines
12501247 char buf[1024];
12511248 int i;
12521249
1253− dynarray_add((void ***)&s->input_libs, &s->nb_input_libs, tcc_strdup(libraryname));
1254−
12551250 /* first we look for the dynamic library if not static linking */
12561251 if (!s->static_link) {
12571252 #ifdef TCC_TARGET_PE
@@ -1608,17 +1603,16 @@ PUB_FUNC void set_num_callers(int n) · 350 unmodified lines
16081603 }
16091604
16101605
1611−LIBTCCAPI const char *tcc_default_target(TCCState *s)
1606+PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file)
16121607 {
1613− /* FIXME will break in multithreaded case */
1614− static char outfile_default[1024];
1615−
1608+ char buf[1024];
16161609 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);
16221616 #ifdef TCC_TARGET_PE
16231617 if (s->output_type == TCC_OUTPUT_DLL)
16241618 strcpy(ext, ".dll");
@@ -1632,21 +1626,18 @@ LIBTCCAPI const char *tcc_default_target(TCCState *s) · 7 unmodified lines
16321626 && *ext)
16331627 strcpy(ext, ".o");
16341628 else
1635− pstrcpy(outfile_default, sizeof(outfile_default), "a.out");
1629+ pstrcpy(buf, sizeof(buf), "a.out");
16361630
1637− return outfile_default;
1631+ return tcc_strdup(buf);
16381632 }
16391633
16401634
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)
16421636 {
16431637 FILE *depout;
16441638 char buf[1024], *ext;
16451639 int i;
16461640
1647− if (!target)
1648− target = tcc_default_target(s);
1649−
16501641 if (!filename) {
16511642 /* compute filename automatically
16521643 * dir/file.o -> dir/file.d */
libtcc.h+0−14
@@ -103,20 +103,6 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); · 102 unmodified lines
103103 /* set CONFIG_TCCDIR at runtime */
104104 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
105105
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−
120106 #ifdef __cplusplus
121107 }
122108 #endif
tcc.c+14−13
@@ -30,7 +30,7 @@ static int multiple_files; · 29 unmodified lines
3030 static int print_search_dirs;
3131 static int output_type;
3232 static int reloc_output;
33−static const char *outfile;
33+static char *outfile;
3434 static int do_bench = 0;
3535 static int gen_deps;
3636 static const char *deps_outfile;
@@ -397,7 +397,7 @@ static int parse_args(TCCState *s, int argc, char **argv) · 360 unmodified lines
397397 break;
398398 case TCC_OPTION_o:
399399 multiple_files = 1;
400− outfile = optarg;
400+ outfile = tcc_strdup(optarg);
401401 break;
402402 case TCC_OPTION_r:
403403 /* generate a .o merging several output files */
@@ -488,6 +488,7 @@ int main(int argc, char **argv) · 84 unmodified lines
488488 TCCState *s;
489489 int nb_objfiles, ret, optind;
490490 int64_t start_time = 0;
491+ const char *default_file = NULL;
491492
492493 s = tcc_new();
493494
@@ -541,7 +542,6 @@ int main(int argc, char **argv) · 47 unmodified lines
541542 error("cannot specify libraries with -c");
542543 }
543544
544−
545545 if (output_type == TCC_OUTPUT_PREPROCESS) {
546546 if (!outfile) {
547547 s->outfile = stdout;
@@ -574,6 +574,8 @@ int main(int argc, char **argv) · 26 unmodified lines
574574 printf("-> %s\n", filename);
575575 if (tcc_add_file(s, filename) < 0)
576576 ret = 1;
577+ if (!default_file)
578+ default_file = filename;
577579 }
578580 }
579581
@@ -584,17 +586,15 @@ int main(int argc, char **argv) · 4 unmodified lines
584586 if (do_bench)
585587 tcc_print_stats(s, getclock_us() - start_time);
586588
587− if (s->output_type == TCC_OUTPUT_MEMORY)
589+ if (s->output_type == TCC_OUTPUT_MEMORY) {
588590 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);
598598 /* dump collected dependencies */
599599 if (gen_deps && !ret)
600600 tcc_gen_makedeps(s, outfile, deps_outfile);
@@ -602,6 +602,7 @@ int main(int argc, char **argv) · 1 unmodified line
602602 }
603603
604604 tcc_delete(s);
605+ tcc_free(outfile);
605606
606607 #ifdef MEM_DEBUG
607608 if (do_bench) {
tcc.h+3−6
@@ -580,12 +580,6 @@ struct TCCState { · 579 unmodified lines
580580 /* output file for preprocessing */
581581 FILE *outfile;
582582
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−
589583 /* automatically collected dependencies for this compilation */
590584 char **target_deps;
591585 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
10231017 PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
10241018 PUB_FUNC void set_num_callers(int n);
10251019
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+
10261023 /* ------------ tccpp.c ------------ */
10271024
10281025 ST_DATA struct BufferedFile *file;

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