Add default include paths

This commit is contained in:
Rui Ueyama 2020-09-19 20:42:21 +09:00
parent a1dd6213c8
commit a939a7a906
2 changed files with 13 additions and 0 deletions

12
main.c
View File

@ -29,6 +29,17 @@ static bool take_arg(char *arg) {
return false;
}
static void add_default_include_paths(char *argv0) {
// We expect that chibicc-specific include files are installed
// to ./include relative to argv[0].
strarray_push(&include_paths, format("%s/include", dirname(strdup(argv0))));
// Add standard include paths.
strarray_push(&include_paths, "/usr/local/include");
strarray_push(&include_paths, "/usr/include/x86_64-linux-gnu");
strarray_push(&include_paths, "/usr/include");
}
static void parse_args(int argc, char **argv) {
// Make sure that all command line options that take an argument
// have an argument.
@ -313,6 +324,7 @@ int main(int argc, char **argv) {
parse_args(argc, argv);
if (opt_cc1) {
add_default_include_paths(argv[0]);
cc1();
return 0;
}

View File

@ -71,6 +71,7 @@ int strncmp(char *p, char *q, long n);
void *memcpy(char *dst, char *src, long n);
char *strdup(char *p);
char *strndup(char *p, long n);
char *strdup(char *p);
int isspace(int c);
int ispunct(int c);
int isdigit(int c);