2 * TCC - Tiny C Compiler
4 * Copyright (c) 2001-2004 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 printf("tcc version " TCC_VERSION
" - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard\n"
26 "usage: tcc [-v] [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
27 " [-Wwarn] [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-soname name]\n"
28 " [-static] [infile1 infile2...] [-run infile args...]\n"
31 " -v display current version, increase verbosity\n"
32 " -c compile only - generate an object file\n"
33 " -o outfile set output filename\n"
34 " -Bdir set tcc internal library path\n"
35 " -bench output compilation statistics\n"
36 " -run run compiled source\n"
37 " -fflag set or reset (with 'no-' prefix) 'flag' (see man page)\n"
38 " -Wwarning set or reset (with 'no-' prefix) 'warning' (see man page)\n"
39 " -w disable all warnings\n"
40 "Preprocessor options:\n"
41 " -E preprocess only\n"
42 " -Idir add include path 'dir'\n"
43 " -Dsym[=val] define 'sym' with value 'val'\n"
44 " -Usym undefine 'sym'\n"
46 " -Ldir add library path 'dir'\n"
47 " -llib link with dynamic or static library 'lib'\n"
48 " -shared generate a shared library\n"
49 " -soname set name for shared library to be used at runtime\n"
50 " -static static linking\n"
51 " -rdynamic export all global symbols to dynamic linker\n"
52 " -r generate (relocatable) object file\n"
54 " -g generate runtime debug info\n"
55 #ifdef CONFIG_TCC_BCHECK
56 " -b compile with built-in memory and bounds checker (implies -g)\n"
58 #ifdef CONFIG_TCC_BACKTRACE
59 " -bt N show N callers in stack traces\n"
64 int main(int argc
, char **argv
)
69 int nb_objfiles
, ret
, optind
;
70 char objfilename
[1024];
71 int64_t start_time
= 0;
74 init_tcc_config(&config
);
78 optind
= parse_args(&config
, s
, argc
- 1, argv
+ 1);
79 if (config
.print_search_dirs
) {
80 /* enough for Linux kernel */
81 printf("install: %s/\n", s
->tcc_lib_path
);
84 if (optind
== 0 || config
.nb_files
== 0) {
85 if (optind
&& s
->verbose
)
91 nb_objfiles
= config
.nb_files
- config
.nb_libraries
;
93 /* if outfile provided without other options, we output an
95 if (config
.outfile
&& config
.output_type
== TCC_OUTPUT_MEMORY
)
96 config
.output_type
= TCC_OUTPUT_EXE
;
98 /* check -c consistency : only single file handled. XXX: checks file type */
99 if (config
.output_type
== TCC_OUTPUT_OBJ
&& !config
.reloc_output
) {
100 /* accepts only a single input file */
101 if (nb_objfiles
!= 1)
102 error("cannot specify multiple files with -c");
103 if (config
.nb_libraries
!= 0)
104 error("cannot specify libraries with -c");
108 if (config
.output_type
== TCC_OUTPUT_PREPROCESS
) {
109 if (!config
.outfile
) {
112 s
->outfile
= fopen(config
.outfile
, "w");
114 error("could not open '%s", config
.outfile
);
116 } else if (config
.output_type
!= TCC_OUTPUT_MEMORY
) {
117 if (!config
.outfile
) {
118 /* compute default outfile name */
121 strcmp(config
.files
[0], "-") == 0 ? "a" : tcc_basename(config
.files
[0]);
122 pstrcpy(objfilename
, sizeof(objfilename
), name
);
123 ext
= tcc_fileextension(objfilename
);
125 if (config
.output_type
== TCC_OUTPUT_DLL
)
128 if (config
.output_type
== TCC_OUTPUT_EXE
)
132 if (config
.output_type
== TCC_OUTPUT_OBJ
&& !config
.reloc_output
&& *ext
)
135 pstrcpy(objfilename
, sizeof(objfilename
), "a.out");
136 config
.outfile
= objfilename
;
140 if (config
.do_bench
) {
141 start_time
= getclock_us();
144 tcc_set_output_type(s
, config
.output_type
);
146 /* compile or add each files or library */
147 for(i
= 0; i
< config
.nb_files
&& ret
== 0; i
++) {
148 const char *filename
;
150 filename
= config
.files
[i
];
151 if (filename
[0] == '-' && filename
[1]) {
152 if (tcc_add_library(s
, filename
+ 2) < 0) {
153 error_noabort("cannot find %s", filename
);
158 printf("-> %s\n", filename
);
159 if (tcc_add_file(s
, filename
) < 0)
165 tcc_free(config
.files
);
169 tcc_print_stats(s
, getclock_us() - start_time
);
171 if (s
->output_type
== TCC_OUTPUT_PREPROCESS
) {
174 } else if (s
->output_type
== TCC_OUTPUT_MEMORY
)
175 ret
= tcc_run(s
, argc
- optind
, argv
+ optind
);
177 ret
= tcc_output_file(s
, config
.outfile
) ? 1 : 0;
184 printf("memory: %d bytes, max = %d bytes\n", mem_cur_size
, mem_max_size
);