libtcc: cleanup the 'gen_makedeps' stuff
This commit is contained in:
		
							parent
							
								
									39a07cca58
								
							
						
					
					
						commit
						e6f3bf7f08
					
				
					 4 changed files with 30 additions and 55 deletions
				
			
		
							
								
								
									
										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->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);
 | 
			
		||||
 | 
			
		||||
    tcc_free(s1->tcc_lib_path);
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_SELINUX
 | 
			
		||||
    munmap (s1->write_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)
 | 
			
		||||
{
 | 
			
		||||
    dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename));
 | 
			
		||||
    if (s->output_type == TCC_OUTPUT_PREPROCESS)
 | 
			
		||||
        return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
 | 
			
		||||
    else
 | 
			
		||||
| 
						 | 
				
			
			@ -1250,8 +1247,6 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
 | 
			
		|||
    char buf[1024];
 | 
			
		||||
    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 */
 | 
			
		||||
    if (!s->static_link) {
 | 
			
		||||
#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 */
 | 
			
		||||
    static char outfile_default[1024];
 | 
			
		||||
 | 
			
		||||
    char buf[1024];
 | 
			
		||||
    char *ext;
 | 
			
		||||
    const char *name =
 | 
			
		||||
        strcmp(s->input_files[0], "-") == 0 ? "a"
 | 
			
		||||
                                            : tcc_basename(s->input_files[0]);
 | 
			
		||||
    pstrcpy(outfile_default, sizeof(outfile_default), name);
 | 
			
		||||
    ext = tcc_fileextension(outfile_default);
 | 
			
		||||
    const char *name = "a";
 | 
			
		||||
 | 
			
		||||
    if (default_file && strcmp(default_file, "-"))
 | 
			
		||||
        name = tcc_basename(default_file);
 | 
			
		||||
    pstrcpy(buf, sizeof(buf), name);
 | 
			
		||||
    ext = tcc_fileextension(buf);
 | 
			
		||||
#ifdef TCC_TARGET_PE
 | 
			
		||||
    if (s->output_type == TCC_OUTPUT_DLL)
 | 
			
		||||
        strcpy(ext, ".dll");
 | 
			
		||||
| 
						 | 
				
			
			@ -1632,21 +1626,18 @@ LIBTCCAPI const char *tcc_default_target(TCCState *s)
 | 
			
		|||
        && *ext)
 | 
			
		||||
        strcpy(ext, ".o");
 | 
			
		||||
    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;
 | 
			
		||||
    char buf[1024], *ext;
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    if (!target)
 | 
			
		||||
        target = tcc_default_target(s);
 | 
			
		||||
 | 
			
		||||
    if (!filename) {
 | 
			
		||||
        /* compute filename automatically
 | 
			
		||||
         * 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 */
 | 
			
		||||
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
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										23
									
								
								tcc.c
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								tcc.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -30,7 +30,7 @@ static int multiple_files;
 | 
			
		|||
static int print_search_dirs;
 | 
			
		||||
static int output_type;
 | 
			
		||||
static int reloc_output;
 | 
			
		||||
static const char *outfile;
 | 
			
		||||
static char *outfile;
 | 
			
		||||
static int do_bench = 0;
 | 
			
		||||
static int gen_deps;
 | 
			
		||||
static const char *deps_outfile;
 | 
			
		||||
| 
						 | 
				
			
			@ -397,7 +397,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
 | 
			
		|||
                break;
 | 
			
		||||
            case TCC_OPTION_o:
 | 
			
		||||
                multiple_files = 1;
 | 
			
		||||
                outfile = optarg;
 | 
			
		||||
                outfile = tcc_strdup(optarg);
 | 
			
		||||
                break;
 | 
			
		||||
            case TCC_OPTION_r:
 | 
			
		||||
                /* generate a .o merging several output files */
 | 
			
		||||
| 
						 | 
				
			
			@ -488,6 +488,7 @@ int main(int argc, char **argv)
 | 
			
		|||
    TCCState *s;
 | 
			
		||||
    int nb_objfiles, ret, optind;
 | 
			
		||||
    int64_t start_time = 0;
 | 
			
		||||
    const char *default_file = NULL;
 | 
			
		||||
 | 
			
		||||
    s = tcc_new();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -541,7 +542,6 @@ int main(int argc, char **argv)
 | 
			
		|||
            error("cannot specify libraries with -c");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if (output_type == TCC_OUTPUT_PREPROCESS) {
 | 
			
		||||
        if (!outfile) {
 | 
			
		||||
            s->outfile = stdout;
 | 
			
		||||
| 
						 | 
				
			
			@ -574,6 +574,8 @@ int main(int argc, char **argv)
 | 
			
		|||
                printf("-> %s\n", filename);
 | 
			
		||||
            if (tcc_add_file(s, filename) < 0)
 | 
			
		||||
                ret = 1;
 | 
			
		||||
            if (!default_file)
 | 
			
		||||
                default_file = filename;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -584,17 +586,15 @@ int main(int argc, char **argv)
 | 
			
		|||
        if (do_bench)
 | 
			
		||||
            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);
 | 
			
		||||
        else {
 | 
			
		||||
            if (s->output_type == TCC_OUTPUT_PREPROCESS) {
 | 
			
		||||
                if (outfile)
 | 
			
		||||
        } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
 | 
			
		||||
             if (s->outfile)
 | 
			
		||||
                fclose(s->outfile);
 | 
			
		||||
        } else {
 | 
			
		||||
                ret = tcc_output_file(s, outfile ? outfile : tcc_default_target(s));
 | 
			
		||||
                ret = ret ? 1 : 0;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!outfile)
 | 
			
		||||
                outfile = tcc_default_target(s, default_file);
 | 
			
		||||
            ret = !!tcc_output_file(s, outfile);
 | 
			
		||||
            /* dump collected dependencies */
 | 
			
		||||
            if (gen_deps && !ret)
 | 
			
		||||
                tcc_gen_makedeps(s, outfile, deps_outfile);
 | 
			
		||||
| 
						 | 
				
			
			@ -602,6 +602,7 @@ int main(int argc, char **argv)
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    tcc_delete(s);
 | 
			
		||||
    tcc_free(outfile);
 | 
			
		||||
 | 
			
		||||
#ifdef MEM_DEBUG
 | 
			
		||||
    if (do_bench) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								tcc.h
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								tcc.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -580,12 +580,6 @@ struct TCCState {
 | 
			
		|||
    /* output file for preprocessing */
 | 
			
		||||
    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 */
 | 
			
		||||
    char **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 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 ------------ */
 | 
			
		||||
 | 
			
		||||
ST_DATA struct BufferedFile *file;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue