Warn about a conflicting compile options spectified on the command line.

Try "tcc -E -c tccasm.c -o tccasm.o"
This commit is contained in:
seyko 2015-01-06 22:19:45 +03:00
parent b93179f3c0
commit c334b59142
3 changed files with 19 additions and 7 deletions

View File

@ -906,7 +906,7 @@ LIBTCCAPI TCCState *tcc_new(void)
#else #else
tcc_set_lib_path(s, CONFIG_TCCDIR); tcc_set_lib_path(s, CONFIG_TCCDIR);
#endif #endif
s->output_type = TCC_OUTPUT_MEMORY; s->output_type = 0;
preprocess_new(); preprocess_new();
s->include_stack_ptr = s->include_stack; s->include_stack_ptr = s->include_stack;
@ -1831,6 +1831,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
s->do_debug = 1; s->do_debug = 1;
break; break;
case TCC_OPTION_c: case TCC_OPTION_c:
if (s->output_type)
tcc_warning("-c: some compiler action already specified (%d)", s->output_type);
s->output_type = TCC_OUTPUT_OBJ; s->output_type = TCC_OUTPUT_OBJ;
break; break;
#ifdef TCC_TARGET_ARM #ifdef TCC_TARGET_ARM
@ -1849,6 +1851,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
s->static_link = 1; s->static_link = 1;
break; break;
case TCC_OPTION_shared: case TCC_OPTION_shared:
if (s->output_type)
tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);
s->output_type = TCC_OUTPUT_DLL; s->output_type = TCC_OUTPUT_DLL;
break; break;
case TCC_OPTION_soname: case TCC_OPTION_soname:
@ -1862,6 +1866,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
break; break;
case TCC_OPTION_r: case TCC_OPTION_r:
/* generate a .o merging several output files */ /* generate a .o merging several output files */
if (s->output_type)
tcc_warning("-r: some compiler action already specified (%d)", s->output_type);
s->option_r = 1; s->option_r = 1;
s->output_type = TCC_OUTPUT_OBJ; s->output_type = TCC_OUTPUT_OBJ;
break; break;
@ -1878,6 +1884,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
s->print_search_dirs = 1; s->print_search_dirs = 1;
break; break;
case TCC_OPTION_run: case TCC_OPTION_run:
if (s->output_type)
tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
s->output_type = TCC_OUTPUT_MEMORY; s->output_type = TCC_OUTPUT_MEMORY;
tcc_set_options(s, optarg); tcc_set_options(s, optarg);
run = 1; run = 1;
@ -1907,6 +1915,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
cstr_ccat(&linker_arg, '\0'); cstr_ccat(&linker_arg, '\0');
break; break;
case TCC_OPTION_E: case TCC_OPTION_E:
if (s->output_type)
tcc_warning("-E: some compiler action already specified (%d)", s->output_type);
s->output_type = TCC_OUTPUT_PREPROCESS; s->output_type = TCC_OUTPUT_PREPROCESS;
break; break;
case TCC_OPTION_MD: case TCC_OPTION_MD:

View File

@ -58,11 +58,11 @@ LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
/* set output type. MUST BE CALLED before any compilation */ /* set output type. MUST BE CALLED before any compilation */
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type); LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
#define TCC_OUTPUT_MEMORY 0 /* output will be run in memory (default) */ #define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
#define TCC_OUTPUT_EXE 1 /* executable file */ #define TCC_OUTPUT_EXE 2 /* executable file */
#define TCC_OUTPUT_DLL 2 /* dynamic library */ #define TCC_OUTPUT_DLL 3 /* dynamic library */
#define TCC_OUTPUT_OBJ 3 /* object file */ #define TCC_OUTPUT_OBJ 4 /* object file */
#define TCC_OUTPUT_PREPROCESS 4 /* only preprocess (used internally) */ #define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
/* equivalent to -Lpath option */ /* equivalent to -Lpath option */
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname); LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);

4
tcc.c
View File

@ -249,7 +249,6 @@ int main(int argc, char **argv)
const char *first_file = NULL; const char *first_file = NULL;
s = tcc_new(); s = tcc_new();
s->output_type = TCC_OUTPUT_EXE;
optind = tcc_parse_args(s, argc - 1, argv + 1); optind = tcc_parse_args(s, argc - 1, argv + 1);
tcc_set_environment(s); tcc_set_environment(s);
@ -259,6 +258,9 @@ int main(int argc, char **argv)
return 1; return 1;
} }
if (s->output_type == 0)
s->output_type = TCC_OUTPUT_EXE;
if (s->option_m) if (s->option_m)
exec_other_tcc(s, argv, s->option_m); exec_other_tcc(s, argv, s->option_m);