--- /dev/null
+# Copyright 2019-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit toolchain-funcs linux-info cmake-utils
+
+DESCRIPTION="High-level tracing language for eBPF"
+HOMEPAGE="https://github.com/iovisor/bpftrace"
+
+if [[ ${PV} =~ 9{4,} ]]; then
+ inherit git-r3
+ EGIT_REPO_URI="https://github.com/iovisor/${PN}"
+ BDEPEND=""
+else
+ MY_PV="${PV//_/}"
+ SRC_URI="https://github.com/iovisor/${PN}/archive/v${MY_PV}.tar.gz -> ${P}.tar.gz"
+ KEYWORDS="~amd64 ~arm64 ~x86"
+ BDEPEND="app-arch/xz-utils "
+fi
+
+LICENSE="Apache-2.0"
+SLOT="0"
+IUSE="test"
+
+COMMON_DEPEND="dev-util/systemtap
+ sys-devel/clang:=
+ dev-libs/libbpf:=
+ >=sys-devel/llvm-3.7.1:=[llvm_targets_BPF(+)]
+ >=dev-util/bcc-0.12.0:=
+ virtual/libelf"
+DEPEND="${COMMON_DEPEND}
+ test? ( dev-cpp/gtest )"
+RDEPEND="${COMMON_DEPEND}"
+BDEPEND+="dev-util/cmake
+ sys-devel/flex
+ sys-devel/bison"
+
+S="${WORKDIR}/${PN}-${MY_PV}"
+QA_DT_NEEDED="/usr/lib.*/libbpftraceresources.so"
+
+PATCHES=(
+ "${FILESDIR}/bpftrace-0.10.0-install-libs.patch"
+ "${FILESDIR}/bpftrace-0.10.0-dont-compress-man.patch"
+)
+
+# lots of fixing needed
+RESTRICT="test"
+
+pkg_pretend() {
+ local CONFIG_CHECK="
+ ~BPF
+ ~BPF_EVENTS
+ ~BPF_JIT
+ ~BPF_SYSCALL
+ ~FTRACE_SYSCALLS
+ ~HAVE_EBPF_JIT
+ "
+
+ check_extra_config
+}
+
+src_prepare() {
+ cmake-utils_src_prepare
+}
+
+src_configure() {
+ local -a mycmakeargs
+ mycmakeargs=(
+ "-DSTATIC_LINKING:BOOL=OFF"
+ "-DBUILD_TESTING:BOOL=OFF"
+ )
+
+ cmake-utils_src_configure
+}
--- /dev/null
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e89a6a9..efa2ff3 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -90,9 +90,10 @@ find_package(FLEX REQUIRED)
+ bison_target(bison_parser src/parser.yy ${CMAKE_BINARY_DIR}/parser.tab.cc VERBOSE)
+ flex_target(flex_lexer src/lexer.l ${CMAKE_BINARY_DIR}/lex.yy.cc)
+ add_flex_bison_dependency(flex_lexer bison_parser)
+-add_library(parser ${BISON_bison_parser_OUTPUTS} ${FLEX_flex_lexer_OUTPUTS})
+-target_compile_options(parser PRIVATE "-w")
+-target_include_directories(parser PUBLIC src src/ast ${CMAKE_BINARY_DIR})
++add_library(bpftraceparser ${BISON_bison_parser_OUTPUTS} ${FLEX_flex_lexer_OUTPUTS})
++target_compile_options(bpftraceparser PRIVATE "-w")
++target_include_directories(bpftraceparser PUBLIC src src/ast ${CMAKE_BINARY_DIR})
++install(TARGETS bpftraceparser LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+ include(CheckSymbolExists)
+ set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt
+index a95c60a..f5c4d67 100644
+--- a/resources/CMakeLists.txt
++++ b/resources/CMakeLists.txt
+@@ -1,6 +1,7 @@
+-add_library(resources headers.cpp)
++add_library(bpftraceresources headers.cpp)
+
+-target_include_directories(resources PUBLIC ../src)
++target_include_directories(bpftraceresources PUBLIC ../src)
++install(TARGETS bpftraceresources LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+ function(embed_headers output)
+ file(WRITE ${output} "#include \"headers.h\"\n\nnamespace bpftrace {\n")
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 4fa0418..4d0c2a9 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -75,7 +75,8 @@ if (ALLOW_UNSAFE_PROBE)
+ target_compile_definitions(bpftrace PRIVATE HAVE_UNSAFE_PROBE)
+ endif(ALLOW_UNSAFE_PROBE)
+
+-target_link_libraries(bpftrace arch ast parser resources)
++target_link_libraries(bpftrace bpftracearch bpftraceast bpftraceparser
++ bpftraceresources)
+
+ target_link_libraries(bpftrace ${LIBBCC_LIBRARIES})
+ if(STATIC_LINKING)
+diff --git a/src/arch/CMakeLists.txt b/src/arch/CMakeLists.txt
+index 7156276..32faeae 100644
+--- a/src/arch/CMakeLists.txt
++++ b/src/arch/CMakeLists.txt
+@@ -1,10 +1,12 @@
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
+- add_library(arch aarch64.cpp)
++ add_library(bpftracearch aarch64.cpp)
+ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64" OR
+ CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
+- add_library(arch ppc64.cpp)
++ add_library(bpftracearch ppc64.cpp)
+ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+- add_library(arch x86_64.cpp)
++ add_library(bpftracearch x86_64.cpp)
+ else()
+ message(FATAL_ERROR "Unsupported architecture: {CMAKE_SYSTEM_PROCESSOR}")
+ endif()
++
++install(TARGETS bpftracearch LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+diff --git a/src/ast/CMakeLists.txt b/src/ast/CMakeLists.txt
+index 0d58cd9..e33d585 100644
+--- a/src/ast/CMakeLists.txt
++++ b/src/ast/CMakeLists.txt
+@@ -1,4 +1,4 @@
+-add_library(ast
++add_library(bpftraceast
+ ast.cpp
+ attachpoint_parser.cpp
+ codegen_llvm.cpp
+@@ -8,16 +8,17 @@ add_library(ast
+ semantic_analyser.cpp
+ )
+
+-target_include_directories(ast PUBLIC ${CMAKE_SOURCE_DIR}/src)
+-target_include_directories(ast PUBLIC ${CMAKE_SOURCE_DIR}/src/ast)
+-target_include_directories(ast PUBLIC ${CMAKE_BINARY_DIR})
+-target_link_libraries(ast arch)
++target_include_directories(bpftraceast PUBLIC ${CMAKE_SOURCE_DIR}/src)
++target_include_directories(bpftraceast PUBLIC ${CMAKE_SOURCE_DIR}/src/ast)
++target_include_directories(bpftraceast PUBLIC ${CMAKE_BINARY_DIR})
++target_link_libraries(bpftraceast bpftracearch)
++install(TARGETS bpftraceast LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+ if (HAVE_KFUNC)
+- target_compile_definitions(ast PRIVATE HAVE_KFUNC)
++ target_compile_definitions(bpftraceast PRIVATE HAVE_KFUNC)
+ endif(HAVE_KFUNC)
+
+-add_dependencies(ast parser)
++add_dependencies(bpftraceast bpftraceparser)
+
+ if (STATIC_LINKING)
+ set(clang_libs
+@@ -41,26 +42,26 @@ if (STATIC_LINKING)
+ if(EMBED_LIBCLANG_ONLY)
+ unlink_transitive_dependency("${CLANG_EXPORTED_TARGETS}" "LLVM")
+ endif()
+- target_link_libraries(ast ${CLANG_EMBEDDED_CMAKE_TARGETS})
++ target_link_libraries(bpftraceast ${CLANG_EMBEDDED_CMAKE_TARGETS})
+ else()
+ list(INSERT clang_libs 0 libclang.a)
+ endif()
+
+ if(EMBED_LLVM)
+- target_link_libraries(ast ${LLVM_EMBEDDED_CMAKE_TARGETS})
++ target_link_libraries(bpftraceast ${LLVM_EMBEDDED_CMAKE_TARGETS})
+ else()
+ llvm_map_components_to_libnames(llvm_libs bpfcodegen ipo irreader mcjit orcjit ${LLVM_TARGETS_TO_BUILD})
+- target_link_libraries(ast ${clang_libs})
+- target_link_libraries(ast ${llvm_libs})
++ target_link_libraries(bpftraceast ${clang_libs})
++ target_link_libraries(bpftraceast ${llvm_libs})
+ endif()
+ else()
+ find_library(found_LLVM LLVM HINTS ${LLVM_LIBRARY_DIRS})
+ if(found_LLVM)
+- target_link_libraries(ast LLVM)
++ target_link_libraries(bpftraceast LLVM)
+ else()
+ llvm_map_components_to_libnames(_llvm_libs bpfcodegen ipo irreader mcjit orcjit ${LLVM_TARGETS_TO_BUILD})
+ llvm_expand_dependencies(llvm_libs ${_llvm_libs})
+- target_link_libraries(ast ${llvm_libs})
++ target_link_libraries(bpftraceast ${llvm_libs})
+ endif()
+- target_link_libraries(ast libclang)
++ target_link_libraries(bpftraceast libclang)
+ endif()
+diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
+index 56bcb4a..3f874f8 100644
+--- a/tests/CMakeLists.txt
++++ b/tests/CMakeLists.txt
+@@ -93,7 +93,8 @@ if(HAVE_BFD_DISASM)
+ endif(STATIC_LINKING)
+ endif(HAVE_BFD_DISASM)
+
+-target_link_libraries(bpftrace_test arch ast parser resources)
++target_link_libraries(bpftrace_test bpftracearch bpftraceast bpftraceparser
++ bpftraceresources)
+
+ target_link_libraries(bpftrace_test ${LIBBCC_LIBRARIES})
+ if (STATIC_LINKING)