diff --git a/README.md b/README.md index d51836ea13..3833bdc33c 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,13 @@ compromises backward compatibility. ### Debug / Development Build -If you have gcc or clang installed, you can find out what `ZIG_LIBC_DIR` should -be set to (example below). +If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR` should +be set to (example below). `ZIG_LIBC_INCLUDE_DIR` likely can be set to `/usr/include`. ``` mkdir build cd build -cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_DIR=$(dirname $(dirname $(cc -print-file-name=crt1.o))) +cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=/usr/include make make install ./run_tests @@ -84,13 +84,13 @@ make install ### Release / Install Build -Once installed, `ZIG_LIBC_DIR` can be overridden by the `--libc-path` parameter -to the zig binary. +Once installed, `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_INCLUDE_DIR` can be overridden +by the `--libc-lib-dir` and `--libc-include-dir` parameters to the zig binary. ``` mkdir build cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_DIR=path/to/libc/dir +cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_LIB_DIR=/some/path -DZIG_LIBC_INCLUDE_DIR=/some/path make sudo make install ``` diff --git a/src/all_types.hpp b/src/all_types.hpp index 1f87ee128e..f15756ebfd 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1062,9 +1062,8 @@ struct CodeGen { bool strip_debug_symbols; bool have_exported_main; bool link_libc; - Buf *libc_path; - Buf *libc_lib_path; - Buf *libc_include_path; + Buf *libc_lib_dir; + Buf *libc_include_dir; CodeGenBuildType build_type; LLVMTargetMachineRef target_machine; LLVMZigDIFile *dummy_di_file; diff --git a/src/analyze.cpp b/src/analyze.cpp index a0bd943a19..7af8632b96 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -5486,20 +5486,12 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { } void find_libc_path(CodeGen *g) { - if (!g->libc_path || buf_len(g->libc_path) == 0) { - g->libc_path = buf_create_from_str(ZIG_LIBC_DIR); - if (!g->libc_path || buf_len(g->libc_path) == 0) { - // later we can handle this better by reporting an error via the normal mechanism - zig_panic("Unable to determine libc path. You can use `--libc-path`"); - } + // later we can handle this better by reporting an error via the normal mechanism + if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) { + zig_panic("Unable to determine libc lib path. probably need to reconfigure"); } - if (!g->libc_lib_path) { - g->libc_lib_path = buf_alloc(); - os_path_join(g->libc_path, buf_create_from_str("lib"), g->libc_lib_path); - } - if (!g->libc_include_path) { - g->libc_include_path = buf_alloc(); - os_path_join(g->libc_path, buf_create_from_str("include"), g->libc_include_path); + if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) { + zig_panic("Unable to determine libc include path. probably need to reconfigure"); } } diff --git a/src/codegen.cpp b/src/codegen.cpp index ecdc249443..c68632100a 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -33,6 +33,9 @@ CodeGen *codegen_create(Buf *root_source_dir) { g->next_error_index = 1; g->error_value_count = 1; + g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR); + g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR); + return g; } @@ -69,8 +72,12 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) { g->root_out_name = out_name; } -void codegen_set_libc_path(CodeGen *g, Buf *libc_path) { - g->libc_path = libc_path; +void codegen_set_libc_lib_dir(CodeGen *g, Buf *libc_lib_dir) { + g->libc_lib_dir = libc_lib_dir; +} + +void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { + g->libc_include_dir = libc_include_dir; } void codegen_add_lib_dir(CodeGen *g, const char *dir) { @@ -3710,7 +3717,7 @@ static void generate_h_file(CodeGen *g) { static const char *get_libc_file(CodeGen *g, const char *file) { Buf *out_buf = buf_alloc(); - os_path_join(g->libc_lib_path, buf_create_from_str(file), out_buf); + os_path_join(g->libc_lib_dir, buf_create_from_str(file), out_buf); return buf_ptr(out_buf); } diff --git a/src/codegen.hpp b/src/codegen.hpp index eeee2754e2..2682204efe 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -23,7 +23,8 @@ void codegen_set_verbose(CodeGen *codegen, bool verbose); void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); void codegen_set_out_type(CodeGen *codegen, OutType out_type); void codegen_set_out_name(CodeGen *codegen, Buf *out_name); -void codegen_set_libc_path(CodeGen *codegen, Buf *libc_path); +void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); +void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); void codegen_add_lib_dir(CodeGen *codegen, const char *dir); void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); diff --git a/src/config.h.in b/src/config.h.in index 8b78e56238..ffe76ffa23 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -8,7 +8,8 @@ #define ZIG_HEADERS_DIR "@CMAKE_INSTALL_PREFIX@/@C_HEADERS_DEST@" #define ZIG_STD_DIR "@CMAKE_INSTALL_PREFIX@/@ZIG_STD_DEST@" -#define ZIG_LIBC_DIR "@ZIG_LIBC_DIR@" +#define ZIG_LIBC_INCLUDE_DIR "@ZIG_LIBC_INCLUDE_DIR@" +#define ZIG_LIBC_LIB_DIR "@ZIG_LIBC_LIB_DIR@" #cmakedefine ZIG_LLVM_OLD_CXX_ABI diff --git a/src/main.cpp b/src/main.cpp index ec48438bfc..1b671007a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,22 +16,23 @@ static int usage(const char *arg0) { fprintf(stderr, "Usage: %s [command] [options]\n" "Commands:\n" - " build create executable, object, or library from target\n" - " version print version number and exit\n" - " parseh convert a c header file to zig extern declarations\n" + " build create executable, object, or library from target\n" + " version print version number and exit\n" + " parseh convert a c header file to zig extern declarations\n" "Options:\n" - " --release build with optimizations on and debug protection off\n" - " --static output will be statically linked\n" - " --strip exclude debug symbols\n" - " --export [exe|lib|obj] override output type\n" - " --name [name] override output name\n" - " --output [file] override destination path\n" - " --verbose turn on compiler debug output\n" - " --color [auto|off|on] enable or disable colored error messages\n" - " --libc-path [path] set the C compiler data path\n" - " -isystem [dir] add additional search path for other .h files\n" - " -dirafter [dir] same as -isystem but do it last\n" - " --library-path [dir] add a directory to the library search path\n" + " --release build with optimizations on and debug protection off\n" + " --static output will be statically linked\n" + " --strip exclude debug symbols\n" + " --export [exe|lib|obj] override output type\n" + " --name [name] override output name\n" + " --output [file] override destination path\n" + " --verbose turn on compiler debug output\n" + " --color [auto|off|on] enable or disable colored error messages\n" + " --libc-lib-dir [path] set the C compiler data path\n" + " --libc-include-dir [path] set the C compiler data path\n" + " -isystem [dir] add additional search path for other .h files\n" + " -dirafter [dir] same as -isystem but do it last\n" + " --library-path [dir] add a directory to the library search path\n" , arg0); return EXIT_FAILURE; } @@ -55,7 +56,8 @@ int main(int argc, char **argv) { const char *out_name = nullptr; bool verbose = false; ErrColor color = ErrColorAuto; - const char *libc_path = nullptr; + const char *libc_lib_dir = nullptr; + const char *libc_include_dir = nullptr; ZigList clang_argv = {0}; ZigList lib_dirs = {0}; int err; @@ -102,8 +104,10 @@ int main(int argc, char **argv) { } } else if (strcmp(arg, "--name") == 0) { out_name = argv[i]; - } else if (strcmp(arg, "--libc-path") == 0) { - libc_path = argv[i]; + } else if (strcmp(arg, "--libc-lib-dir") == 0) { + libc_lib_dir = argv[i]; + } else if (strcmp(arg, "--libc-include-dir") == 0) { + libc_include_dir = argv[i]; } else if (strcmp(arg, "-isystem") == 0) { clang_argv.append("-isystem"); clang_argv.append(argv[i]); @@ -182,8 +186,10 @@ int main(int argc, char **argv) { codegen_set_out_type(g, out_type); if (out_name) codegen_set_out_name(g, buf_create_from_str(out_name)); - if (libc_path) - codegen_set_libc_path(g, buf_create_from_str(libc_path)); + if (libc_lib_dir) + codegen_set_libc_lib_dir(g, buf_create_from_str(libc_lib_dir)); + if (libc_include_dir) + codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); codegen_set_verbose(g, verbose); codegen_set_errmsg_color(g, color); diff --git a/src/parseh.cpp b/src/parseh.cpp index cf577f0f0a..b8acbbcf48 100644 --- a/src/parseh.cpp +++ b/src/parseh.cpp @@ -1413,7 +1413,7 @@ int parse_h_file(ImportTableEntry *import, ZigList *errors, const ch clang_argv.append(ZIG_HEADERS_DIR); clang_argv.append("-isystem"); - clang_argv.append(buf_ptr(codegen->libc_include_path)); + clang_argv.append(buf_ptr(codegen->libc_include_dir)); for (int i = 0; i < codegen->clang_argv_len; i += 1) { clang_argv.append(codegen->clang_argv[i]);