aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-06-27 16:40:00 +0200
committerMichael Matz <matz@suse.de>2016-12-15 17:47:06 +0100
commit928514954898ee6c05d0495b0f84ed4e3fd42c71 (patch)
tree12f6f4806117ff3f1c0ebcc0fdc8d69a33f715e1
parent21d2b71b5c1ad1c51866ff8d7a1376f132b1cafa (diff)
downloadtinycc-928514954898ee6c05d0495b0f84ed4e3fd42c71.tar.gz
tinycc-928514954898ee6c05d0495b0f84ed4e3fd42c71.tar.bz2
Implement -include cmdline option
This option includes a file as if '#include "file"' is the first line of compiled files. It's processed after all -D/-U options and is processed per input file.
-rw-r--r--libtcc.c6
-rw-r--r--tcc.h4
-rw-r--r--tccpp.c14
3 files changed, 24 insertions, 0 deletions
diff --git a/libtcc.c b/libtcc.c
index 23e4e76..3d4acff 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1518,6 +1518,7 @@ enum {
TCC_OPTION_f,
TCC_OPTION_isystem,
TCC_OPTION_iwithprefix,
+ TCC_OPTION_include,
TCC_OPTION_nostdinc,
TCC_OPTION_nostdlib,
TCC_OPTION_print_search_dirs,
@@ -1582,6 +1583,7 @@ static const TCCOption tcc_options[] = {
{ "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG },
{ "iwithprefix", TCC_OPTION_iwithprefix, TCC_OPTION_HAS_ARG },
+ { "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG },
{ "nostdinc", TCC_OPTION_nostdinc, 0 },
{ "nostdlib", TCC_OPTION_nostdlib, 0 },
{ "print-search-dirs", TCC_OPTION_print_search_dirs, 0 },
@@ -1789,6 +1791,10 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
snprintf(buf, sizeof buf, "{B}/%s", optarg);
tcc_add_sysinclude_path(s, buf);
break;
+ case TCC_OPTION_include:
+ dynarray_add((void ***)&s->cmd_include_files,
+ &s->nb_cmd_include_files, tcc_strdup(optarg));
+ break;
case TCC_OPTION_nostdinc:
s->nostdinc = 1;
break;
diff --git a/tcc.h b/tcc.h
index 47af365..1e2b815 100644
--- a/tcc.h
+++ b/tcc.h
@@ -661,6 +661,10 @@ struct TCCState {
char **crt_paths;
int nb_crt_paths;
+ /* -include files */
+ char **cmd_include_files;
+ int nb_cmd_include_files;
+
/* error handling */
void *error_opaque;
void (*error_func)(void *opaque, const char *msg);
diff --git a/tccpp.c b/tccpp.c
index 6446c9c..151bce6 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -3480,6 +3480,20 @@ ST_FUNC void preprocess_start(TCCState *s1)
s1->dollars_in_identifiers ? IS_ID : 0;
isidnum_table['.' - CH_EOF] =
(parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
+ if (s1->nb_cmd_include_files) {
+ CString cstr;
+ int i;
+ cstr_new(&cstr);
+ for (i = 0; i < s1->nb_cmd_include_files; i++) {
+ cstr_cat(&cstr, "#include \"", -1);
+ cstr_cat(&cstr, s1->cmd_include_files[i], -1);
+ cstr_cat(&cstr, "\"\n", -1);
+ }
+ *s1->include_stack_ptr++ = file;
+ tcc_open_bf(s1, "<command line>", cstr.size);
+ memcpy(file->buffer, cstr.data, cstr.size);
+ cstr_free(&cstr);
+ }
}
ST_FUNC void tccpp_new(TCCState *s)