diff options
| author | Steffen Nurpmeso <steffen@sdaoden.eu> | 2017-09-30 00:13:05 +0200 |
|---|---|---|
| committer | Steffen Nurpmeso <steffen@sdaoden.eu> | 2017-10-03 17:58:45 +0200 |
| commit | 1d5e386b0a78393ac6b670c209a185849ec798a1 (patch) | |
| tree | 6f01f1f94079d73ee45caefe3ea3fa4ae5ecac61 | |
| parent | a1c90513131164500f503108a845fee1e8632cc6 (diff) | |
| download | tinycc-1d5e386b0a78393ac6b670c209a185849ec798a1.tar.gz tinycc-1d5e386b0a78393ac6b670c209a185849ec798a1.tar.bz2 | |
Introduce VIP sysinclude paths which are always searched first
| -rw-r--r-- | libtcc.c | 10 | ||||
| -rw-r--r-- | libtcc.h | 3 | ||||
| -rw-r--r-- | tcc.c | 1 | ||||
| -rw-r--r-- | tcc.h | 18 | ||||
| -rw-r--r-- | tccpp.c | 13 |
5 files changed, 36 insertions, 9 deletions
@@ -906,6 +906,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1) /* free include paths */ dynarray_reset(&s1->cached_includes, &s1->nb_cached_includes); + dynarray_reset(&s1->tccinclude_paths, &s1->nb_tccinclude_paths); dynarray_reset(&s1->include_paths, &s1->nb_include_paths); dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths); dynarray_reset(&s1->cmd_include_files, &s1->nb_cmd_include_files); @@ -946,6 +947,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) if (!s->nostdinc) { /* default include paths */ /* -isystem paths have already been handled */ + tcc_add_tccinclude_path(s, CONFIG_TCC_TCCINCLUDEPATHS); tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); } @@ -983,6 +985,12 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) return 0; } +LIBTCCAPI int tcc_add_tccinclude_path(TCCState *s, const char *pathname) +{ + tcc_split_path(s, &s->tccinclude_paths, &s->nb_tccinclude_paths, pathname); + return 0; +} + LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) { tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname); @@ -1821,7 +1829,7 @@ reparse: break; case TCC_OPTION_iwithprefix: snprintf(buf, sizeof buf, "{B}/%s", optarg); - tcc_add_sysinclude_path(s, buf); + tcc_add_tccinclude_path(s, buf); break; case TCC_OPTION_include: dynarray_add(&s->cmd_include_files, @@ -32,6 +32,9 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *str); /*****************************/ /* preprocessor */ +/* add in tcc include path, searched before anything else */ +LIBTCCAPI int tcc_add_tccinclude_path(TCCState *s, const char *pathname); + /* add include path */ LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname); @@ -181,6 +181,7 @@ static void print_search_dirs(TCCState *s) { printf("install: %s\n", s->tcc_lib_path); /* print_dirs("programs", NULL, 0); */ + print_dirs("tcc-include", s->tccinclude_paths, s->nb_tccinclude_paths); print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths); print_dirs("libraries", s->library_paths, s->nb_library_paths); #ifndef TCC_TARGET_PE @@ -195,13 +195,18 @@ extern long double strtold (const char *__nptr, char **__endptr); /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */ /* system include paths */ -#ifndef CONFIG_TCC_SYSINCLUDEPATHS +#ifndef CONFIG_TCC_TCCINCLUDEPATHS # ifdef TCC_TARGET_PE -# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi" +# define CONFIG_TCC_TCCINCLUDEPATHS "{B}/include;{B}/include/winapi" # else +# define CONFIG_TCC_TCCINCLUDEPATHS "{B}/include" +# endif +#endif + +#ifndef CONFIG_TCC_SYSINCLUDEPATHS +# ifndef TCC_TARGET_PE # define CONFIG_TCC_SYSINCLUDEPATHS \ - "{B}/include" \ - ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \ + ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include") # endif #endif @@ -715,7 +720,10 @@ struct TCCState { DLLReference **loaded_dlls; int nb_loaded_dlls; - /* include paths */ + /* include paths, search order */ + char **tccinclude_paths; + int nb_tccinclude_paths; + char **include_paths; int nb_include_paths; @@ -1803,7 +1803,8 @@ ST_FUNC void preprocess(int is_bof) /* store current file in stack, but increment stack later below */ *s1->include_stack_ptr = file; i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0; - n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; + n = 2 + s1->nb_tccinclude_paths + s1->nb_include_paths + + s1->nb_sysinclude_paths; for (; i < n; ++i) { char buf1[sizeof file->filename]; CachedInclude *e; @@ -1825,8 +1826,14 @@ ST_FUNC void preprocess(int is_bof) } else { /* search in all the include paths */ - int j = i - 2, k = j - s1->nb_include_paths; - path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k]; + int k, j = i - 2; + + if (j < (k = s1->nb_tccinclude_paths)) + path = s1->tccinclude_paths[j]; + else if ((j -= k) < s1->nb_include_paths) + path = s1->include_paths[j]; + else if ((j -= s1->nb_include_paths) < s1->nb_sysinclude_paths) + path = s1->sysinclude_paths[j]; pstrcpy(buf1, sizeof(buf1), path); pstrcat(buf1, sizeof(buf1), "/"); } |
