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