2001-11-01 22:48:10 +08:00
|
|
|
/*
|
|
|
|
* TCC - Tiny C Compiler
|
2015-07-30 04:53:57 +08:00
|
|
|
*
|
2004-10-28 05:38:03 +08:00
|
|
|
* Copyright (c) 2001-2004 Fabrice Bellard
|
2001-11-01 22:48:10 +08:00
|
|
|
*
|
2003-05-24 22:11:17 +08:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2001-11-01 22:48:10 +08:00
|
|
|
*
|
2003-05-24 22:11:17 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-11-01 22:48:10 +08:00
|
|
|
*
|
2003-05-24 22:11:17 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-11-01 22:48:10 +08:00
|
|
|
*/
|
2003-04-14 03:49:30 +08:00
|
|
|
|
2011-07-15 00:45:37 +08:00
|
|
|
#ifdef ONE_SOURCE
|
2009-05-06 02:18:53 +08:00
|
|
|
#include "libtcc.c"
|
2011-07-15 00:45:37 +08:00
|
|
|
#else
|
|
|
|
#include "tcc.h"
|
2009-07-19 04:08:01 +08:00
|
|
|
#endif
|
2009-04-18 19:17:27 +08:00
|
|
|
|
2015-03-03 21:08:33 +08:00
|
|
|
static void print_paths(const char *msg, char **paths, int nb_paths)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf("%s:\n%s", msg, nb_paths ? "" : " -\n");
|
|
|
|
for(i = 0; i < nb_paths; i++)
|
|
|
|
printf(" %s\n", paths[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_info(TCCState *s, int what)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case 0:
|
|
|
|
printf("tcc version %s ("
|
|
|
|
#ifdef TCC_TARGET_I386
|
|
|
|
"i386"
|
|
|
|
#elif defined TCC_TARGET_X86_64
|
|
|
|
"x86-64"
|
2015-03-04 03:30:24 +08:00
|
|
|
#elif defined TCC_TARGET_C67
|
|
|
|
"C67"
|
2015-03-03 21:08:33 +08:00
|
|
|
#elif defined TCC_TARGET_ARM
|
|
|
|
"ARM"
|
|
|
|
# ifdef TCC_ARM_HARDFLOAT
|
|
|
|
" Hard Float"
|
|
|
|
# endif
|
|
|
|
#elif defined TCC_TARGET_ARM64
|
|
|
|
"AArch64"
|
|
|
|
# ifdef TCC_ARM_HARDFLOAT
|
|
|
|
" Hard Float"
|
|
|
|
# endif
|
|
|
|
#endif
|
2015-03-04 03:30:24 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
" Windows"
|
2016-10-15 15:47:08 +08:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
/* Current Apple OS name as of 2016 */
|
|
|
|
" macOS"
|
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
|
|
" FreeBSD"
|
|
|
|
#elif defined(__DragonFly__)
|
2016-10-16 12:12:55 +08:00
|
|
|
" DragonFly BSD"
|
2016-10-15 15:47:08 +08:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
" NetBSD"
|
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
" OpenBSD"
|
|
|
|
#elif defined(__linux__)
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
" Linux"
|
2016-10-15 15:47:08 +08:00
|
|
|
#else
|
|
|
|
" Unidentified system"
|
2015-03-03 21:08:33 +08:00
|
|
|
#endif
|
|
|
|
")\n", TCC_VERSION);
|
|
|
|
break;
|
|
|
|
case 1:
|
2015-03-04 02:41:22 +08:00
|
|
|
printf("install: %s\n", s->tcc_lib_path);
|
2015-03-03 21:08:33 +08:00
|
|
|
/* print_paths("programs", NULL, 0); */
|
|
|
|
print_paths("include", s->sysinclude_paths, s->nb_sysinclude_paths);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
print_paths("libraries", s->library_paths, s->nb_library_paths);
|
|
|
|
#ifndef TCC_TARGET_PE
|
|
|
|
print_paths("crt", s->crt_paths, s->nb_crt_paths);
|
2015-03-03 21:08:33 +08:00
|
|
|
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
#endif
|
2015-03-03 21:08:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
static void help(void)
|
2002-05-14 07:00:17 +08:00
|
|
|
{
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
printf("Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n"
|
2010-09-09 01:13:36 +08:00
|
|
|
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
|
|
|
|
" tcc [options...] -run infile [arguments...]\n"
|
2002-07-16 06:17:02 +08:00
|
|
|
"General options:\n"
|
|
|
|
" -c compile only - generate an object file\n"
|
2002-07-25 06:10:59 +08:00
|
|
|
" -o outfile set output filename\n"
|
2007-11-15 01:34:30 +08:00
|
|
|
" -run run compiled source\n"
|
2003-10-18 04:43:47 +08:00
|
|
|
" -fflag set or reset (with 'no-' prefix) 'flag' (see man page)\n"
|
|
|
|
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see man page)\n"
|
2003-09-20 04:35:50 +08:00
|
|
|
" -w disable all warnings\n"
|
2013-02-11 03:39:05 +08:00
|
|
|
" -v show version\n"
|
|
|
|
" -vv show included files (as sole argument: show search paths)\n"
|
|
|
|
" -bench show compilation statistics\n"
|
2002-07-16 06:17:02 +08:00
|
|
|
"Preprocessor options:\n"
|
|
|
|
" -Idir add include path 'dir'\n"
|
|
|
|
" -Dsym[=val] define 'sym' with value 'val'\n"
|
|
|
|
" -Usym undefine 'sym'\n"
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
" -E preprocess only\n"
|
2016-05-05 20:12:53 +08:00
|
|
|
" -P[1] no / alternative #line output with -E\n"
|
|
|
|
" -dD -dM output #define directives with -E\n"
|
2017-02-14 02:03:29 +08:00
|
|
|
" -include file include file above each input file\n"
|
2002-07-16 06:17:02 +08:00
|
|
|
"Linker options:\n"
|
2002-07-22 08:20:38 +08:00
|
|
|
" -Ldir add library path 'dir'\n"
|
2002-08-18 21:22:55 +08:00
|
|
|
" -llib link with dynamic or static library 'lib'\n"
|
2013-02-11 03:39:05 +08:00
|
|
|
" -r generate (relocatable) object file\n"
|
2002-07-28 07:08:04 +08:00
|
|
|
" -shared generate a shared library\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
" -rdynamic export all global symbols to dynamic linker\n"
|
2008-03-26 05:04:47 +08:00
|
|
|
" -soname set name for shared library to be used at runtime\n"
|
2002-07-25 06:10:59 +08:00
|
|
|
" -static static linking\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
" -pthread link with -lpthread and -D_REENTRANT (POSIX Linux)\n"
|
2013-02-13 02:13:28 +08:00
|
|
|
" -Wl,-opt[=val] set linker option (see manual)\n"
|
2002-11-03 08:43:55 +08:00
|
|
|
"Debugger options:\n"
|
|
|
|
" -g generate runtime debug info\n"
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
" -b compile with built-in memory and bounds checker (implies -g)\n"
|
|
|
|
#endif
|
2009-04-19 00:21:38 +08:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2002-11-03 08:43:55 +08:00
|
|
|
" -bt N show N callers in stack traces\n"
|
2009-04-19 00:21:38 +08:00
|
|
|
#endif
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
"Misc options:\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
" -x[c|a|n] specify type of the next infile\n"
|
2013-02-13 02:13:28 +08:00
|
|
|
" -nostdinc do not use standard system include paths\n"
|
|
|
|
" -nostdlib do not link with standard crt and libraries\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
" -Bdir use 'dir' as tcc's private library/include path\n"
|
tcc: Draft suppoprt for -MD/-MF options
In build systems, this is used to automatically collect target
dependencies, e.g.
---- 8< (hello.c) ----
#include "hello.h"
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
$ tcc -MD -c hello.c # -> hello.o, hello.d
$ cat hello.d
hello.o : \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate
dependencies for whatever action is being taken. E.g. for .c -> exe, the
result will be:
$ tcc -MD -o hello hello.c # -> hello, hello.d
hello: \
/usr/lib/crt1.o \
/usr/lib/crti.o \
hello.c \
hello.h \
/usr/include/stdio.h \
/usr/include/features.h \
/usr/include/bits/predefs.h \
/usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs.h \
/usr/include/bits/wordsize.h \
/usr/include/gnu/stubs-32.h \
/home/kirr/local/tcc/lib/tcc/include/stddef.h \
/usr/include/bits/types.h \
/usr/include/bits/wordsize.h \
/usr/include/bits/typesizes.h \
/usr/include/libio.h \
/usr/include/_G_config.h \
/usr/include/wchar.h \
/home/kirr/local/tcc/lib/tcc/include/stdarg.h \
/usr/include/bits/stdio_lim.h \
/usr/include/bits/sys_errlist.h \
/usr/lib/libc.so \
/lib/libc.so.6 \
/usr/lib/ld-linux.so.2 \
/lib/ld-linux.so.2 \
/usr/lib/libc_nonshared.a \
/lib/libc.so.6 \
/usr/lib/libc_nonshared.a \
/home/kirr/local/tcc/lib/tcc/libtcc1.a \
/usr/lib/crtn.o \
So tcc dependency generator is a bit more clever than one used in gcc :)
Also, I've updated TODO and Changelog (in not-yet-released section).
v2:
(Taking inputs from grischka and me myself)
- put code to generate deps file into a function.
- used tcc_fileextension() instead of open-coding
- generate deps only when compilation/preprocessing was successful
v3:
- use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
2010-06-21 00:08:12 +08:00
|
|
|
" -MD generate target dependencies for make\n"
|
|
|
|
" -MF depfile put generated dependencies here\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
" -dumpversion print version\n"
|
|
|
|
" - use stdin pipe as infile\n"
|
|
|
|
" @listfile read arguments from listfile\n"
|
|
|
|
"Target specific options:\n"
|
|
|
|
" -m32/64 execute i386/x86-64 cross compiler\n"
|
|
|
|
" -mms-bitfields use MSVC bitfield layout\n"
|
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
" -mfloat-abi hard/softfp on arm\n"
|
|
|
|
#endif
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
" -mno-sse disable floats on x86-64\n"
|
|
|
|
#endif
|
2002-05-14 07:00:17 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-08-06 22:08:33 +08:00
|
|
|
/* re-execute the i386/x86_64 cross-compilers with tcc -m32/-m64: */
|
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
2010-12-07 08:17:20 +08:00
|
|
|
#ifdef _WIN32
|
2011-08-06 22:08:33 +08:00
|
|
|
#include <process.h>
|
2017-02-09 02:49:28 +08:00
|
|
|
|
|
|
|
static char *str_replace(const char *str, const char *p, const char *r)
|
|
|
|
{
|
|
|
|
const char *s, *s0;
|
|
|
|
char *d, *d0;
|
|
|
|
int sl, pl, rl;
|
|
|
|
|
|
|
|
sl = strlen(str);
|
|
|
|
pl = strlen(p);
|
|
|
|
rl = strlen(r);
|
|
|
|
for (d0 = NULL;; d0 = tcc_malloc(sl + 1)) {
|
|
|
|
for (d = d0, s = str; s0 = s, s = strstr(s, p), s; s += pl) {
|
|
|
|
if (d) {
|
|
|
|
memcpy(d, s0, sl = s - s0), d += sl;
|
|
|
|
memcpy(d, r, rl), d += rl;
|
|
|
|
} else
|
|
|
|
sl += rl - pl;
|
|
|
|
}
|
|
|
|
if (d) {
|
|
|
|
strcpy(d, s0);
|
|
|
|
return d0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-06 22:08:33 +08:00
|
|
|
static int execvp_win32(const char *prog, char **argv)
|
2010-12-08 16:27:06 +08:00
|
|
|
{
|
2017-02-09 02:49:28 +08:00
|
|
|
int ret; char **p;
|
|
|
|
/* replace all " by \" */
|
|
|
|
for (p = argv; *p; ++p)
|
|
|
|
if (strchr(*p, '"'))
|
|
|
|
*p = str_replace(*p, "\"", "\\\"");
|
|
|
|
ret = _spawnvp(P_NOWAIT, prog, (const char *const*)argv);
|
2011-08-06 22:08:33 +08:00
|
|
|
if (-1 == ret)
|
|
|
|
return ret;
|
|
|
|
cwait(&ret, ret, WAIT_CHILD);
|
|
|
|
exit(ret);
|
2010-12-07 08:17:20 +08:00
|
|
|
}
|
2011-08-06 22:08:33 +08:00
|
|
|
#define execvp execvp_win32
|
|
|
|
#endif
|
2016-12-19 05:57:03 +08:00
|
|
|
static void exec_other_tcc(TCCState *s, char **argv, int option)
|
2010-12-08 16:27:06 +08:00
|
|
|
{
|
2017-02-09 02:49:28 +08:00
|
|
|
char child_path[4096], *a0 = argv[0]; const char *target;
|
|
|
|
int l;
|
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
switch (option) {
|
2017-02-09 02:49:28 +08:00
|
|
|
|
2011-08-06 22:08:33 +08:00
|
|
|
#ifdef TCC_TARGET_I386
|
|
|
|
case 32: break;
|
|
|
|
case 64: target = "x86_64";
|
|
|
|
#else
|
|
|
|
case 64: break;
|
|
|
|
case 32: target = "i386";
|
2017-02-09 02:49:28 +08:00
|
|
|
|
2011-08-06 22:08:33 +08:00
|
|
|
#endif
|
2017-02-09 02:49:28 +08:00
|
|
|
l = tcc_basename(a0) - a0;
|
|
|
|
snprintf(child_path, sizeof child_path,
|
2011-08-06 22:08:33 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
2017-02-09 02:49:28 +08:00
|
|
|
"%.*s%s-win32-tcc"
|
|
|
|
#else
|
|
|
|
"%.*s%s-tcc"
|
2011-08-06 22:08:33 +08:00
|
|
|
#endif
|
2017-02-09 02:49:28 +08:00
|
|
|
, l, a0, target);
|
|
|
|
if (strcmp(a0, child_path)) {
|
2011-08-06 22:08:33 +08:00
|
|
|
if (s->verbose > 0)
|
2017-02-09 02:49:28 +08:00
|
|
|
printf("tcc: using '%s'\n", child_path + l), fflush(stdout);
|
2011-08-06 22:08:33 +08:00
|
|
|
execvp(argv[0] = child_path, argv);
|
|
|
|
}
|
2017-02-09 02:49:28 +08:00
|
|
|
tcc_error("'%s' not found", child_path + l);
|
2010-12-08 16:27:06 +08:00
|
|
|
}
|
|
|
|
}
|
2013-02-13 02:13:28 +08:00
|
|
|
#else
|
2016-12-19 05:57:03 +08:00
|
|
|
#define exec_other_tcc(s, argv, option)
|
2010-12-08 16:27:06 +08:00
|
|
|
#endif
|
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
static void gen_makedeps(TCCState *s, const char *target, const char *filename)
|
2011-08-11 22:55:30 +08:00
|
|
|
{
|
2013-02-13 02:13:28 +08:00
|
|
|
FILE *depout;
|
2017-02-09 02:49:28 +08:00
|
|
|
char buf[1024];
|
2013-02-13 02:13:28 +08:00
|
|
|
int i;
|
2011-08-11 22:55:30 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
if (!filename) {
|
2017-02-09 02:49:28 +08:00
|
|
|
/* compute filename automatically: dir/file.o -> dir/file.d */
|
|
|
|
snprintf(buf, sizeof buf, "%.*s.d",
|
|
|
|
(int)(tcc_fileextension(target) - target), target);
|
2013-02-13 02:13:28 +08:00
|
|
|
filename = buf;
|
|
|
|
}
|
2011-01-04 17:17:52 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
if (s->verbose)
|
|
|
|
printf("<- %s\n", filename);
|
|
|
|
|
|
|
|
/* XXX return err codes instead of error() ? */
|
|
|
|
depout = fopen(filename, "w");
|
|
|
|
if (!depout)
|
|
|
|
tcc_error("could not open '%s'", filename);
|
|
|
|
|
2016-06-28 00:47:09 +08:00
|
|
|
fprintf(depout, "%s: \\\n", target);
|
2013-02-13 02:13:28 +08:00
|
|
|
for (i=0; i<s->nb_target_deps; ++i)
|
|
|
|
fprintf(depout, " %s \\\n", s->target_deps[i]);
|
|
|
|
fprintf(depout, "\n");
|
|
|
|
fclose(depout);
|
|
|
|
}
|
2012-04-19 00:32:37 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
static char *default_outputfile(TCCState *s, const char *first_file)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
char *ext;
|
|
|
|
const char *name = "a";
|
|
|
|
|
|
|
|
if (first_file && strcmp(first_file, "-"))
|
|
|
|
name = tcc_basename(first_file);
|
2017-02-09 02:49:28 +08:00
|
|
|
snprintf(buf, sizeof(buf), "%s", name);
|
2013-02-13 02:13:28 +08:00
|
|
|
ext = tcc_fileextension(buf);
|
|
|
|
#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
|
2016-10-02 02:04:33 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r && *ext)
|
2013-02-13 02:13:28 +08:00
|
|
|
strcpy(ext, ".o");
|
|
|
|
else
|
|
|
|
strcpy(buf, "a.out");
|
|
|
|
return tcc_strdup(buf);
|
|
|
|
}
|
2008-04-28 02:50:35 +08:00
|
|
|
|
2016-10-18 05:24:01 +08:00
|
|
|
static unsigned getclock_ms(void)
|
2013-02-13 02:13:28 +08:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2016-10-18 05:24:01 +08:00
|
|
|
return GetTickCount();
|
2013-02-13 02:13:28 +08:00
|
|
|
#else
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
2016-10-18 05:24:01 +08:00
|
|
|
return tv.tv_sec*1000 + (tv.tv_usec+500)/1000;
|
2013-02-13 02:13:28 +08:00
|
|
|
#endif
|
2003-10-05 05:23:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
TCCState *s;
|
2015-05-13 03:02:51 +08:00
|
|
|
int ret, optind, i;
|
2016-10-18 05:24:01 +08:00
|
|
|
unsigned start_time = 0;
|
2016-10-02 02:04:33 +08:00
|
|
|
const char *first_file = NULL;
|
2003-10-05 05:23:51 +08:00
|
|
|
|
2009-04-18 19:17:27 +08:00
|
|
|
s = tcc_new();
|
2009-07-19 04:07:33 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
optind = tcc_parse_args(s, argc - 1, argv + 1);
|
2015-05-13 03:02:51 +08:00
|
|
|
|
2013-02-19 19:47:36 +08:00
|
|
|
tcc_set_environment(s);
|
2011-08-06 22:08:33 +08:00
|
|
|
|
2013-02-13 02:13:28 +08:00
|
|
|
if (optind == 0) {
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 20:29:39 +08:00
|
|
|
help();
|
2013-02-13 02:13:28 +08:00
|
|
|
return 1;
|
2003-01-07 04:21:08 +08:00
|
|
|
}
|
2011-08-06 22:08:33 +08:00
|
|
|
|
2016-12-19 05:57:03 +08:00
|
|
|
if (s->cross_target)
|
|
|
|
exec_other_tcc(s, argv, s->cross_target);
|
2013-02-13 02:13:28 +08:00
|
|
|
|
2011-08-06 22:08:33 +08:00
|
|
|
if (s->verbose)
|
2013-02-13 02:13:28 +08:00
|
|
|
display_info(s, 0);
|
2011-08-06 22:08:33 +08:00
|
|
|
|
2016-10-02 02:19:37 +08:00
|
|
|
if (s->nb_files == 0) {
|
|
|
|
if (optind == 1) {
|
|
|
|
if (s->print_search_dirs || s->verbose == 2) {
|
|
|
|
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
|
|
|
display_info(s, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (s->verbose)
|
|
|
|
return 1;
|
|
|
|
}
|
2013-02-13 02:13:28 +08:00
|
|
|
tcc_error("no input files\n");
|
2016-10-02 02:19:37 +08:00
|
|
|
}
|
2002-07-18 08:51:11 +08:00
|
|
|
|
2002-08-31 06:46:35 +08:00
|
|
|
/* check -c consistency : only single file handled. XXX: checks file type */
|
2013-02-13 02:13:28 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
|
|
|
|
if (s->nb_libraries != 0)
|
|
|
|
tcc_error("cannot specify libraries with -c");
|
2002-08-31 06:46:35 +08:00
|
|
|
/* accepts only a single input file */
|
2016-10-02 02:04:33 +08:00
|
|
|
if (s->nb_files != 1)
|
|
|
|
tcc_error("cannot specify multiple files with -c");
|
2002-08-31 06:46:35 +08:00
|
|
|
}
|
2015-05-13 02:32:32 +08:00
|
|
|
|
2016-10-02 02:19:37 +08:00
|
|
|
if (s->output_type == 0)
|
|
|
|
s->output_type = TCC_OUTPUT_EXE;
|
2013-02-13 02:13:28 +08:00
|
|
|
tcc_set_output_type(s, s->output_type);
|
2002-08-31 06:46:35 +08:00
|
|
|
|
2016-10-02 02:04:33 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
|
|
|
if (!s->outfile) {
|
|
|
|
s->ppfp = stdout;
|
|
|
|
} else {
|
|
|
|
s->ppfp = fopen(s->outfile, "w");
|
|
|
|
if (!s->ppfp)
|
|
|
|
tcc_error("could not write '%s'", s->outfile);
|
|
|
|
}
|
2016-10-02 02:49:38 +08:00
|
|
|
} else if (s->output_type != TCC_OUTPUT_OBJ) {
|
|
|
|
if (s->option_pthread)
|
|
|
|
tcc_set_options(s, "-lpthread");
|
2016-10-02 02:04:33 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 02:19:37 +08:00
|
|
|
if (s->do_bench)
|
2016-10-18 05:24:01 +08:00
|
|
|
start_time = getclock_ms();
|
2016-10-02 02:19:37 +08:00
|
|
|
|
2002-08-31 06:46:35 +08:00
|
|
|
/* compile or add each files or library */
|
2013-02-13 02:13:28 +08:00
|
|
|
for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
|
2016-10-02 02:04:58 +08:00
|
|
|
struct filespec *f = s->files[i];
|
2016-10-02 02:54:45 +08:00
|
|
|
if (f->type >= AFF_TYPE_LIB) {
|
|
|
|
s->alacarte_link = f->type == AFF_TYPE_LIB;
|
2016-10-02 02:04:58 +08:00
|
|
|
if (tcc_add_library_err(s, f->name) < 0)
|
|
|
|
ret = 1;
|
2002-08-31 06:46:35 +08:00
|
|
|
} else {
|
2016-10-02 01:56:25 +08:00
|
|
|
if (1 == s->verbose)
|
2016-10-02 02:04:58 +08:00
|
|
|
printf("-> %s\n", f->name);
|
2016-10-02 02:46:16 +08:00
|
|
|
s->filetype = f->type;
|
|
|
|
if (tcc_add_file(s, f->name) < 0)
|
2007-12-20 01:36:42 +08:00
|
|
|
ret = 1;
|
2016-10-02 02:04:33 +08:00
|
|
|
if (!first_file)
|
2016-10-02 02:04:58 +08:00
|
|
|
first_file = f->name;
|
2002-08-31 06:46:35 +08:00
|
|
|
}
|
2016-10-02 02:54:45 +08:00
|
|
|
s->filetype = AFF_TYPE_NONE;
|
|
|
|
s->alacarte_link = 1;
|
2002-07-18 08:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-10-02 03:52:11 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
|
|
|
if (s->outfile)
|
|
|
|
fclose(s->ppfp);
|
|
|
|
|
|
|
|
} else if (0 == ret) {
|
2011-08-06 22:08:46 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_MEMORY) {
|
2012-03-06 03:15:56 +08:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2012-05-13 16:21:39 +08:00
|
|
|
ret = tcc_run(s, argc - 1 - optind, argv + 1 + optind);
|
2012-03-06 03:15:56 +08:00
|
|
|
#endif
|
2016-10-02 02:04:33 +08:00
|
|
|
} else {
|
|
|
|
if (!s->outfile)
|
|
|
|
s->outfile = default_outputfile(s, first_file);
|
2013-02-13 02:13:28 +08:00
|
|
|
ret = !!tcc_output_file(s, s->outfile);
|
|
|
|
if (s->gen_deps && !ret)
|
|
|
|
gen_makedeps(s, s->outfile, s->deps_outfile);
|
2010-06-16 20:54:24 +08:00
|
|
|
}
|
2009-07-07 03:10:14 +08:00
|
|
|
}
|
2002-01-27 02:05:29 +08:00
|
|
|
|
2016-10-18 05:24:01 +08:00
|
|
|
if (s->do_bench)
|
|
|
|
tcc_print_stats(s, getclock_ms() - start_time);
|
2009-07-07 03:10:14 +08:00
|
|
|
tcc_delete(s);
|
2002-11-02 22:12:32 +08:00
|
|
|
return ret;
|
2001-10-28 07:48:39 +08:00
|
|
|
}
|