History

Revert "ability to compile multiple *.c files with -c switch"

copy & paste coding, twisted control flow This reverts commit a13f183e4c2c4b4d1d40e142b57a4298672dfd2c. Also, set linker args for DLLs also.

grischka committed 10 years ago

Commit e6301131 parent 3ddbfe12 files · +24 −48Browse files

Unified · Split

2 files
  1. libtcc.c +5 −16
  2. tcc.c +19 −32
libtcc.c+5−16
@@ -1061,7 +1061,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 1060 unmodified lines
10611061 #else
10621062 tcc_set_lib_path(s, CONFIG_TCCDIR);
10631063 #endif
1064− s->output_type = 0;
1064+
10651065 preprocess_new();
10661066 s->include_stack_ptr = s->include_stack;
10671067
@@ -1229,10 +1229,6 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 161 unmodified lines
12291229
12301230 tcc_cleanup();
12311231
1232− /* close a preprocessor output */
1233− if (s1->ppfp && s1->ppfp != stdout)
1234− fclose(s1->ppfp);
1235−
12361232 /* free all sections */
12371233 for(i = 1; i < s1->nb_sections; i++)
12381234 free_section(s1->sections[i]);
@@ -1609,16 +1605,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 370 unmodified lines
16091605 {
16101606 s->output_type = output_type;
16111607
1612− if (s->output_type == TCC_OUTPUT_PREPROCESS) {
1613− if (!s->outfile) {
1614− s->ppfp = stdout;
1615− } else {
1616− s->ppfp = fopen(s->outfile, "w");
1617− if (!s->ppfp)
1618− tcc_error("could not write '%s'", s->outfile);
1619− }
1620− }
1621−
16221608 if (!s->nostdinc) {
16231609 /* default include paths */
16241610 /* -isystem paths have already been handled */
@@ -2289,6 +2275,9 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) · 664 unmodified lines
22892275 s->print_search_dirs = 1;
22902276 break;
22912277 case TCC_OPTION_run:
2278+#ifndef TCC_IS_NATIVE
2279+ tcc_error("-run is not available in a cross compiler");
2280+#endif
22922281 if (s->output_type)
22932282 tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
22942283 s->output_type = TCC_OUTPUT_MEMORY;
@@ -2397,7 +2386,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 102 unmodified lines
23972386 s->nb_libraries++;
23982387 }
23992388
2400− if (s->output_type == TCC_OUTPUT_EXE)
2389+ if (s->output_type == TCC_OUTPUT_EXE || s->output_type == TCC_OUTPUT_DLL)
24012390 tcc_set_linker(s, (const char *)pas->linker_arg.data);
24022391
24032392 if (is_allocated) {
tcc.c+19−32
@@ -223,9 +223,7 @@ static char *default_outputfile(TCCState *s, const char *first_file) · 222 unmodified lines
223223 strcpy(ext, ".exe");
224224 else
225225 #endif
226− if (( (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) ||
227− (s->output_type == TCC_OUTPUT_PREPROCESS) )
228− && *ext)
226+ if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r && *ext)
229227 strcpy(ext, ".o");
230228 else
231229 strcpy(buf, "a.out");
@@ -252,6 +250,7 @@ int main(int argc, char **argv) · 20 unmodified lines
252250 TCCState *s;
253251 int ret, optind, i;
254252 int64_t start_time = 0;
253+ const char *first_file = NULL;
255254
256255 s = tcc_new();
257256
@@ -290,13 +289,22 @@ int main(int argc, char **argv) · 32 unmodified lines
290289 if (s->nb_libraries != 0)
291290 tcc_error("cannot specify libraries with -c");
292291 /* accepts only a single input file */
293− if ((s->nb_files != 1) && s->outfile) {
294− tcc_error("cannot specify multiple files with -c and -o");
295− }
292+ if (s->nb_files != 1)
293+ tcc_error("cannot specify multiple files with -c");
296294 }
297295
298296 tcc_set_output_type(s, s->output_type);
299297
298+ if (s->output_type == TCC_OUTPUT_PREPROCESS) {
299+ if (!s->outfile) {
300+ s->ppfp = stdout;
301+ } else {
302+ s->ppfp = fopen(s->outfile, "w");
303+ if (!s->ppfp)
304+ tcc_error("could not write '%s'", s->outfile);
305+ }
306+ }
307+
300308 /* compile or add each files or library */
301309 for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
302310 int filetype = *(unsigned char *)s->files[i];
@@ -312,27 +320,10 @@ int main(int argc, char **argv) · 9 unmodified lines
312320 } else {
313321 if (1 == s->verbose)
314322 printf("-> %s\n", filename);
315− if (!s->outfile)
316− s->outfile = default_outputfile(s, filename);
317323 if (tcc_add_file(s, filename, filetype) < 0)
318324 ret = 1;
319− else
320− if (s->output_type == TCC_OUTPUT_OBJ) {
321− ret = !!tcc_output_file(s, s->outfile);
322− if (s->gen_deps && !ret)
323− gen_makedeps(s, s->outfile, s->deps_outfile);
324− if (!ret) {
325− if ((i+1) < s->nb_files) {
326− tcc_delete(s);
327− s = tcc_new();
328− tcc_parse_args(s, argc - 1, argv + 1);
329− tcc_set_environment(s);
330− if (s->output_type != TCC_OUTPUT_OBJ)
331− tcc_error("internal error");
332− tcc_set_output_type(s, s->output_type);
333− }
334− }
335− }
325+ if (!first_file)
326+ first_file = filename;
336327 }
337328 }
338329
@@ -340,14 +331,10 @@ int main(int argc, char **argv) · 1 unmodified line
340331 if (s->output_type == TCC_OUTPUT_MEMORY) {
341332 #ifdef TCC_IS_NATIVE
342333 ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind);
343−#else
344− tcc_error_noabort("-run is not available in a cross compiler");
345− ret = 1;
346334 #endif
347− } else
348− if (s->output_type == TCC_OUTPUT_EXE ||
349− s->output_type == TCC_OUTPUT_DLL)
350− {
335+ } else {
336+ if (!s->outfile)
337+ s->outfile = default_outputfile(s, first_file);
351338 ret = !!tcc_output_file(s, s->outfile);
352339 if (s->gen_deps && !ret)
353340 gen_makedeps(s, s->outfile, s->deps_outfile);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t