2001-11-01 17:48:10 +03:00
|
|
|
/*
|
|
|
|
* TCC - Tiny C Compiler
|
|
|
|
*
|
2004-10-28 01:38:03 +04:00
|
|
|
* Copyright (c) 2001-2004 Fabrice Bellard
|
2001-11-01 17:48:10 +03:00
|
|
|
*
|
2003-05-24 18:11:17 +04: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 17:48:10 +03:00
|
|
|
*
|
2003-05-24 18:11:17 +04: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 17:48:10 +03:00
|
|
|
*
|
2003-05-24 18:11:17 +04: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 17:48:10 +03:00
|
|
|
*/
|
2003-04-13 23:49:30 +04:00
|
|
|
|
2011-07-14 20:45:37 +04:00
|
|
|
#ifdef ONE_SOURCE
|
2009-05-05 22:18:53 +04:00
|
|
|
#include "libtcc.c"
|
2011-07-14 20:45:37 +04:00
|
|
|
#else
|
|
|
|
#include "tcc.h"
|
2009-07-19 00:08:01 +04:00
|
|
|
#endif
|
2009-04-18 15:17:27 +04:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
static char **files;
|
|
|
|
static int nb_files, nb_libraries;
|
|
|
|
static int multiple_files;
|
|
|
|
static int print_search_dirs;
|
|
|
|
static int output_type;
|
|
|
|
static int reloc_output;
|
2011-08-06 18:08:46 +04:00
|
|
|
static char *outfile;
|
2009-12-20 03:53:49 +03:00
|
|
|
static int do_bench = 0;
|
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-20 20:08:12 +04:00
|
|
|
static int gen_deps;
|
|
|
|
static const char *deps_outfile;
|
2011-08-06 18:08:33 +04:00
|
|
|
static const char *m_option;
|
2012-04-10 18:33:39 +04:00
|
|
|
static char *linker_arg;
|
2009-12-20 03:53:49 +03:00
|
|
|
|
|
|
|
#define TCC_OPTION_HAS_ARG 0x0001
|
|
|
|
#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
|
|
|
|
|
|
|
|
static void help(void)
|
2002-05-14 03:00:17 +04:00
|
|
|
{
|
2006-10-16 23:44:00 +04:00
|
|
|
printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard\n"
|
2010-09-08 21:13:36 +04:00
|
|
|
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
|
|
|
|
" tcc [options...] -run infile [arguments...]\n"
|
2002-07-16 02:17:02 +04:00
|
|
|
"General options:\n"
|
2008-03-31 23:49:14 +04:00
|
|
|
" -v display current version, increase verbosity\n"
|
2002-07-16 02:17:02 +04:00
|
|
|
" -c compile only - generate an object file\n"
|
2002-07-25 02:10:59 +04:00
|
|
|
" -o outfile set output filename\n"
|
2011-02-02 11:00:12 +03:00
|
|
|
" -Bdir set tcc internal library and include path\n"
|
2002-07-25 02:10:59 +04:00
|
|
|
" -bench output compilation statistics\n"
|
2007-11-14 20:34:30 +03:00
|
|
|
" -run run compiled source\n"
|
2003-10-18 00:43:47 +04: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 00:35:50 +04:00
|
|
|
" -w disable all warnings\n"
|
2002-07-16 02:17:02 +04:00
|
|
|
"Preprocessor options:\n"
|
2006-10-16 23:44:00 +04:00
|
|
|
" -E preprocess only\n"
|
2002-07-16 02:17:02 +04:00
|
|
|
" -Idir add include path 'dir'\n"
|
|
|
|
" -Dsym[=val] define 'sym' with value 'val'\n"
|
|
|
|
" -Usym undefine 'sym'\n"
|
|
|
|
"Linker options:\n"
|
2002-07-22 04:20:38 +04:00
|
|
|
" -Ldir add library path 'dir'\n"
|
2002-08-18 17:22:55 +04:00
|
|
|
" -llib link with dynamic or static library 'lib'\n"
|
2010-11-25 03:42:08 +03:00
|
|
|
" -pthread link with -lpthread and -D_REENTRANT (POSIX Linux)\n"
|
2002-07-28 03:08:04 +04:00
|
|
|
" -shared generate a shared library\n"
|
2008-03-26 00:04:47 +03:00
|
|
|
" -soname set name for shared library to be used at runtime\n"
|
2002-07-25 02:10:59 +04:00
|
|
|
" -static static linking\n"
|
2003-05-24 20:21:09 +04:00
|
|
|
" -rdynamic export all global symbols to dynamic linker\n"
|
2007-12-19 20:36:42 +03:00
|
|
|
" -r generate (relocatable) object file\n"
|
2002-11-03 03:43:55 +03: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-18 20:21:38 +04:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2002-11-03 03:43:55 +03:00
|
|
|
" -bt N show N callers in stack traces\n"
|
2009-04-18 20:21:38 +04: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-20 20:08:12 +04:00
|
|
|
"Misc options:\n"
|
|
|
|
" -MD generate target dependencies for make\n"
|
|
|
|
" -MF depfile put generated dependencies here\n"
|
2002-05-14 03:00:17 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2003-01-06 23:21:08 +03:00
|
|
|
typedef struct TCCOption {
|
|
|
|
const char *name;
|
|
|
|
uint16_t index;
|
|
|
|
uint16_t flags;
|
|
|
|
} TCCOption;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TCC_OPTION_HELP,
|
|
|
|
TCC_OPTION_I,
|
|
|
|
TCC_OPTION_D,
|
|
|
|
TCC_OPTION_U,
|
|
|
|
TCC_OPTION_L,
|
|
|
|
TCC_OPTION_B,
|
|
|
|
TCC_OPTION_l,
|
|
|
|
TCC_OPTION_bench,
|
|
|
|
TCC_OPTION_bt,
|
|
|
|
TCC_OPTION_b,
|
|
|
|
TCC_OPTION_g,
|
|
|
|
TCC_OPTION_c,
|
|
|
|
TCC_OPTION_static,
|
|
|
|
TCC_OPTION_shared,
|
2008-03-26 00:04:47 +03:00
|
|
|
TCC_OPTION_soname,
|
2003-01-06 23:21:08 +03:00
|
|
|
TCC_OPTION_o,
|
|
|
|
TCC_OPTION_r,
|
2010-12-05 03:04:33 +03:00
|
|
|
TCC_OPTION_s,
|
2004-10-18 04:18:20 +04:00
|
|
|
TCC_OPTION_Wl,
|
2003-01-06 23:21:08 +03:00
|
|
|
TCC_OPTION_W,
|
|
|
|
TCC_OPTION_O,
|
|
|
|
TCC_OPTION_m,
|
|
|
|
TCC_OPTION_f,
|
2011-02-02 10:32:53 +03:00
|
|
|
TCC_OPTION_isystem,
|
2003-01-06 23:21:08 +03:00
|
|
|
TCC_OPTION_nostdinc,
|
2003-04-27 15:45:01 +04:00
|
|
|
TCC_OPTION_nostdlib,
|
2003-01-06 23:21:08 +03:00
|
|
|
TCC_OPTION_print_search_dirs,
|
|
|
|
TCC_OPTION_rdynamic,
|
2010-12-20 15:23:30 +03:00
|
|
|
TCC_OPTION_pedantic,
|
2010-11-25 03:42:08 +03:00
|
|
|
TCC_OPTION_pthread,
|
2003-04-14 01:54:03 +04:00
|
|
|
TCC_OPTION_run,
|
|
|
|
TCC_OPTION_v,
|
2003-09-20 00:35:50 +04:00
|
|
|
TCC_OPTION_w,
|
2004-12-17 01:19:28 +03:00
|
|
|
TCC_OPTION_pipe,
|
2006-10-16 23:44:00 +04:00
|
|
|
TCC_OPTION_E,
|
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-20 20:08:12 +04:00
|
|
|
TCC_OPTION_MD,
|
|
|
|
TCC_OPTION_MF,
|
2009-06-17 04:11:27 +04:00
|
|
|
TCC_OPTION_x,
|
2003-01-06 23:21:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const TCCOption tcc_options[] = {
|
|
|
|
{ "h", TCC_OPTION_HELP, 0 },
|
2010-01-27 00:58:48 +03:00
|
|
|
{ "-help", TCC_OPTION_HELP, 0 },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "?", TCC_OPTION_HELP, 0 },
|
|
|
|
{ "I", TCC_OPTION_I, TCC_OPTION_HAS_ARG },
|
|
|
|
{ "D", TCC_OPTION_D, TCC_OPTION_HAS_ARG },
|
|
|
|
{ "U", TCC_OPTION_U, TCC_OPTION_HAS_ARG },
|
|
|
|
{ "L", TCC_OPTION_L, TCC_OPTION_HAS_ARG },
|
|
|
|
{ "B", TCC_OPTION_B, TCC_OPTION_HAS_ARG },
|
|
|
|
{ "l", TCC_OPTION_l, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
{ "bench", TCC_OPTION_bench, 0 },
|
2010-09-08 21:13:36 +04:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "bt", TCC_OPTION_bt, TCC_OPTION_HAS_ARG },
|
2010-09-08 21:13:36 +04:00
|
|
|
#endif
|
2003-01-06 23:21:08 +03:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
{ "b", TCC_OPTION_b, 0 },
|
|
|
|
#endif
|
2004-12-17 01:19:28 +03:00
|
|
|
{ "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "c", TCC_OPTION_c, 0 },
|
|
|
|
{ "static", TCC_OPTION_static, 0 },
|
|
|
|
{ "shared", TCC_OPTION_shared, 0 },
|
2008-03-26 00:04:47 +03:00
|
|
|
{ "soname", TCC_OPTION_soname, TCC_OPTION_HAS_ARG },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
|
2010-12-20 15:23:30 +03:00
|
|
|
{ "pedantic", TCC_OPTION_pedantic, 0},
|
2010-11-25 03:42:08 +03:00
|
|
|
{ "pthread", TCC_OPTION_pthread, 0},
|
2003-10-05 01:23:51 +04:00
|
|
|
{ "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2003-05-24 19:46:29 +04:00
|
|
|
{ "rdynamic", TCC_OPTION_rdynamic, 0 },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "r", TCC_OPTION_r, 0 },
|
2010-12-05 03:04:33 +03:00
|
|
|
{ "s", TCC_OPTION_s, 0 },
|
2004-10-18 04:18:20 +04:00
|
|
|
{ "Wl,", TCC_OPTION_Wl, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
{ "O", TCC_OPTION_O, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
|
|
|
{ "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG },
|
|
|
|
{ "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2011-02-02 10:32:53 +03:00
|
|
|
{ "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "nostdinc", TCC_OPTION_nostdinc, 0 },
|
2003-04-27 15:45:01 +04:00
|
|
|
{ "nostdlib", TCC_OPTION_nostdlib, 0 },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
|
2008-03-31 23:49:14 +04:00
|
|
|
{ "v", TCC_OPTION_v, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
|
2003-09-20 00:35:50 +04:00
|
|
|
{ "w", TCC_OPTION_w, 0 },
|
2004-12-17 01:19:28 +03:00
|
|
|
{ "pipe", TCC_OPTION_pipe, 0},
|
2006-10-16 23:44:00 +04:00
|
|
|
{ "E", TCC_OPTION_E, 0},
|
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-20 20:08:12 +04:00
|
|
|
{ "MD", TCC_OPTION_MD, 0},
|
|
|
|
{ "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG },
|
2009-06-17 04:11:27 +04:00
|
|
|
{ "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG },
|
2003-01-06 23:21:08 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
static int64_t getclock_us(void)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
struct _timeb tb;
|
|
|
|
_ftime(&tb);
|
|
|
|
return (tb.time * 1000LL + tb.millitm) * 1000LL;
|
|
|
|
#else
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_sec * 1000000LL + tv.tv_usec;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-10-05 01:23:51 +04:00
|
|
|
/* convert 'str' into an array of space separated strings */
|
|
|
|
static int expand_args(char ***pargv, const char *str)
|
2002-05-14 03:00:17 +04:00
|
|
|
{
|
2003-10-05 01:23:51 +04:00
|
|
|
const char *s1;
|
|
|
|
char **argv, *arg;
|
|
|
|
int argc, len;
|
2003-01-06 23:21:08 +03:00
|
|
|
|
2003-10-05 01:23:51 +04:00
|
|
|
argc = 0;
|
|
|
|
argv = NULL;
|
|
|
|
for(;;) {
|
|
|
|
while (is_space(*str))
|
|
|
|
str++;
|
|
|
|
if (*str == '\0')
|
|
|
|
break;
|
|
|
|
s1 = str;
|
|
|
|
while (*str != '\0' && !is_space(*str))
|
|
|
|
str++;
|
|
|
|
len = str - s1;
|
|
|
|
arg = tcc_malloc(len + 1);
|
|
|
|
memcpy(arg, s1, len);
|
|
|
|
arg[len] = '\0';
|
|
|
|
dynarray_add((void ***)&argv, &argc, arg);
|
|
|
|
}
|
|
|
|
*pargv = argv;
|
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
2011-08-06 18:08:33 +04: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 03:17:20 +03:00
|
|
|
#ifdef _WIN32
|
2011-08-06 18:08:33 +04:00
|
|
|
#include <process.h>
|
|
|
|
static int execvp_win32(const char *prog, char **argv)
|
2010-12-08 11:27:06 +03:00
|
|
|
{
|
2011-08-06 18:08:33 +04:00
|
|
|
int ret = spawnvp(P_NOWAIT, prog, (char const*const*)argv);
|
|
|
|
if (-1 == ret)
|
|
|
|
return ret;
|
|
|
|
cwait(&ret, ret, WAIT_CHILD);
|
|
|
|
exit(ret);
|
2010-12-07 03:17:20 +03:00
|
|
|
}
|
2011-08-06 18:08:33 +04:00
|
|
|
#define execvp execvp_win32
|
|
|
|
#endif
|
|
|
|
static void exec_other_tcc(TCCState *s, char **argv, const char *optarg)
|
2010-12-08 11:27:06 +03:00
|
|
|
{
|
2011-08-06 18:08:33 +04:00
|
|
|
char child_path[4096], *child_name; const char *target;
|
|
|
|
switch (atoi(optarg)) {
|
|
|
|
#ifdef TCC_TARGET_I386
|
|
|
|
case 32: break;
|
|
|
|
case 64: target = "x86_64";
|
|
|
|
#else
|
|
|
|
case 64: break;
|
|
|
|
case 32: target = "i386";
|
|
|
|
#endif
|
|
|
|
pstrcpy(child_path, sizeof child_path - 40, argv[0]);
|
|
|
|
child_name = tcc_basename(child_path);
|
|
|
|
strcpy(child_name, target);
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
strcat(child_name, "-win32");
|
|
|
|
#endif
|
|
|
|
strcat(child_name, "-tcc");
|
|
|
|
if (strcmp(argv[0], child_path)) {
|
|
|
|
if (s->verbose > 0)
|
|
|
|
printf("tcc: using '%s'\n", child_name), fflush(stdout);
|
|
|
|
execvp(argv[0] = child_path, argv);
|
|
|
|
}
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("'%s' not found", child_name);
|
2011-08-06 18:08:33 +04:00
|
|
|
case 0: /* ignore -march etc. */
|
2010-12-08 11:27:06 +03:00
|
|
|
break;
|
|
|
|
default:
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_warning("unsupported option \"-m%s\"", optarg);
|
2010-12-08 11:27:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-11 18:55:30 +04:00
|
|
|
static void parse_option_D(TCCState *s1, const char *optarg)
|
|
|
|
{
|
|
|
|
char *sym = tcc_strdup(optarg);
|
|
|
|
char *value = strchr(sym, '=');
|
|
|
|
if (value)
|
|
|
|
*value++ = '\0';
|
|
|
|
tcc_define_symbol(s1, sym, value);
|
|
|
|
tcc_free(sym);
|
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
static int parse_args(TCCState *s, int argc, char **argv)
|
2003-10-05 01:23:51 +04:00
|
|
|
{
|
|
|
|
int optind;
|
|
|
|
const TCCOption *popt;
|
|
|
|
const char *optarg, *p1, *r1;
|
|
|
|
char *r;
|
2011-01-04 12:17:52 +03:00
|
|
|
int was_pthread;
|
2012-04-10 18:33:39 +04:00
|
|
|
unsigned long linker_argsize = 0;
|
2011-01-04 12:17:52 +03:00
|
|
|
|
|
|
|
was_pthread = 0; /* is set if commandline contains -pthread key */
|
2002-05-14 03:00:17 +04:00
|
|
|
|
2011-08-06 18:08:33 +04:00
|
|
|
optind = 1;
|
2008-04-27 22:50:35 +04:00
|
|
|
while (optind < argc) {
|
|
|
|
|
2002-08-31 02:46:35 +04:00
|
|
|
r = argv[optind++];
|
2008-03-31 22:42:56 +04:00
|
|
|
if (r[0] != '-' || r[1] == '\0') {
|
2002-08-31 02:46:35 +04:00
|
|
|
/* add a new file */
|
|
|
|
dynarray_add((void ***)&files, &nb_files, r);
|
|
|
|
if (!multiple_files) {
|
|
|
|
optind--;
|
|
|
|
/* argv[0] will be this file */
|
|
|
|
break;
|
|
|
|
}
|
2003-01-06 23:21:08 +03:00
|
|
|
} else {
|
|
|
|
/* find option in table (match only the first chars */
|
|
|
|
popt = tcc_options;
|
|
|
|
for(;;) {
|
|
|
|
p1 = popt->name;
|
|
|
|
if (p1 == NULL)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("invalid option -- '%s'", r);
|
2003-01-06 23:21:08 +03:00
|
|
|
r1 = r + 1;
|
|
|
|
for(;;) {
|
|
|
|
if (*p1 == '\0')
|
|
|
|
goto option_found;
|
|
|
|
if (*r1 != *p1)
|
|
|
|
break;
|
|
|
|
p1++;
|
|
|
|
r1++;
|
|
|
|
}
|
|
|
|
popt++;
|
2002-08-31 02:46:35 +04:00
|
|
|
}
|
2003-01-06 23:21:08 +03:00
|
|
|
option_found:
|
|
|
|
if (popt->flags & TCC_OPTION_HAS_ARG) {
|
|
|
|
if (*r1 != '\0' || (popt->flags & TCC_OPTION_NOSEP)) {
|
|
|
|
optarg = r1;
|
|
|
|
} else {
|
|
|
|
if (optind >= argc)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("argument to '%s' is missing", r);
|
2003-01-06 23:21:08 +03:00
|
|
|
optarg = argv[optind++];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (*r1 != '\0')
|
2008-04-27 22:50:35 +04:00
|
|
|
return 0;
|
2003-01-06 23:21:08 +03:00
|
|
|
optarg = NULL;
|
2002-05-14 03:00:17 +04:00
|
|
|
}
|
2003-01-06 23:21:08 +03:00
|
|
|
|
|
|
|
switch(popt->index) {
|
|
|
|
case TCC_OPTION_HELP:
|
2008-04-27 22:50:35 +04:00
|
|
|
return 0;
|
|
|
|
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_I:
|
|
|
|
if (tcc_add_include_path(s, optarg) < 0)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("too many include paths");
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
|
|
|
case TCC_OPTION_D:
|
2011-08-11 18:55:30 +04:00
|
|
|
parse_option_D(s, optarg);
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
|
|
|
case TCC_OPTION_U:
|
|
|
|
tcc_undefine_symbol(s, optarg);
|
|
|
|
break;
|
|
|
|
case TCC_OPTION_L:
|
|
|
|
tcc_add_library_path(s, optarg);
|
|
|
|
break;
|
|
|
|
case TCC_OPTION_B:
|
|
|
|
/* set tcc utilities path (mainly for tcc development) */
|
2009-04-18 15:17:27 +04:00
|
|
|
tcc_set_lib_path(s, optarg);
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
|
|
|
case TCC_OPTION_l:
|
|
|
|
dynarray_add((void ***)&files, &nb_files, r);
|
|
|
|
nb_libraries++;
|
|
|
|
break;
|
2010-11-25 03:42:08 +03:00
|
|
|
case TCC_OPTION_pthread:
|
2011-01-04 12:17:52 +03:00
|
|
|
was_pthread = 1;
|
2011-08-11 18:55:30 +04:00
|
|
|
parse_option_D(s, "_REENTRANT");
|
2010-11-25 03:42:08 +03:00
|
|
|
break;
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_bench:
|
|
|
|
do_bench = 1;
|
|
|
|
break;
|
2009-04-18 20:21:38 +04:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_bt:
|
2011-08-11 18:55:30 +04:00
|
|
|
tcc_set_num_callers(atoi(optarg));
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
2009-04-18 20:21:38 +04:00
|
|
|
#endif
|
2002-03-04 01:45:55 +03:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_b:
|
2009-05-11 20:45:44 +04:00
|
|
|
s->do_bounds_check = 1;
|
|
|
|
s->do_debug = 1;
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
2002-07-27 19:38:21 +04:00
|
|
|
#endif
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_g:
|
2009-05-11 20:45:44 +04:00
|
|
|
s->do_debug = 1;
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
|
|
|
case TCC_OPTION_c:
|
|
|
|
multiple_files = 1;
|
|
|
|
output_type = TCC_OUTPUT_OBJ;
|
|
|
|
break;
|
|
|
|
case TCC_OPTION_static:
|
|
|
|
s->static_link = 1;
|
|
|
|
break;
|
|
|
|
case TCC_OPTION_shared:
|
|
|
|
output_type = TCC_OUTPUT_DLL;
|
|
|
|
break;
|
2008-03-26 00:04:47 +03:00
|
|
|
case TCC_OPTION_soname:
|
2010-12-07 03:17:20 +03:00
|
|
|
s->soname = optarg;
|
|
|
|
break;
|
|
|
|
case TCC_OPTION_m:
|
2011-08-06 18:08:33 +04:00
|
|
|
m_option = optarg;
|
2008-03-26 00:04:47 +03:00
|
|
|
break;
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_o:
|
|
|
|
multiple_files = 1;
|
2011-08-06 18:08:46 +04:00
|
|
|
outfile = tcc_strdup(optarg);
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
|
|
|
case TCC_OPTION_r:
|
|
|
|
/* generate a .o merging several output files */
|
|
|
|
reloc_output = 1;
|
|
|
|
output_type = TCC_OUTPUT_OBJ;
|
|
|
|
break;
|
2011-02-02 10:32:53 +03:00
|
|
|
case TCC_OPTION_isystem:
|
|
|
|
tcc_add_sysinclude_path(s, optarg);
|
|
|
|
break;
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_nostdinc:
|
|
|
|
s->nostdinc = 1;
|
|
|
|
break;
|
2003-04-27 15:45:01 +04:00
|
|
|
case TCC_OPTION_nostdlib:
|
|
|
|
s->nostdlib = 1;
|
|
|
|
break;
|
2003-01-06 23:21:08 +03:00
|
|
|
case TCC_OPTION_print_search_dirs:
|
|
|
|
print_search_dirs = 1;
|
|
|
|
break;
|
2003-04-14 01:54:03 +04:00
|
|
|
case TCC_OPTION_run:
|
2011-08-11 18:55:30 +04:00
|
|
|
{
|
|
|
|
int argc1;
|
|
|
|
char **argv1;
|
|
|
|
argc1 = expand_args(&argv1, optarg);
|
|
|
|
if (argc1 > 0) {
|
|
|
|
parse_args(s, argc1, argv1);
|
2003-10-05 01:23:51 +04:00
|
|
|
}
|
2011-08-11 18:55:30 +04:00
|
|
|
multiple_files = 0;
|
|
|
|
output_type = TCC_OUTPUT_MEMORY;
|
2003-04-14 01:54:03 +04:00
|
|
|
break;
|
2011-08-11 18:55:30 +04:00
|
|
|
}
|
2003-04-14 01:54:03 +04:00
|
|
|
case TCC_OPTION_v:
|
2011-08-06 18:08:33 +04:00
|
|
|
do ++s->verbose; while (*optarg++ == 'v');
|
2008-03-31 23:49:14 +04:00
|
|
|
break;
|
2003-10-18 00:43:47 +04:00
|
|
|
case TCC_OPTION_f:
|
|
|
|
if (tcc_set_flag(s, optarg, 1) < 0 && s->warn_unsupported)
|
|
|
|
goto unsupported_option;
|
|
|
|
break;
|
2003-04-27 00:49:46 +04:00
|
|
|
case TCC_OPTION_W:
|
2003-10-18 00:43:47 +04:00
|
|
|
if (tcc_set_warning(s, optarg, 1) < 0 &&
|
|
|
|
s->warn_unsupported)
|
|
|
|
goto unsupported_option;
|
2003-04-27 00:49:46 +04:00
|
|
|
break;
|
2003-09-20 00:35:50 +04:00
|
|
|
case TCC_OPTION_w:
|
2003-10-04 17:04:47 +04:00
|
|
|
s->warn_none = 1;
|
2003-09-20 00:35:50 +04:00
|
|
|
break;
|
2003-05-24 19:46:29 +04:00
|
|
|
case TCC_OPTION_rdynamic:
|
|
|
|
s->rdynamic = 1;
|
|
|
|
break;
|
2004-10-18 04:18:20 +04:00
|
|
|
case TCC_OPTION_Wl:
|
2012-04-10 18:33:39 +04:00
|
|
|
if (!linker_arg) {
|
|
|
|
linker_argsize = strlen(optarg) + 1;
|
|
|
|
linker_arg = tcc_malloc(linker_argsize);
|
|
|
|
pstrcpy(linker_arg, linker_argsize, optarg);
|
|
|
|
}
|
2012-03-15 03:22:00 +04:00
|
|
|
else {
|
2012-04-10 18:33:39 +04:00
|
|
|
linker_argsize += strlen(optarg) + 1;
|
|
|
|
linker_arg = tcc_realloc(linker_arg, linker_argsize);
|
|
|
|
pstrcat(linker_arg, linker_argsize, ",");
|
|
|
|
pstrcat(linker_arg, linker_argsize, optarg);
|
2012-03-15 03:22:00 +04:00
|
|
|
}
|
2004-10-18 04:18:20 +04:00
|
|
|
break;
|
2006-10-16 23:44:00 +04:00
|
|
|
case TCC_OPTION_E:
|
|
|
|
output_type = TCC_OUTPUT_PREPROCESS;
|
|
|
|
break;
|
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-20 20:08:12 +04:00
|
|
|
case TCC_OPTION_MD:
|
|
|
|
gen_deps = 1;
|
|
|
|
break;
|
|
|
|
case TCC_OPTION_MF:
|
|
|
|
deps_outfile = optarg;
|
|
|
|
break;
|
2009-06-17 04:11:27 +04:00
|
|
|
case TCC_OPTION_x:
|
|
|
|
break;
|
2003-01-06 23:21:08 +03:00
|
|
|
default:
|
2003-04-27 00:49:46 +04:00
|
|
|
if (s->warn_unsupported) {
|
|
|
|
unsupported_option:
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_warning("unsupported option '%s'", r);
|
2003-04-27 00:49:46 +04:00
|
|
|
}
|
2003-01-06 23:21:08 +03:00
|
|
|
break;
|
|
|
|
}
|
2001-11-11 05:53:01 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 18:33:39 +04:00
|
|
|
if ((r = (char *) tcc_set_linker(s, (char *)linker_arg, TRUE)))
|
2012-03-15 03:22:00 +04:00
|
|
|
tcc_error("unsupported linker option '%s'", r);
|
2011-01-04 12:17:52 +03:00
|
|
|
/* fixme: these options could be different on your platform */
|
2011-08-11 18:55:30 +04:00
|
|
|
if (was_pthread && output_type != TCC_OUTPUT_OBJ) {
|
2011-01-04 12:17:52 +03:00
|
|
|
dynarray_add((void ***)&files, &nb_files, "-lpthread");
|
|
|
|
nb_libraries++;
|
|
|
|
}
|
2011-08-06 18:08:33 +04:00
|
|
|
return optind;
|
2003-10-05 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
TCCState *s;
|
|
|
|
int nb_objfiles, ret, optind;
|
|
|
|
int64_t start_time = 0;
|
2011-08-06 18:08:46 +04:00
|
|
|
const char *default_file = NULL;
|
2003-10-05 01:23:51 +04:00
|
|
|
|
2009-04-18 15:17:27 +04:00
|
|
|
s = tcc_new();
|
2009-07-19 00:07:33 +04:00
|
|
|
|
2003-10-05 01:23:51 +04:00
|
|
|
output_type = TCC_OUTPUT_EXE;
|
|
|
|
outfile = NULL;
|
|
|
|
multiple_files = 1;
|
|
|
|
files = NULL;
|
|
|
|
nb_files = 0;
|
|
|
|
nb_libraries = 0;
|
|
|
|
reloc_output = 0;
|
|
|
|
print_search_dirs = 0;
|
2011-08-06 18:08:33 +04:00
|
|
|
m_option = NULL;
|
2007-12-19 20:36:42 +03:00
|
|
|
ret = 0;
|
2003-10-05 01:23:51 +04:00
|
|
|
|
2011-08-06 18:08:33 +04:00
|
|
|
optind = parse_args(s, argc, argv);
|
|
|
|
|
|
|
|
#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_I386
|
|
|
|
if (m_option)
|
|
|
|
exec_other_tcc(s, argv, m_option);
|
|
|
|
#endif
|
|
|
|
|
2003-01-06 23:21:08 +03:00
|
|
|
if (print_search_dirs) {
|
|
|
|
/* enough for Linux kernel */
|
2009-05-11 20:45:44 +04:00
|
|
|
printf("install: %s/\n", s->tcc_lib_path);
|
2003-01-06 23:21:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2011-08-06 18:08:33 +04:00
|
|
|
|
|
|
|
if (s->verbose)
|
|
|
|
printf("tcc version %s\n", TCC_VERSION);
|
|
|
|
|
2008-04-27 22:50:35 +04:00
|
|
|
if (optind == 0 || nb_files == 0) {
|
2009-05-11 20:45:44 +04:00
|
|
|
if (optind && s->verbose)
|
2008-04-27 22:50:35 +04:00
|
|
|
return 0;
|
|
|
|
help();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-31 02:46:35 +04:00
|
|
|
nb_objfiles = nb_files - nb_libraries;
|
|
|
|
|
2002-07-22 04:20:38 +04:00
|
|
|
/* if outfile provided without other options, we output an
|
|
|
|
executable */
|
|
|
|
if (outfile && output_type == TCC_OUTPUT_MEMORY)
|
|
|
|
output_type = TCC_OUTPUT_EXE;
|
2002-07-18 04:51:11 +04:00
|
|
|
|
2002-08-31 02:46:35 +04:00
|
|
|
/* check -c consistency : only single file handled. XXX: checks file type */
|
|
|
|
if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
|
|
|
|
/* accepts only a single input file */
|
|
|
|
if (nb_objfiles != 1)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("cannot specify multiple files with -c");
|
2002-08-31 02:46:35 +04:00
|
|
|
if (nb_libraries != 0)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("cannot specify libraries with -c");
|
2002-08-31 02:46:35 +04:00
|
|
|
}
|
|
|
|
|
2006-10-16 23:44:00 +04:00
|
|
|
if (output_type == TCC_OUTPUT_PREPROCESS) {
|
|
|
|
if (!outfile) {
|
|
|
|
s->outfile = stdout;
|
|
|
|
} else {
|
2007-12-19 20:36:42 +03:00
|
|
|
s->outfile = fopen(outfile, "w");
|
2006-10-16 23:44:00 +04:00
|
|
|
if (!s->outfile)
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error("could not open '%s'", outfile);
|
2006-10-16 23:44:00 +04:00
|
|
|
}
|
2002-07-16 02:17:02 +04:00
|
|
|
}
|
2001-12-08 18:04:01 +03:00
|
|
|
|
2002-11-19 00:46:44 +03:00
|
|
|
if (do_bench) {
|
|
|
|
start_time = getclock_us();
|
|
|
|
}
|
|
|
|
|
2002-08-31 02:46:35 +04:00
|
|
|
tcc_set_output_type(s, output_type);
|
2010-06-20 19:49:58 +04:00
|
|
|
s->reloc_output = reloc_output;
|
2002-08-31 02:46:35 +04:00
|
|
|
|
|
|
|
/* compile or add each files or library */
|
2007-12-19 20:36:42 +03:00
|
|
|
for(i = 0; i < nb_files && ret == 0; i++) {
|
2002-08-31 02:46:35 +04:00
|
|
|
const char *filename;
|
|
|
|
|
|
|
|
filename = files[i];
|
2010-06-20 19:18:58 +04:00
|
|
|
if (filename[0] == '-' && filename[1] == 'l') {
|
2009-05-11 20:46:02 +04:00
|
|
|
if (tcc_add_library(s, filename + 2) < 0) {
|
2011-08-11 19:07:56 +04:00
|
|
|
tcc_error_noabort("cannot find %s", filename);
|
2007-12-19 20:36:42 +03:00
|
|
|
ret = 1;
|
2009-05-11 20:46:02 +04:00
|
|
|
}
|
2002-08-31 02:46:35 +04:00
|
|
|
} else {
|
2009-05-11 20:45:44 +04:00
|
|
|
if (1 == s->verbose)
|
2008-03-31 23:49:14 +04:00
|
|
|
printf("-> %s\n", filename);
|
2007-12-19 20:36:42 +03:00
|
|
|
if (tcc_add_file(s, filename) < 0)
|
|
|
|
ret = 1;
|
2011-08-06 18:08:46 +04:00
|
|
|
if (!default_file)
|
|
|
|
default_file = filename;
|
2002-08-31 02:46:35 +04:00
|
|
|
}
|
2002-07-18 04:51:11 +04:00
|
|
|
}
|
|
|
|
|
2002-11-02 17:12:32 +03:00
|
|
|
/* free all files */
|
|
|
|
tcc_free(files);
|
|
|
|
|
2009-07-06 23:10:14 +04:00
|
|
|
if (0 == ret) {
|
|
|
|
if (do_bench)
|
|
|
|
tcc_print_stats(s, getclock_us() - start_time);
|
|
|
|
|
2011-08-06 18:08:46 +04:00
|
|
|
if (s->output_type == TCC_OUTPUT_MEMORY) {
|
2012-03-05 23:15:56 +04:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2009-07-06 23:10:14 +04:00
|
|
|
ret = tcc_run(s, argc - optind, argv + optind);
|
2012-03-05 23:15:56 +04:00
|
|
|
#else
|
|
|
|
tcc_error_noabort("-run is not available in a cross compiler");
|
|
|
|
#endif
|
2011-08-06 18:08:46 +04:00
|
|
|
} else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
|
|
|
if (s->outfile)
|
|
|
|
fclose(s->outfile);
|
|
|
|
} else {
|
|
|
|
if (!outfile)
|
|
|
|
outfile = tcc_default_target(s, default_file);
|
|
|
|
ret = !!tcc_output_file(s, outfile);
|
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-20 20:08:12 +04:00
|
|
|
/* dump collected dependencies */
|
|
|
|
if (gen_deps && !ret)
|
|
|
|
tcc_gen_makedeps(s, outfile, deps_outfile);
|
2010-06-16 16:54:24 +04:00
|
|
|
}
|
2009-07-06 23:10:14 +04:00
|
|
|
}
|
2002-01-26 21:05:29 +03:00
|
|
|
|
2009-07-06 23:10:14 +04:00
|
|
|
tcc_delete(s);
|
2012-04-10 18:33:39 +04:00
|
|
|
tcc_free(linker_arg);
|
2011-08-06 18:08:46 +04:00
|
|
|
tcc_free(outfile);
|
2002-11-02 17:12:32 +03:00
|
|
|
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
if (do_bench) {
|
|
|
|
printf("memory: %d bytes, max = %d bytes\n", mem_cur_size, mem_max_size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return ret;
|
2001-10-28 02:48:39 +03:00
|
|
|
}
|