forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_halide_h.cpp
More file actions
56 lines (44 loc) · 1.34 KB
/
build_halide_h.cpp
File metadata and controls
56 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <set>
#include <string>
#include <assert.h>
std::set<std::string> done;
void dump_header(std::string header) {
if (done.find(header) != done.end()) return;
done.insert(header);
FILE *f = fopen(header.c_str(), "r");
if (f == NULL) {
fprintf(stderr, "Could not open header %s.\n", header.c_str());
exit(1);
}
char line[1024];
while (fgets(line, 1024, f)) {
if (strncmp(line, "#include \"", 10) == 0) {
char *sub_header = line + 10;
for (int i = 0; i < 1014; i++) {
if (sub_header[i] == '"') sub_header[i] = 0;
}
size_t slash_pos = header.rfind('/');
std::string path;
if (slash_pos != std::string::npos)
path = header.substr(0, slash_pos + 1);
dump_header(path + sub_header);
} else {
fputs(line, stdout);
}
}
fclose(f);
}
int main(int argc, char **headers) {
// If we're building on windows and Halide_SHARED is defined, we'd better
// also define it for clients so that dllimport gets used.
#if defined(_WIN32) && defined(Halide_SHARED)
printf("#define Halide_SHARED\n");
#endif
for (int i = 1; i < argc; i++) {
dump_header(headers[i]);
}
return 0;
}