nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1diff --git a/pre-process.c b/pre-process.c
2index 457685c0..006209ad 100644
3--- a/pre-process.c
4+++ b/pre-process.c
5@@ -2410,32 +2410,27 @@ static void do_preprocess(struct token **list)
6
7 void init_include_path(void)
8 {
9- FILE *fp;
10- char path[256];
11- char arch[32];
12- char os[32];
13-
14- fp = popen("/bin/uname -m", "r");
15- if (!fp)
16- return;
17- if (!fgets(arch, sizeof(arch) - 1, fp))
18- return;
19- pclose(fp);
20- if (arch[strlen(arch) - 1] == '\n')
21- arch[strlen(arch) - 1] = '\0';
22-
23- fp = popen("/bin/uname -o", "r");
24- if (!fp)
25- return;
26- fgets(os, sizeof(os) - 1, fp);
27- pclose(fp);
28-
29- if (strcmp(os, "GNU/Linux\n") != 0)
30- return;
31- strcpy(os, "linux-gnu");
32-
33- snprintf(path, sizeof(path), "/usr/include/%s-%s/", arch, os);
34- add_pre_buffer("#add_system \"%s/\"\n", path);
35+ add_pre_buffer("#add_system \"%s/\"\n", "@clang@");
36+ add_pre_buffer("#add_system \"%s/\"\n", "@libc@");
37+
38+ bool collect = false;
39+ char *nix_cflags = getenv("NIX_CFLAGS_COMPILE");
40+ if (nix_cflags == NULL)
41+ return;
42+
43+ for (
44+ char *token = strtok(nix_cflags, " ");
45+ token != NULL;
46+ token = strtok(NULL, " ")
47+ ) {
48+ if (collect && *token == '/') {
49+ add_pre_buffer("#add_system \"%s/\"\n", token);
50+ collect = false;
51+ continue;
52+ }
53+ if (!strcmp(token, "-isystem"))
54+ collect = true;
55+ }
56 }
57
58 struct token * preprocess(struct token *token)