Skip to content

Commit

Permalink
build: provide bpftool
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido committed May 24, 2022
1 parent e80ea83 commit 29230c9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tools/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
set_xmakever("2.6.1") -- Minimum version to compile BPF source correctly

-- options
option("require-bpftool", {showmenu = true, default = false, description = "require bpftool package"})

--- run `xmake f --require-bpftool=y` to pull bpftool from xmake-repo repo rather than using the system one
if has_config("require-bpftool") then
add_requires("linux-tools", {configs = {bpftool = true}})
add_packages("linux-tools")
end

-- bpftool
local bpftool = path.join("tools", "bpftool")
target("bpftool")
set_kind("phony")
on_config(function (target)
if os.tryrm(bpftool) then
if has_config("require-bpftool") then
local target = path.join(target:pkg("linux-tools"):installdir(), "sbin", "bpftool")
os.ln(target, bpftool)
else
import("lib.detect.find_program")
local sys_bpftool = find_program("bpftool")
if sys_bpftool == nil then
os.raise("cannot find bpftool in system")
end
os.ln(sys_bpftool, bpftool)
end
import("core.base.option")
if option.get("verbose") then
import("core.base.json")
local vers = os.iorunv(bpftool, {"version", "-j"})
print(json.decode(vers))
end
end
end)
before_build(function(target)
import("utils.progress")
progress.show(10, "${color.build.object}providing.bpftool %s", bpftool)
end)
on_clean(function (target)
os.tryrm(bpftool)
end)

0 comments on commit 29230c9

Please sign in to comment.