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
|
|
|
#include "tcc.h"
|
2017-07-24 03:24:11 +08:00
|
|
|
#if ONE_SOURCE
|
|
|
|
# include "libtcc.c"
|
2009-07-19 04:08:01 +08:00
|
|
|
#endif
|
2017-02-18 16:55:34 +08:00
|
|
|
#include "tcctools.c"
|
2015-03-03 21:08:33 +08:00
|
|
|
|
2017-02-18 16:55:46 +08:00
|
|
|
static const char help[] =
|
|
|
|
"Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n"
|
|
|
|
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
|
|
|
|
" tcc [options...] -run infile [arguments...]\n"
|
|
|
|
"General options:\n"
|
2020-05-11 22:23:48 +08:00
|
|
|
" -c compile only - generate an object file\n"
|
|
|
|
" -o outfile set output filename\n"
|
|
|
|
" -run run compiled source\n"
|
|
|
|
" -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n"
|
|
|
|
" -std=c99 Conform to the ISO 1999 C standard (default).\n"
|
|
|
|
" -std=c11 Conform to the ISO 2011 C standard.\n"
|
|
|
|
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n"
|
2021-08-01 02:44:51 +08:00
|
|
|
" -w disable all warnings\n"
|
2021-03-30 17:25:58 +08:00
|
|
|
" -v --version show version\n"
|
2020-05-11 22:23:48 +08:00
|
|
|
" -vv show search paths or loaded files\n"
|
|
|
|
" -h -hh show this, show more help\n"
|
|
|
|
" -bench show compilation statistics\n"
|
|
|
|
" - use stdin pipe as infile\n"
|
|
|
|
" @listfile read arguments from listfile\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
"Preprocessor options:\n"
|
2020-05-11 22:23:48 +08:00
|
|
|
" -Idir add include path 'dir'\n"
|
|
|
|
" -Dsym[=val] define 'sym' with value 'val'\n"
|
|
|
|
" -Usym undefine 'sym'\n"
|
|
|
|
" -E preprocess only\n"
|
2020-07-11 12:41:44 +08:00
|
|
|
" -C keep comments (not yet implemented)\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
"Linker options:\n"
|
2020-05-11 22:23:48 +08:00
|
|
|
" -Ldir add library path 'dir'\n"
|
|
|
|
" -llib link with dynamic or static library 'lib'\n"
|
|
|
|
" -r generate (relocatable) object file\n"
|
|
|
|
" -shared generate a shared library/dll\n"
|
|
|
|
" -rdynamic export all global symbols to dynamic linker\n"
|
|
|
|
" -soname set name for shared library to be used at runtime\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
" -Wl,-opt[=val] set linker option (see tcc -hh)\n"
|
|
|
|
"Debugger options:\n"
|
2022-05-08 05:16:13 +08:00
|
|
|
" -g generate stab runtime debug info\n"
|
Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.
The stabs code still works and is used if configure option --dwarf
is not used.
Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.
arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size
arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U
libtcc.c:
- parse -gdwarf option
tcc.c:
- add dwarf option
tcc.h:
- add dwarf option and sections
tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun
tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
only this section has to be parsed instead of .debug_info and
.debug_abbrev.
- fix init debug_modes
tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function
dwarf.h:
- New file
tcc-doc.texi:
- document dwarf
configure:
- add dwarf option
lib/Makefile
- change -gstabs into -gdwarf
lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 15:10:37 +08:00
|
|
|
" -gdwarf[-x] generate dwarf runtime debug info\n"
|
2002-11-03 08:43:55 +08:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2020-05-11 22:23:48 +08:00
|
|
|
" -b compile with built-in memory and bounds checker (implies -g)\n"
|
2002-11-03 08:43:55 +08:00
|
|
|
#endif
|
2009-04-19 00:21:38 +08:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
2020-05-11 22:23:48 +08:00
|
|
|
" -bt[N] link with backtrace (stack dump) support [show max N callers]\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
#endif
|
|
|
|
"Misc. options:\n"
|
2020-05-11 22:23:48 +08:00
|
|
|
" -x[c|a|b|n] specify type of the next infile (C,ASM,BIN,NONE)\n"
|
|
|
|
" -nostdinc do not use standard system include paths\n"
|
|
|
|
" -nostdlib do not link with standard crt and libraries\n"
|
|
|
|
" -Bdir set tcc's private include/library dir\n"
|
2021-03-30 17:25:58 +08:00
|
|
|
" -M[M]D generate make dependency file [ignore system files]\n"
|
|
|
|
" -M[M] as above but no other output\n"
|
2020-05-11 22:23:48 +08:00
|
|
|
" -MF file specify dependency file name\n"
|
|
|
|
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
|
|
|
|
" -m32/64 defer to i386/x86_64 cross compiler\n"
|
|
|
|
#endif
|
2017-02-18 16:55:46 +08:00
|
|
|
"Tools:\n"
|
2022-04-19 13:53:19 +08:00
|
|
|
" create library : tcc -ar [rcsv] lib.a [files]\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
" create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n"
|
2009-04-19 00:21:38 +08:00
|
|
|
#endif
|
2017-02-18 16:55:46 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
static const char help2[] =
|
|
|
|
"Tiny C Compiler "TCC_VERSION" - More Options\n"
|
|
|
|
"Special options:\n"
|
|
|
|
" -P -P1 with -E: no/alternative #line output\n"
|
|
|
|
" -dD -dM with -E: output #define directives\n"
|
|
|
|
" -pthread same as -D_REENTRANT and -lpthread\n"
|
|
|
|
" -On same as -D__OPTIMIZE__ for n > 0\n"
|
|
|
|
" -Wp,-opt same as -opt\n"
|
|
|
|
" -include file include 'file' above each input file\n"
|
|
|
|
" -isystem dir add 'dir' to system include path\n"
|
|
|
|
" -static link to static libraries (not recommended)\n"
|
|
|
|
" -dumpversion print version\n"
|
|
|
|
" -print-search-dirs print search paths\n"
|
2017-07-21 04:21:27 +08:00
|
|
|
" -dt with -run/-E: auto-define 'test_...' macros\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
"Ignored options:\n"
|
2021-03-30 17:25:58 +08:00
|
|
|
" -arch -C --param -pedantic -pipe -s -traditional\n"
|
2021-07-28 02:55:24 +08:00
|
|
|
"-W[no-]... warnings:\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
" all turn on some (*) warnings\n"
|
2021-08-01 02:44:51 +08:00
|
|
|
" error[=warning] stop after warning (any or specified)\n"
|
|
|
|
" write-strings strings are const\n"
|
|
|
|
" unsupported warn about ignored options, pragmas, etc.\n"
|
|
|
|
" implicit-function-declaration warn for missing prototype (*)\n"
|
|
|
|
" discarded-qualifiers warn when const is dropped (*)\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
"-f[no-]... flags:\n"
|
|
|
|
" unsigned-char default char is unsigned\n"
|
|
|
|
" signed-char default char is signed\n"
|
|
|
|
" common use common section instead of bss\n"
|
|
|
|
" leading-underscore decorate extern symbols\n"
|
2017-02-21 01:58:08 +08:00
|
|
|
" ms-extensions allow anonymous struct in struct\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
" dollars-in-identifiers allow '$' in C symbols\n"
|
2021-01-24 01:17:38 +08:00
|
|
|
" test-coverage create code coverage code\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
"-m... target specific options:\n"
|
|
|
|
" ms-bitfields use MSVC bitfield layout\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
#ifdef TCC_TARGET_ARM
|
2017-02-18 16:55:46 +08:00
|
|
|
" float-abi hard/softfp on arm\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
#endif
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
2017-02-18 16:55:46 +08:00
|
|
|
" no-sse disable floats on x86_64\n"
|
2017-02-18 16:55:34 +08:00
|
|
|
#endif
|
2017-02-18 16:55:46 +08:00
|
|
|
"-Wl,... linker options:\n"
|
|
|
|
" -nostdlib do not link with standard crt/libs\n"
|
|
|
|
" -[no-]whole-archive load lib(s) fully/only as needed\n"
|
2017-04-04 14:34:52 +08:00
|
|
|
" -export-all-symbols same as -rdynamic\n"
|
2018-06-12 00:15:24 +08:00
|
|
|
" -export-dynamic same as -rdynamic\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
" -image-base= -Ttext= set base address of executable\n"
|
|
|
|
" -section-alignment= set section alignment in executable\n"
|
2017-02-18 16:55:34 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
2017-02-18 16:55:46 +08:00
|
|
|
" -file-alignment= set PE file alignment\n"
|
|
|
|
" -stack= set PE stack reserve\n"
|
|
|
|
" -large-address-aware set related PE option\n"
|
2017-04-04 14:34:52 +08:00
|
|
|
" -subsystem=[console/windows] set PE subsystem\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
" -oformat=[pe-* binary] set executable output format\n"
|
|
|
|
"Predefined macros:\n"
|
|
|
|
" tcc -E -dM - < nul\n"
|
|
|
|
#else
|
2017-05-08 23:44:52 +08:00
|
|
|
" -rpath= set dynamic library search path\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
" -enable-new-dtags set DT_RUNPATH instead of DT_RPATH\n"
|
|
|
|
" -soname= set DT_SONAME elf tag\n"
|
|
|
|
" -Bsymbolic set DT_SYMBOLIC elf tag\n"
|
|
|
|
" -oformat=[elf32/64-* binary] set executable output format\n"
|
2022-07-28 23:33:51 +08:00
|
|
|
" -init= -fini= -Map= -as-needed -O (ignored)\n"
|
2017-02-18 16:55:46 +08:00
|
|
|
"Predefined macros:\n"
|
|
|
|
" tcc -E -dM - < /dev/null\n"
|
2016-12-19 05:57:03 +08:00
|
|
|
#endif
|
2017-02-18 16:55:46 +08:00
|
|
|
"See also the manual for more details.\n"
|
|
|
|
;
|
2017-02-09 02:49:28 +08:00
|
|
|
|
2017-02-18 16:55:46 +08:00
|
|
|
static const char version[] =
|
2021-04-01 04:24:29 +08:00
|
|
|
"tcc version "TCC_VERSION
|
2021-08-02 02:04:46 +08:00
|
|
|
#ifdef TCC_GITHASH
|
|
|
|
" "TCC_GITHASH
|
2021-04-01 04:24:29 +08:00
|
|
|
#endif
|
|
|
|
" ("
|
2011-08-06 22:08:33 +08:00
|
|
|
#ifdef TCC_TARGET_I386
|
2017-02-18 16:55:34 +08:00
|
|
|
"i386"
|
|
|
|
#elif defined TCC_TARGET_X86_64
|
2017-02-18 16:55:46 +08:00
|
|
|
"x86_64"
|
2017-02-18 16:55:34 +08:00
|
|
|
#elif defined TCC_TARGET_C67
|
|
|
|
"C67"
|
|
|
|
#elif defined TCC_TARGET_ARM
|
|
|
|
"ARM"
|
2021-01-09 22:04:46 +08:00
|
|
|
# ifdef TCC_ARM_EABI
|
|
|
|
" eabi"
|
|
|
|
# ifdef TCC_ARM_HARDFLOAT
|
|
|
|
"hf"
|
|
|
|
# endif
|
|
|
|
# endif
|
2017-02-18 16:55:34 +08:00
|
|
|
#elif defined TCC_TARGET_ARM64
|
|
|
|
"AArch64"
|
2020-04-12 23:34:01 +08:00
|
|
|
#elif defined TCC_TARGET_RISCV64
|
|
|
|
"riscv64"
|
2017-02-21 01:58:08 +08:00
|
|
|
#endif
|
2011-08-06 22:08:33 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
2017-02-18 16:55:34 +08:00
|
|
|
" Windows"
|
2017-03-28 15:28:59 +08:00
|
|
|
#elif defined(TCC_TARGET_MACHO)
|
|
|
|
" Darwin"
|
2020-12-17 03:08:43 +08:00
|
|
|
#elif TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel
|
2017-02-18 16:55:34 +08:00
|
|
|
" FreeBSD"
|
2020-12-17 03:08:43 +08:00
|
|
|
#elif TARGETOS_OpenBSD
|
2020-11-27 18:24:19 +08:00
|
|
|
" OpenBSD"
|
2020-12-17 03:08:43 +08:00
|
|
|
#elif TARGETOS_NetBSD
|
2020-12-11 21:26:26 +08:00
|
|
|
" NetBSD"
|
2017-02-09 02:49:28 +08:00
|
|
|
#else
|
2017-02-21 01:58:08 +08:00
|
|
|
" Linux"
|
2011-08-06 22:08:33 +08:00
|
|
|
#endif
|
2017-02-18 16:55:46 +08:00
|
|
|
")\n"
|
|
|
|
;
|
2010-12-08 16:27:06 +08:00
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
static void print_dirs(const char *msg, char **paths, int nb_paths)
|
2011-08-11 22:55:30 +08:00
|
|
|
{
|
2013-02-13 02:13:28 +08:00
|
|
|
int i;
|
2017-02-18 16:55:34 +08:00
|
|
|
printf("%s:\n%s", msg, nb_paths ? "" : " -\n");
|
|
|
|
for(i = 0; i < nb_paths; i++)
|
|
|
|
printf(" %s\n", paths[i]);
|
|
|
|
}
|
2011-08-11 22:55:30 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
static void print_search_dirs(TCCState *s)
|
2017-02-18 16:55:34 +08:00
|
|
|
{
|
2021-10-22 13:39:54 +08:00
|
|
|
printf("install: %s\n", s->tcc_lib_path);
|
2017-02-18 16:55:34 +08:00
|
|
|
/* print_dirs("programs", NULL, 0); */
|
2021-10-22 13:39:54 +08:00
|
|
|
print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
|
|
|
|
print_dirs("libraries", s->library_paths, s->nb_library_paths);
|
2022-08-20 18:58:56 +08:00
|
|
|
printf("libtcc1:\n %s/%s\n", s->library_paths[0], CONFIG_TCC_CROSSPREFIX TCC_LIBTCC1);
|
|
|
|
#ifndef TCC_TARGET_PE
|
2021-10-22 13:39:54 +08:00
|
|
|
print_dirs("crt", s->crt_paths, s->nb_crt_paths);
|
|
|
|
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
|
2017-02-18 16:55:34 +08:00
|
|
|
#endif
|
2013-02-13 02:13:28 +08:00
|
|
|
}
|
2012-04-19 00:32:37 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
static void set_environment(TCCState *s)
|
2017-02-21 01:58:08 +08:00
|
|
|
{
|
|
|
|
char * path;
|
|
|
|
|
|
|
|
path = getenv("C_INCLUDE_PATH");
|
|
|
|
if(path != NULL) {
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_add_sysinclude_path(s, path);
|
2017-02-21 01:58:08 +08:00
|
|
|
}
|
|
|
|
path = getenv("CPATH");
|
|
|
|
if(path != NULL) {
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_add_include_path(s, path);
|
2017-02-21 01:58:08 +08:00
|
|
|
}
|
|
|
|
path = getenv("LIBRARY_PATH");
|
|
|
|
if(path != NULL) {
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_add_library_path(s, path);
|
2017-02-21 01:58:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
static char *default_outputfile(TCCState *s, const char *first_file)
|
2013-02-13 02:13:28 +08:00
|
|
|
{
|
|
|
|
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
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_DLL)
|
2013-02-13 02:13:28 +08:00
|
|
|
strcpy(ext, ".dll");
|
|
|
|
else
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_EXE)
|
2013-02-13 02:13:28 +08:00
|
|
|
strcpy(ext, ".exe");
|
|
|
|
else
|
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
if ((s->just_deps || 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");
|
2021-10-22 13:39:54 +08:00
|
|
|
return tcc_strdup(buf);
|
2013-02-13 02:13:28 +08:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-07-21 04:21:27 +08:00
|
|
|
int main(int argc0, char **argv0)
|
2003-10-05 05:23:51 +08:00
|
|
|
{
|
2021-10-22 13:39:54 +08:00
|
|
|
TCCState *s, *s1;
|
2019-12-17 05:34:47 +08:00
|
|
|
int ret, opt, n = 0, t = 0, done;
|
2021-08-02 02:04:46 +08:00
|
|
|
unsigned start_time = 0, end_time = 0;
|
2017-02-18 16:55:34 +08:00
|
|
|
const char *first_file;
|
2017-07-21 04:21:27 +08:00
|
|
|
int argc; char **argv;
|
|
|
|
FILE *ppfp = stdout;
|
2003-10-05 05:23:51 +08:00
|
|
|
|
2017-02-18 16:55:34 +08:00
|
|
|
redo:
|
2017-07-21 04:21:27 +08:00
|
|
|
argc = argc0, argv = argv0;
|
2021-10-22 13:39:54 +08:00
|
|
|
s = s1 = tcc_new();
|
2022-08-20 18:58:56 +08:00
|
|
|
#ifdef CONFIG_TCC_SWITCHES /* predefined options */
|
2022-05-18 04:28:32 +08:00
|
|
|
tcc_set_options(s, CONFIG_TCC_SWITCHES);
|
|
|
|
#endif
|
2021-10-22 13:39:54 +08:00
|
|
|
opt = tcc_parse_args(s, &argc, &argv, 1);
|
2017-02-18 16:55:34 +08:00
|
|
|
|
2019-12-17 05:34:47 +08:00
|
|
|
if (n == 0) {
|
2020-06-01 23:11:11 +08:00
|
|
|
if (opt == OPT_HELP) {
|
|
|
|
fputs(help, stdout);
|
2021-10-22 13:39:54 +08:00
|
|
|
if (!s->verbose)
|
2020-06-02 00:10:58 +08:00
|
|
|
return 0;
|
|
|
|
++opt;
|
2020-06-01 23:11:11 +08:00
|
|
|
}
|
|
|
|
if (opt == OPT_HELP2) {
|
2020-06-02 00:01:12 +08:00
|
|
|
fputs(help2, stdout);
|
2020-06-01 23:11:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-02-18 16:55:34 +08:00
|
|
|
if (opt == OPT_M32 || opt == OPT_M64)
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_tool_cross(s, argv, opt); /* never returns */
|
|
|
|
if (s->verbose)
|
2017-02-18 16:55:46 +08:00
|
|
|
printf(version);
|
2017-02-18 16:55:34 +08:00
|
|
|
if (opt == OPT_AR)
|
2021-10-22 13:39:54 +08:00
|
|
|
return tcc_tool_ar(s, argc, argv);
|
2017-02-18 16:55:34 +08:00
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
if (opt == OPT_IMPDEF)
|
2021-10-22 13:39:54 +08:00
|
|
|
return tcc_tool_impdef(s, argc, argv);
|
2017-02-18 16:55:34 +08:00
|
|
|
#endif
|
|
|
|
if (opt == OPT_V)
|
|
|
|
return 0;
|
|
|
|
if (opt == OPT_PRINT_DIRS) {
|
|
|
|
/* initialize search dirs */
|
2021-10-22 13:39:54 +08:00
|
|
|
set_environment(s);
|
|
|
|
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
|
|
|
print_search_dirs(s);
|
2017-02-18 16:55:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-08-06 22:08:33 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->nb_files == 0)
|
|
|
|
tcc_error("no input files");
|
2017-02-18 16:55:34 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
|
|
|
if (s->outfile && 0!=strcmp("-",s->outfile)) {
|
|
|
|
ppfp = fopen(s->outfile, "w");
|
2017-07-21 04:21:27 +08:00
|
|
|
if (!ppfp)
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_error("could not write '%s'", s->outfile);
|
2016-10-02 02:19:37 +08:00
|
|
|
}
|
2021-10-22 13:39:54 +08:00
|
|
|
} else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
|
|
|
|
if (s->nb_libraries)
|
|
|
|
tcc_error("cannot specify libraries with -c");
|
|
|
|
if (s->nb_files > 1 && s->outfile)
|
|
|
|
tcc_error("cannot specify output file with -c many files");
|
2016-10-02 02:19:37 +08:00
|
|
|
}
|
2002-07-18 08:51:11 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->do_bench)
|
2017-02-18 16:55:34 +08:00
|
|
|
start_time = getclock_ms();
|
2002-08-31 06:46:35 +08:00
|
|
|
}
|
2015-05-13 02:32:32 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
set_environment(s);
|
|
|
|
if (s->output_type == 0)
|
|
|
|
s->output_type = TCC_OUTPUT_EXE;
|
|
|
|
tcc_set_output_type(s, s->output_type);
|
|
|
|
s->ppfp = ppfp;
|
2017-07-21 04:21:27 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if ((s->output_type == TCC_OUTPUT_MEMORY
|
|
|
|
|| s->output_type == TCC_OUTPUT_PREPROCESS)
|
|
|
|
&& (s->dflag & 16)) { /* -dt option */
|
2019-12-17 05:34:47 +08:00
|
|
|
if (t)
|
2021-10-22 13:39:54 +08:00
|
|
|
s->dflag |= 32;
|
|
|
|
s->run_test = ++t;
|
2019-12-17 05:34:47 +08:00
|
|
|
if (n)
|
|
|
|
--n;
|
|
|
|
}
|
2002-08-31 06:46:35 +08:00
|
|
|
|
|
|
|
/* compile or add each files or library */
|
2019-12-17 05:34:47 +08:00
|
|
|
first_file = NULL, ret = 0;
|
|
|
|
do {
|
2021-10-22 13:39:54 +08:00
|
|
|
struct filespec *f = s->files[n];
|
|
|
|
s->filetype = f->type;
|
2018-06-01 05:51:59 +08:00
|
|
|
if (f->type & AFF_TYPE_LIB) {
|
2021-10-22 13:39:54 +08:00
|
|
|
if (tcc_add_library_err(s, f->name) < 0)
|
2016-10-02 02:04:58 +08:00
|
|
|
ret = 1;
|
2002-08-31 06:46:35 +08:00
|
|
|
} else {
|
2021-10-22 13:39:54 +08:00
|
|
|
if (1 == s->verbose)
|
2016-10-02 02:04:58 +08:00
|
|
|
printf("-> %s\n", f->name);
|
2016-10-02 02:04:33 +08:00
|
|
|
if (!first_file)
|
2016-10-02 02:04:58 +08:00
|
|
|
first_file = f->name;
|
2021-10-22 13:39:54 +08:00
|
|
|
if (tcc_add_file(s, f->name) < 0)
|
2017-02-18 16:55:34 +08:00
|
|
|
ret = 1;
|
2002-08-31 06:46:35 +08:00
|
|
|
}
|
2021-10-22 13:39:54 +08:00
|
|
|
done = ret || ++n >= s->nb_files;
|
|
|
|
} while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r));
|
2002-07-18 08:51:11 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->do_bench)
|
2021-08-02 02:04:46 +08:00
|
|
|
end_time = getclock_ms();
|
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->run_test) {
|
2017-07-24 03:24:11 +08:00
|
|
|
t = 0;
|
2021-10-22 13:39:54 +08:00
|
|
|
} else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
2017-07-21 04:21:27 +08:00
|
|
|
;
|
2016-10-02 03:52:11 +08:00
|
|
|
} else if (0 == ret) {
|
2021-10-22 13:39:54 +08:00
|
|
|
if (s->output_type == TCC_OUTPUT_MEMORY) {
|
2012-03-06 03:15:56 +08:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2021-10-22 13:39:54 +08:00
|
|
|
ret = tcc_run(s, argc, argv);
|
2012-03-06 03:15:56 +08:00
|
|
|
#endif
|
2016-10-02 02:04:33 +08:00
|
|
|
} else {
|
2021-10-22 13:39:54 +08:00
|
|
|
if (!s->outfile)
|
|
|
|
s->outfile = default_outputfile(s, first_file);
|
|
|
|
if (!s->just_deps && tcc_output_file(s, s->outfile))
|
2017-02-18 16:55:34 +08:00
|
|
|
ret = 1;
|
2021-10-22 13:39:54 +08:00
|
|
|
else if (s->gen_deps)
|
|
|
|
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
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
if (done && 0 == t && 0 == ret && s->do_bench)
|
|
|
|
tcc_print_stats(s, end_time - start_time);
|
2021-08-02 02:04:46 +08:00
|
|
|
|
2021-10-22 13:39:54 +08:00
|
|
|
tcc_delete(s);
|
2019-12-17 05:34:47 +08:00
|
|
|
if (!done)
|
2017-02-18 16:55:34 +08:00
|
|
|
goto redo; /* compile more files with -c */
|
2017-07-21 04:21:27 +08:00
|
|
|
if (t)
|
|
|
|
goto redo; /* run more tests with -dt -run */
|
2021-08-02 02:04:46 +08:00
|
|
|
|
2017-07-21 04:21:27 +08:00
|
|
|
if (ppfp && ppfp != stdout)
|
|
|
|
fclose(ppfp);
|
2002-11-02 22:12:32 +08:00
|
|
|
return ret;
|
2001-10-28 07:48:39 +08:00
|
|
|
}
|