diff options
| author | Kirill Smelkov <kirr@landau.phys.spbu.ru> | 2010-06-16 16:54:24 +0400 |
|---|---|---|
| committer | Kirill Smelkov <kirr@mns.spb.ru> | 2010-06-20 21:36:47 +0400 |
| commit | bdae4a59c3a74b2ff464c02029c625251719a7d7 (patch) | |
| tree | ff92d915614eeecb0516f1c9015007d8c44b53c7 /libtcc.c | |
| parent | a919a373da07305e763d1cb4ecb3a5a44bdebb2a (diff) | |
| download | tinycc-bdae4a59c3a74b2ff464c02029c625251719a7d7.tar.gz tinycc-bdae4a59c3a74b2ff464c02029c625251719a7d7.tar.bz2 | |
tcc: Refactor "compute default outfile name" into libtcc function
Since for upcoming -MD support default _compile_ output file be needed
even when preprocesssing (tcc -E), let's move this code out of one
particular condition block into a common function, so that we could use
it in deps generation code too.
v2:
- As suggested by grischka, moved into libtcc function instead of always
computing near start of main()
- There is a FIXME about how to return result - I don't want to bother
callers with allocating temp buffers, not I think it will be a good
idea to hook default_target to TCCState. Clearly, I'm to used to
things like std::string and python's str...
Diffstat (limited to 'libtcc.c')
| -rw-r--r-- | libtcc.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -1557,3 +1557,31 @@ 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 && *ext) + strcpy(ext, ".o"); + else + pstrcpy(outfile_default, sizeof(outfile_default), "a.out"); + + return outfile_default; +} |
