authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 19:22:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 19:22:58-07:00
logc281533638dd08bb84f4f538fd8c5ae85791d034
tree94ed711ef254a4b35d729dd944c1da2d0f833e63
parent69d4f55fbf816bf417dfab9c0e7525971922f166

build command supports -isystem argument


7 files changed, 29 insertions(+), 9 deletions(-)

src/all_types.hpp+3
......@@ -1041,6 +1041,9 @@ struct CodeGen {
10411041 uint32_t error_value_count;
10421042 TypeTableEntry *err_tag_type;
10431043 LLVMValueRef int_overflow_fns[2][3][4]; // [0-signed,1-unsigned][0-add,1-sub,2-mul][0-8,1-16,2-32,3-64]
1044
1045 const char **clang_argv;
1046 int clang_argv_len;
10441047};
10451048
10461049struct VariableTableEntry {
src/analyze.cpp+3-1
......@@ -1057,7 +1057,9 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *import, AstNode
10571057 find_libc_path(g);
10581058 int err;
10591059 ParseH parse_h = {{0}};
1060 if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, buf_ptr(g->libc_include_path)))) {
1060 if ((err = parse_h_buf(&parse_h, child_context->c_import_buf, g->clang_argv, g->clang_argv_len,
1061 buf_ptr(g->libc_include_path))))
1062 {
10611063 zig_panic("unable to parse h file: %s\n", err_str(err));
10621064 }
10631065
src/codegen.cpp+5
......@@ -32,6 +32,11 @@ CodeGen *codegen_create(Buf *root_source_dir) {
3232 return g;
3333}
3434
35void codegen_set_clang_argv(CodeGen *g, const char **args, int len) {
36 g->clang_argv = args;
37 g->clang_argv_len = len;
38}
39
3540void codegen_set_build_type(CodeGen *g, CodeGenBuildType build_type) {
3641 g->build_type = build_type;
3742}
src/codegen.hpp+1
......@@ -13,6 +13,7 @@
1313
1414CodeGen *codegen_create(Buf *root_source_dir);
1515
16void codegen_set_clang_argv(CodeGen *codegen, const char **args, int len);
1617void codegen_set_build_type(CodeGen *codegen, CodeGenBuildType build_type);
1718void codegen_set_is_static(CodeGen *codegen, bool is_static);
1819void codegen_set_strip(CodeGen *codegen, bool strip);
src/main.cpp+11-6
......@@ -20,7 +20,7 @@ static int usage(const char *arg0) {
2020 " build create executable, object, or library from target\n"
2121 " version print version number and exit\n"
2222 " parseh convert a c header file to zig extern declarations\n"
23 "Command: build target\n"
23 "Options:\n"
2424 " --release build with optimizations on and debug protection off\n"
2525 " --static output will be statically linked\n"
2626 " --strip exclude debug symbols\n"
......@@ -30,10 +30,8 @@ static int usage(const char *arg0) {
3030 " --verbose turn on compiler debug output\n"
3131 " --color [auto|off|on] enable or disable colored error messages\n"
3232 " --libc-path [path] set the C compiler data path\n"
33 "Command: parseh target\n"
3433 " -isystem [dir] add additional search path for other .h files\n"
3534 " -dirafter [dir] same as -isystem but do it last\n"
36 " -B[prefix] set the C compiler data path\n"
3735 , arg0);
3836 return EXIT_FAILURE;
3937}
......@@ -54,6 +52,7 @@ struct Build {
5452 bool verbose;
5553 ErrColor color;
5654 const char *libc_path;
55 ZigList<const char *> clang_argv;
5756};
5857
5958static int build(const char *arg0, int argc, char **argv) {
......@@ -62,7 +61,7 @@ static int build(const char *arg0, int argc, char **argv) {
6261
6362 for (int i = 0; i < argc; i += 1) {
6463 char *arg = argv[i];
65 if (arg[0] == '-' && arg[1] == '-') {
64 if (arg[0] == '-') {
6665 if (strcmp(arg, "--release") == 0) {
6766 b.release = true;
6867 } else if (strcmp(arg, "--strip") == 0) {
......@@ -103,6 +102,12 @@ static int build(const char *arg0, int argc, char **argv) {
103102 b.out_name = argv[i];
104103 } else if (strcmp(arg, "--libc-path") == 0) {
105104 b.libc_path = argv[i];
105 } else if (strcmp(arg, "-isystem") == 0) {
106 b.clang_argv.append("-isystem");
107 b.clang_argv.append(argv[i]);
108 } else if (strcmp(arg, "-dirafter") == 0) {
109 b.clang_argv.append("-dirafter");
110 b.clang_argv.append(argv[i]);
106111 } else {
107112 return usage(arg0);
108113 }
......@@ -140,6 +145,7 @@ static int build(const char *arg0, int argc, char **argv) {
140145
141146 CodeGen *g = codegen_create(&root_source_dir);
142147 codegen_set_build_type(g, b.release ? CodeGenBuildTypeRelease : CodeGenBuildTypeDebug);
148 codegen_set_clang_argv(g, b.clang_argv.items, b.clang_argv.length);
143149 codegen_set_strip(g, b.strip);
144150 codegen_set_is_static(g, b.is_static);
145151 if (b.out_type != OutTypeUnknown)
......@@ -202,8 +208,7 @@ static int parseh(const char *arg0, int argc, char **argv) {
202208 }
203209 clang_argv.append("-isystem");
204210 clang_argv.append(argv[i + 1]);
205 } else if (arg[1] == 'B') {
206 clang_argv.append(arg);
211 i += 1;
207212 } else {
208213 fprintf(stderr, "unrecognized argument: %s", arg);
209214 return usage(arg0);
src/parseh.cpp+5-1
......@@ -345,7 +345,7 @@ static bool decl_visitor(void *context, const Decl *decl) {
345345 return true;
346346}
347347
348int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) {
348int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path) {
349349 int err;
350350 Buf tmp_file_path = BUF_INIT;
351351 if ((err = os_buf_to_tmp_file(source, buf_create_from_str(".h"), &tmp_file_path))) {
......@@ -357,6 +357,10 @@ int parse_h_buf(ParseH *parse_h, Buf *source, const char *libc_include_path) {
357357 clang_argv.append("-isystem");
358358 clang_argv.append(libc_include_path);
359359
360 for (int i = 0; i < args_len; i += 1) {
361 clang_argv.append(args[i]);
362 }
363
360364 err = parse_h_file(parse_h, &clang_argv);
361365
362366 os_delete_file(&tmp_file_path);
src/parseh.hpp+1-1
......@@ -12,6 +12,6 @@
1212#include "all_types.hpp"
1313
1414int parse_h_file(ParseH *parse_h, ZigList<const char *> *clang_argv);
15int parse_h_buf(ParseH *parse_h, Buf *buf, const char *libc_include_path);
15int parse_h_buf(ParseH *parse_h, Buf *source, const char **args, int args_len, const char *libc_include_path);
1616
1717#endif