diff options
| author | Kirill Smelkov <kirr@mns.spb.ru> | 2010-06-21 20:50:32 +0400 |
|---|---|---|
| committer | Kirill Smelkov <kirr@mns.spb.ru> | 2010-06-21 20:50:41 +0400 |
| commit | 9775aea1ab634a74cd4254df85e93d4cbf098cce (patch) | |
| tree | dbdf8823c5c64ef3d4d40749401c9cb129f3521d /libtcc.c | |
| parent | 3ba37e1e3f1d942c3115406cdccf01ce84d53bee (diff) | |
| parent | 2fe5210a33556ed18bc878046d39e25964a52840 (diff) | |
| download | tinycc-9775aea1ab634a74cd4254df85e93d4cbf098cce.tar.gz tinycc-9775aea1ab634a74cd4254df85e93d4cbf098cce.tar.bz2 | |
Merge branch 'kirr/tcc-MD' into mob
Hello up there.
I'm trying to change gcc to tcc for faster develpment on slow machines,
and the first obstacle that turned out was lack of dependency generation
on tcc side.
Attached patches try to fix that.
Thanks,
Kirill
* tcc-MD:
.gitignore += tags
tcc: Explicitly require -l<lib> for libraries
Document what tcc_fileextension does
tcc -E: Let output_default be <file>.o instead of a.out
tcc: Draft suppoprt for -MD/-MF options
tcc: Refactor "compute default outfile name" into libtcc function
Add input files/libs and reloc_output switch to TCCState
tcc: Fix typo in error (it's '%s', not '%s)
chmod a-x i386-gen.c
.gitignore += *.o *.a
.cvsignore -> .gitignore
Diffstat (limited to 'libtcc.c')
| -rw-r--r-- | libtcc.c | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -168,6 +168,10 @@ PUB_FUNC char *tcc_basename(const char *name) return p; } +/* extract extension part of a file + * + * (if no extension, return pointer to end-of-string) + */ PUB_FUNC char *tcc_fileextension (const char *name) { char *b = tcc_basename(name); @@ -1038,6 +1042,11 @@ LIBTCCAPI void tcc_delete(TCCState *s1) 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); + #ifdef HAVE_SELINUX munmap (s1->write_mem, s1->mem_size); munmap (s1->runtime_mem, s1->mem_size); @@ -1088,6 +1097,10 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) goto the_end; } + /* update target deps */ + dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps, + tcc_strdup(filename)); + if (flags & AFF_PREPROCESS) { ret = tcc_preprocess(s1); goto the_end; @@ -1184,6 +1197,8 @@ 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 @@ -1220,6 +1235,8 @@ 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) { @@ -1549,3 +1566,67 @@ PUB_FUNC void set_num_callers(int n) num_callers = n; #endif } + + +LIBTCCAPI const char *tcc_default_target(TCCState *s) +{ + /* FIXME will break in multithreaded case */ + static char outfile_default[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); +#ifdef TCC_TARGET_PE + if (s->output_type == TCC_OUTPUT_DLL) + strcpy(ext, ".dll"); + else + if (s->output_type == TCC_OUTPUT_EXE) + strcpy(ext, ".exe"); + else +#endif + if (( (s->output_type == TCC_OUTPUT_OBJ && !s->reloc_output) || + (s->output_type == TCC_OUTPUT_PREPROCESS) ) + && *ext) + strcpy(ext, ".o"); + else + pstrcpy(outfile_default, sizeof(outfile_default), "a.out"); + + return outfile_default; +} + + +LIBTCCAPI 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 */ + pstrcpy(buf, sizeof(buf), target); + ext = tcc_fileextension(buf); + pstrcpy(ext, sizeof(buf) - (ext-buf), ".d"); + filename = buf; + } + + if (s->verbose) + printf("<- %s\n", filename); + + /* XXX return err codes instead of error() ? */ + depout = fopen(filename, "w"); + if (!depout) + error("could not open '%s'", filename); + + fprintf(depout, "%s : \\\n", target); + for (i=0; i<s->nb_target_deps; ++i) + fprintf(depout, "\t%s \\\n", s->target_deps[i]); + fprintf(depout, "\n"); + fclose(depout); +} |
