mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-04 06:30:10 +08:00
Introduce VIP sysinclude paths which are always searched first
This commit is contained in:
parent
a1c9051313
commit
1d5e386b0a
10
libtcc.c
10
libtcc.c
@ -906,6 +906,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
|
|||||||
|
|
||||||
/* free include paths */
|
/* free include paths */
|
||||||
dynarray_reset(&s1->cached_includes, &s1->nb_cached_includes);
|
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->include_paths, &s1->nb_include_paths);
|
||||||
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
||||||
dynarray_reset(&s1->cmd_include_files, &s1->nb_cmd_include_files);
|
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) {
|
if (!s->nostdinc) {
|
||||||
/* default include paths */
|
/* default include paths */
|
||||||
/* -isystem paths have already been handled */
|
/* -isystem paths have already been handled */
|
||||||
|
tcc_add_tccinclude_path(s, CONFIG_TCC_TCCINCLUDEPATHS);
|
||||||
tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
|
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;
|
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)
|
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
|
||||||
{
|
{
|
||||||
tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
|
tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
|
||||||
@ -1821,7 +1829,7 @@ reparse:
|
|||||||
break;
|
break;
|
||||||
case TCC_OPTION_iwithprefix:
|
case TCC_OPTION_iwithprefix:
|
||||||
snprintf(buf, sizeof buf, "{B}/%s", optarg);
|
snprintf(buf, sizeof buf, "{B}/%s", optarg);
|
||||||
tcc_add_sysinclude_path(s, buf);
|
tcc_add_tccinclude_path(s, buf);
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_include:
|
case TCC_OPTION_include:
|
||||||
dynarray_add(&s->cmd_include_files,
|
dynarray_add(&s->cmd_include_files,
|
||||||
|
3
libtcc.h
3
libtcc.h
@ -32,6 +32,9 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
|
|||||||
/*****************************/
|
/*****************************/
|
||||||
/* preprocessor */
|
/* preprocessor */
|
||||||
|
|
||||||
|
/* add in tcc include path, searched before anything else */
|
||||||
|
LIBTCCAPI int tcc_add_tccinclude_path(TCCState *s, const char *pathname);
|
||||||
|
|
||||||
/* add include path */
|
/* add include path */
|
||||||
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
|
LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
|
||||||
|
|
||||||
|
1
tcc.c
1
tcc.c
@ -181,6 +181,7 @@ static void print_search_dirs(TCCState *s)
|
|||||||
{
|
{
|
||||||
printf("install: %s\n", s->tcc_lib_path);
|
printf("install: %s\n", s->tcc_lib_path);
|
||||||
/* print_dirs("programs", NULL, 0); */
|
/* 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("include", s->sysinclude_paths, s->nb_sysinclude_paths);
|
||||||
print_dirs("libraries", s->library_paths, s->nb_library_paths);
|
print_dirs("libraries", s->library_paths, s->nb_library_paths);
|
||||||
#ifndef TCC_TARGET_PE
|
#ifndef TCC_TARGET_PE
|
||||||
|
18
tcc.h
18
tcc.h
@ -195,13 +195,18 @@ extern long double strtold (const char *__nptr, char **__endptr);
|
|||||||
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
|
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
|
||||||
|
|
||||||
/* system include paths */
|
/* system include paths */
|
||||||
#ifndef CONFIG_TCC_SYSINCLUDEPATHS
|
#ifndef CONFIG_TCC_TCCINCLUDEPATHS
|
||||||
# ifdef TCC_TARGET_PE
|
# ifdef TCC_TARGET_PE
|
||||||
# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
|
# define CONFIG_TCC_TCCINCLUDEPATHS "{B}/include;{B}/include/winapi"
|
||||||
# else
|
# else
|
||||||
|
# define CONFIG_TCC_TCCINCLUDEPATHS "{B}/include"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_TCC_SYSINCLUDEPATHS
|
||||||
|
# ifndef TCC_TARGET_PE
|
||||||
# define CONFIG_TCC_SYSINCLUDEPATHS \
|
# 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")
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
@ -715,7 +720,10 @@ struct TCCState {
|
|||||||
DLLReference **loaded_dlls;
|
DLLReference **loaded_dlls;
|
||||||
int nb_loaded_dlls;
|
int nb_loaded_dlls;
|
||||||
|
|
||||||
/* include paths */
|
/* include paths, search order */
|
||||||
|
char **tccinclude_paths;
|
||||||
|
int nb_tccinclude_paths;
|
||||||
|
|
||||||
char **include_paths;
|
char **include_paths;
|
||||||
int nb_include_paths;
|
int nb_include_paths;
|
||||||
|
|
||||||
|
13
tccpp.c
13
tccpp.c
@ -1803,7 +1803,8 @@ ST_FUNC void preprocess(int is_bof)
|
|||||||
/* store current file in stack, but increment stack later below */
|
/* store current file in stack, but increment stack later below */
|
||||||
*s1->include_stack_ptr = file;
|
*s1->include_stack_ptr = file;
|
||||||
i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0;
|
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) {
|
for (; i < n; ++i) {
|
||||||
char buf1[sizeof file->filename];
|
char buf1[sizeof file->filename];
|
||||||
CachedInclude *e;
|
CachedInclude *e;
|
||||||
@ -1825,8 +1826,14 @@ ST_FUNC void preprocess(int is_bof)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* search in all the include paths */
|
/* search in all the include paths */
|
||||||
int j = i - 2, k = j - s1->nb_include_paths;
|
int k, j = i - 2;
|
||||||
path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k];
|
|
||||||
|
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);
|
pstrcpy(buf1, sizeof(buf1), path);
|
||||||
pstrcat(buf1, sizeof(buf1), "/");
|
pstrcat(buf1, sizeof(buf1), "/");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user