Commit c07b54f6 authored by Rodney Lorrimar's avatar Rodney Lorrimar Committed by Alastair Robertson

build: Allow hard-coding a default kernel headers directory

parent c0dbeaf5
......@@ -28,3 +28,9 @@ target_link_libraries(bpftrace ${binary_dir}/src/cc/frontends/clang/libclang_fro
target_link_libraries(bpftrace ${LIBELF_LIBRARIES})
install(TARGETS bpftrace DESTINATION bin)
set(KERNEL_HEADERS_DIR "" CACHE PATH "Hard-code kernel headers directory")
if (KERNEL_HEADERS_DIR)
MESSAGE(STATUS "Using KERNEL_HEADERS_DIR=${KERNEL_HEADERS_DIR}")
target_compile_definitions(bpftrace PUBLIC KERNEL_HEADERS_DIR="${KERNEL_HEADERS_DIR}")
endif()
......@@ -161,15 +161,21 @@ void ClangParser::parse(ast::Program *program, StructMap &structs)
struct utsname utsname;
uname(&utsname);
const char *kpath_env = ::getenv("BPFTRACE_KERNEL_SOURCE");
std::string kdir = kpath_env ?
std::string(kpath_env) :
const char *kpath_fixed =
#ifdef KERNEL_HEADERS_DIR
kpath_env ? kpath_env : KERNEL_HEADERS_DIR;
#else
kpath_env;
#endif
std::string kdir = kpath_fixed ?
std::string(kpath_fixed) :
std::string("/lib/modules/") + utsname.release;
auto kpath_info = get_kernel_path_info(kdir);
auto kpath = kpath_env ?
auto kpath = kpath_fixed ?
kdir :
kdir + "/" + kpath_info.second;
bool has_kpath_source = kpath_env ? false : kpath_info.first;
bool has_kpath_source = kpath_fixed ? false : kpath_info.first;
std::vector<std::string> kflags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment