mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-04 06:30:10 +08:00
libtcc: cleanup the 'gen_makedeps' stuff
This commit is contained in:
parent
39a07cca58
commit
e6f3bf7f08
35
libtcc.c
35
libtcc.c
@ -1065,12 +1065,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
|
|||||||
dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
|
dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
|
||||||
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
||||||
|
|
||||||
tcc_free(s1->tcc_lib_path);
|
|
||||||
|
|
||||||
dynarray_reset(&s1->input_files, &s1->nb_input_files);
|
|
||||||
dynarray_reset(&s1->input_libs, &s1->nb_input_libs);
|
|
||||||
dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
|
dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
|
||||||
|
|
||||||
|
tcc_free(s1->tcc_lib_path);
|
||||||
|
|
||||||
#ifdef HAVE_SELINUX
|
#ifdef HAVE_SELINUX
|
||||||
munmap (s1->write_mem, s1->mem_size);
|
munmap (s1->write_mem, s1->mem_size);
|
||||||
munmap (s1->runtime_mem, s1->mem_size);
|
munmap (s1->runtime_mem, s1->mem_size);
|
||||||
@ -1215,7 +1213,6 @@ the_end:
|
|||||||
|
|
||||||
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
|
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
|
||||||
{
|
{
|
||||||
dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename));
|
|
||||||
if (s->output_type == TCC_OUTPUT_PREPROCESS)
|
if (s->output_type == TCC_OUTPUT_PREPROCESS)
|
||||||
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
|
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
|
||||||
else
|
else
|
||||||
@ -1250,8 +1247,6 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
dynarray_add((void ***)&s->input_libs, &s->nb_input_libs, tcc_strdup(libraryname));
|
|
||||||
|
|
||||||
/* first we look for the dynamic library if not static linking */
|
/* first we look for the dynamic library if not static linking */
|
||||||
if (!s->static_link) {
|
if (!s->static_link) {
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
@ -1608,17 +1603,16 @@ PUB_FUNC void set_num_callers(int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LIBTCCAPI const char *tcc_default_target(TCCState *s)
|
PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file)
|
||||||
{
|
{
|
||||||
/* FIXME will break in multithreaded case */
|
char buf[1024];
|
||||||
static char outfile_default[1024];
|
|
||||||
|
|
||||||
char *ext;
|
char *ext;
|
||||||
const char *name =
|
const char *name = "a";
|
||||||
strcmp(s->input_files[0], "-") == 0 ? "a"
|
|
||||||
: tcc_basename(s->input_files[0]);
|
if (default_file && strcmp(default_file, "-"))
|
||||||
pstrcpy(outfile_default, sizeof(outfile_default), name);
|
name = tcc_basename(default_file);
|
||||||
ext = tcc_fileextension(outfile_default);
|
pstrcpy(buf, sizeof(buf), name);
|
||||||
|
ext = tcc_fileextension(buf);
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
if (s->output_type == TCC_OUTPUT_DLL)
|
if (s->output_type == TCC_OUTPUT_DLL)
|
||||||
strcpy(ext, ".dll");
|
strcpy(ext, ".dll");
|
||||||
@ -1632,21 +1626,18 @@ LIBTCCAPI const char *tcc_default_target(TCCState *s)
|
|||||||
&& *ext)
|
&& *ext)
|
||||||
strcpy(ext, ".o");
|
strcpy(ext, ".o");
|
||||||
else
|
else
|
||||||
pstrcpy(outfile_default, sizeof(outfile_default), "a.out");
|
pstrcpy(buf, sizeof(buf), "a.out");
|
||||||
|
|
||||||
return outfile_default;
|
return tcc_strdup(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename)
|
PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename)
|
||||||
{
|
{
|
||||||
FILE *depout;
|
FILE *depout;
|
||||||
char buf[1024], *ext;
|
char buf[1024], *ext;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!target)
|
|
||||||
target = tcc_default_target(s);
|
|
||||||
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
/* compute filename automatically
|
/* compute filename automatically
|
||||||
* dir/file.o -> dir/file.d */
|
* dir/file.o -> dir/file.d */
|
||||||
|
14
libtcc.h
14
libtcc.h
@ -103,20 +103,6 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
|
|||||||
/* set CONFIG_TCCDIR at runtime */
|
/* set CONFIG_TCCDIR at runtime */
|
||||||
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
|
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
|
||||||
|
|
||||||
|
|
||||||
/*****************************/
|
|
||||||
/* Miscellaneous */
|
|
||||||
|
|
||||||
/* Get default target filename for this compilation */
|
|
||||||
LIBTCCAPI const char *tcc_default_target(TCCState *s);
|
|
||||||
|
|
||||||
/* Generate make dependencies for target and store them into file
|
|
||||||
*
|
|
||||||
* !target - use default target name
|
|
||||||
* !filename - use (target.o -> target.d)
|
|
||||||
*/
|
|
||||||
LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
27
tcc.c
27
tcc.c
@ -30,7 +30,7 @@ static int multiple_files;
|
|||||||
static int print_search_dirs;
|
static int print_search_dirs;
|
||||||
static int output_type;
|
static int output_type;
|
||||||
static int reloc_output;
|
static int reloc_output;
|
||||||
static const char *outfile;
|
static char *outfile;
|
||||||
static int do_bench = 0;
|
static int do_bench = 0;
|
||||||
static int gen_deps;
|
static int gen_deps;
|
||||||
static const char *deps_outfile;
|
static const char *deps_outfile;
|
||||||
@ -397,7 +397,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case TCC_OPTION_o:
|
case TCC_OPTION_o:
|
||||||
multiple_files = 1;
|
multiple_files = 1;
|
||||||
outfile = optarg;
|
outfile = tcc_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_r:
|
case TCC_OPTION_r:
|
||||||
/* generate a .o merging several output files */
|
/* generate a .o merging several output files */
|
||||||
@ -488,6 +488,7 @@ int main(int argc, char **argv)
|
|||||||
TCCState *s;
|
TCCState *s;
|
||||||
int nb_objfiles, ret, optind;
|
int nb_objfiles, ret, optind;
|
||||||
int64_t start_time = 0;
|
int64_t start_time = 0;
|
||||||
|
const char *default_file = NULL;
|
||||||
|
|
||||||
s = tcc_new();
|
s = tcc_new();
|
||||||
|
|
||||||
@ -541,7 +542,6 @@ int main(int argc, char **argv)
|
|||||||
error("cannot specify libraries with -c");
|
error("cannot specify libraries with -c");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (output_type == TCC_OUTPUT_PREPROCESS) {
|
if (output_type == TCC_OUTPUT_PREPROCESS) {
|
||||||
if (!outfile) {
|
if (!outfile) {
|
||||||
s->outfile = stdout;
|
s->outfile = stdout;
|
||||||
@ -574,6 +574,8 @@ int main(int argc, char **argv)
|
|||||||
printf("-> %s\n", filename);
|
printf("-> %s\n", filename);
|
||||||
if (tcc_add_file(s, filename) < 0)
|
if (tcc_add_file(s, filename) < 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
if (!default_file)
|
||||||
|
default_file = filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,17 +586,15 @@ int main(int argc, char **argv)
|
|||||||
if (do_bench)
|
if (do_bench)
|
||||||
tcc_print_stats(s, getclock_us() - start_time);
|
tcc_print_stats(s, getclock_us() - start_time);
|
||||||
|
|
||||||
if (s->output_type == TCC_OUTPUT_MEMORY)
|
if (s->output_type == TCC_OUTPUT_MEMORY) {
|
||||||
ret = tcc_run(s, argc - optind, argv + optind);
|
ret = tcc_run(s, argc - optind, argv + optind);
|
||||||
else {
|
} else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
||||||
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
if (s->outfile)
|
||||||
if (outfile)
|
fclose(s->outfile);
|
||||||
fclose(s->outfile);
|
} else {
|
||||||
} else {
|
if (!outfile)
|
||||||
ret = tcc_output_file(s, outfile ? outfile : tcc_default_target(s));
|
outfile = tcc_default_target(s, default_file);
|
||||||
ret = ret ? 1 : 0;
|
ret = !!tcc_output_file(s, outfile);
|
||||||
}
|
|
||||||
|
|
||||||
/* dump collected dependencies */
|
/* dump collected dependencies */
|
||||||
if (gen_deps && !ret)
|
if (gen_deps && !ret)
|
||||||
tcc_gen_makedeps(s, outfile, deps_outfile);
|
tcc_gen_makedeps(s, outfile, deps_outfile);
|
||||||
@ -602,6 +602,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tcc_delete(s);
|
tcc_delete(s);
|
||||||
|
tcc_free(outfile);
|
||||||
|
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
if (do_bench) {
|
if (do_bench) {
|
||||||
|
9
tcc.h
9
tcc.h
@ -580,12 +580,6 @@ struct TCCState {
|
|||||||
/* output file for preprocessing */
|
/* output file for preprocessing */
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
|
|
||||||
/* input files and libraries for this compilation */
|
|
||||||
char **input_files;
|
|
||||||
int nb_input_files;
|
|
||||||
char **input_libs;
|
|
||||||
int nb_input_libs;
|
|
||||||
|
|
||||||
/* automatically collected dependencies for this compilation */
|
/* automatically collected dependencies for this compilation */
|
||||||
char **target_deps;
|
char **target_deps;
|
||||||
int nb_target_deps;
|
int nb_target_deps;
|
||||||
@ -1023,6 +1017,9 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value);
|
|||||||
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
|
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
|
||||||
PUB_FUNC void set_num_callers(int n);
|
PUB_FUNC void set_num_callers(int n);
|
||||||
|
|
||||||
|
PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file);
|
||||||
|
PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
|
||||||
|
|
||||||
/* ------------ tccpp.c ------------ */
|
/* ------------ tccpp.c ------------ */
|
||||||
|
|
||||||
ST_DATA struct BufferedFile *file;
|
ST_DATA struct BufferedFile *file;
|
||||||
|
Loading…
Reference in New Issue
Block a user