authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-02 15:04:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-02 15:04:14-07:00
log7af59c76e40d185ed1a8962c2d5fd0f88680d5a7
treefbd8eeaf799fbea424a546b0ae199ce91a7e70ad
parent5824b15249c8fb42aba5ca347d7dc702a4a00a9f

build: fix libc path finding


8 files changed, 54 insertions(+), 48 deletions(-)

README.md+6-6
......@@ -70,13 +70,13 @@ compromises backward compatibility.
7070
7171### Debug / Development Build
7272
73If you have gcc or clang installed, you can find out what `ZIG_LIBC_DIR` should
74be set to (example below).
73If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR` should
74be set to (example below). `ZIG_LIBC_INCLUDE_DIR` likely can be set to `/usr/include`.
7575
7676```
7777mkdir build
7878cd build
79cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_DIR=$(dirname $(dirname $(cc -print-file-name=crt1.o)))
79cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=/usr/include
8080make
8181make install
8282./run_tests
......@@ -84,13 +84,13 @@ make install
8484
8585### Release / Install Build
8686
87Once installed, `ZIG_LIBC_DIR` can be overridden by the `--libc-path` parameter
88to the zig binary.
87Once installed, `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_INCLUDE_DIR` can be overridden
88by the `--libc-lib-dir` and `--libc-include-dir` parameters to the zig binary.
8989
9090```
9191mkdir build
9292cd build
93cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_DIR=path/to/libc/dir
93cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_LIB_DIR=/some/path -DZIG_LIBC_INCLUDE_DIR=/some/path
9494make
9595sudo make install
9696```
src/all_types.hpp+2-3
......@@ -1062,9 +1062,8 @@ struct CodeGen {
10621062 bool strip_debug_symbols;
10631063 bool have_exported_main;
10641064 bool link_libc;
1065 Buf *libc_path;
1066 Buf *libc_lib_path;
1067 Buf *libc_include_path;
1065 Buf *libc_lib_dir;
1066 Buf *libc_include_dir;
10681067 CodeGenBuildType build_type;
10691068 LLVMTargetMachineRef target_machine;
10701069 LLVMZigDIFile *dummy_di_file;
src/analyze.cpp+5-13
......@@ -5486,20 +5486,12 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
54865486}
54875487
54885488void find_libc_path(CodeGen *g) {
5489 if (!g->libc_path || buf_len(g->libc_path) == 0) {
5490 g->libc_path = buf_create_from_str(ZIG_LIBC_DIR);
5491 if (!g->libc_path || buf_len(g->libc_path) == 0) {
5492 // later we can handle this better by reporting an error via the normal mechanism
5493 zig_panic("Unable to determine libc path. You can use `--libc-path`");
5494 }
5495 }
5496 if (!g->libc_lib_path) {
5497 g->libc_lib_path = buf_alloc();
5498 os_path_join(g->libc_path, buf_create_from_str("lib"), g->libc_lib_path);
5489 // later we can handle this better by reporting an error via the normal mechanism
5490 if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) {
5491 zig_panic("Unable to determine libc lib path. probably need to reconfigure");
54995492 }
5500 if (!g->libc_include_path) {
5501 g->libc_include_path = buf_alloc();
5502 os_path_join(g->libc_path, buf_create_from_str("include"), g->libc_include_path);
5493 if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) {
5494 zig_panic("Unable to determine libc include path. probably need to reconfigure");
55035495 }
55045496}
55055497
src/codegen.cpp+10-3
......@@ -33,6 +33,9 @@ CodeGen *codegen_create(Buf *root_source_dir) {
3333 g->next_error_index = 1;
3434 g->error_value_count = 1;
3535
36 g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR);
37 g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR);
38
3639 return g;
3740}
3841
......@@ -69,8 +72,12 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
6972 g->root_out_name = out_name;
7073}
7174
72void codegen_set_libc_path(CodeGen *g, Buf *libc_path) {
73 g->libc_path = libc_path;
75void codegen_set_libc_lib_dir(CodeGen *g, Buf *libc_lib_dir) {
76 g->libc_lib_dir = libc_lib_dir;
77}
78
79void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) {
80 g->libc_include_dir = libc_include_dir;
7481}
7582
7683void codegen_add_lib_dir(CodeGen *g, const char *dir) {
......@@ -3710,7 +3717,7 @@ static void generate_h_file(CodeGen *g) {
37103717
37113718static const char *get_libc_file(CodeGen *g, const char *file) {
37123719 Buf *out_buf = buf_alloc();
3713 os_path_join(g->libc_lib_path, buf_create_from_str(file), out_buf);
3720 os_path_join(g->libc_lib_dir, buf_create_from_str(file), out_buf);
37143721 return buf_ptr(out_buf);
37153722}
37163723
src/codegen.hpp+2-1
......@@ -23,7 +23,8 @@ void codegen_set_verbose(CodeGen *codegen, bool verbose);
2323void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
2424void codegen_set_out_type(CodeGen *codegen, OutType out_type);
2525void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
26void codegen_set_libc_path(CodeGen *codegen, Buf *libc_path);
26void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir);
27void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir);
2728void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
2829
2930void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code);
src/config.h.in+2-1
......@@ -8,7 +8,8 @@
88
99#define ZIG_HEADERS_DIR "@CMAKE_INSTALL_PREFIX@/@C_HEADERS_DEST@"
1010#define ZIG_STD_DIR "@CMAKE_INSTALL_PREFIX@/@ZIG_STD_DEST@"
11#define ZIG_LIBC_DIR "@ZIG_LIBC_DIR@"
11#define ZIG_LIBC_INCLUDE_DIR "@ZIG_LIBC_INCLUDE_DIR@"
12#define ZIG_LIBC_LIB_DIR "@ZIG_LIBC_LIB_DIR@"
1213
1314#cmakedefine ZIG_LLVM_OLD_CXX_ABI
1415
src/main.cpp+26-20
......@@ -16,22 +16,23 @@
1616static int usage(const char *arg0) {
1717 fprintf(stderr, "Usage: %s [command] [options]\n"
1818 "Commands:\n"
19 " build create executable, object, or library from target\n"
20 " version print version number and exit\n"
21 " parseh convert a c header file to zig extern declarations\n"
19 " build create executable, object, or library from target\n"
20 " version print version number and exit\n"
21 " parseh convert a c header file to zig extern declarations\n"
2222 "Options:\n"
23 " --release build with optimizations on and debug protection off\n"
24 " --static output will be statically linked\n"
25 " --strip exclude debug symbols\n"
26 " --export [exe|lib|obj] override output type\n"
27 " --name [name] override output name\n"
28 " --output [file] override destination path\n"
29 " --verbose turn on compiler debug output\n"
30 " --color [auto|off|on] enable or disable colored error messages\n"
31 " --libc-path [path] set the C compiler data path\n"
32 " -isystem [dir] add additional search path for other .h files\n"
33 " -dirafter [dir] same as -isystem but do it last\n"
34 " --library-path [dir] add a directory to the library search path\n"
23 " --release build with optimizations on and debug protection off\n"
24 " --static output will be statically linked\n"
25 " --strip exclude debug symbols\n"
26 " --export [exe|lib|obj] override output type\n"
27 " --name [name] override output name\n"
28 " --output [file] override destination path\n"
29 " --verbose turn on compiler debug output\n"
30 " --color [auto|off|on] enable or disable colored error messages\n"
31 " --libc-lib-dir [path] set the C compiler data path\n"
32 " --libc-include-dir [path] set the C compiler data path\n"
33 " -isystem [dir] add additional search path for other .h files\n"
34 " -dirafter [dir] same as -isystem but do it last\n"
35 " --library-path [dir] add a directory to the library search path\n"
3536 , arg0);
3637 return EXIT_FAILURE;
3738}
......@@ -55,7 +56,8 @@ int main(int argc, char **argv) {
5556 const char *out_name = nullptr;
5657 bool verbose = false;
5758 ErrColor color = ErrColorAuto;
58 const char *libc_path = nullptr;
59 const char *libc_lib_dir = nullptr;
60 const char *libc_include_dir = nullptr;
5961 ZigList<const char *> clang_argv = {0};
6062 ZigList<const char *> lib_dirs = {0};
6163 int err;
......@@ -102,8 +104,10 @@ int main(int argc, char **argv) {
102104 }
103105 } else if (strcmp(arg, "--name") == 0) {
104106 out_name = argv[i];
105 } else if (strcmp(arg, "--libc-path") == 0) {
106 libc_path = argv[i];
107 } else if (strcmp(arg, "--libc-lib-dir") == 0) {
108 libc_lib_dir = argv[i];
109 } else if (strcmp(arg, "--libc-include-dir") == 0) {
110 libc_include_dir = argv[i];
107111 } else if (strcmp(arg, "-isystem") == 0) {
108112 clang_argv.append("-isystem");
109113 clang_argv.append(argv[i]);
......@@ -182,8 +186,10 @@ int main(int argc, char **argv) {
182186 codegen_set_out_type(g, out_type);
183187 if (out_name)
184188 codegen_set_out_name(g, buf_create_from_str(out_name));
185 if (libc_path)
186 codegen_set_libc_path(g, buf_create_from_str(libc_path));
189 if (libc_lib_dir)
190 codegen_set_libc_lib_dir(g, buf_create_from_str(libc_lib_dir));
191 if (libc_include_dir)
192 codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir));
187193 codegen_set_verbose(g, verbose);
188194 codegen_set_errmsg_color(g, color);
189195
src/parseh.cpp+1-1
......@@ -1413,7 +1413,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
14131413 clang_argv.append(ZIG_HEADERS_DIR);
14141414
14151415 clang_argv.append("-isystem");
1416 clang_argv.append(buf_ptr(codegen->libc_include_path));
1416 clang_argv.append(buf_ptr(codegen->libc_include_dir));
14171417
14181418 for (int i = 0; i < codegen->clang_argv_len; i += 1) {
14191419 clang_argv.append(codegen->clang_argv[i]);