parent
e4ac3586ab
commit
fd300238ea
3 changed files with 87 additions and 50 deletions
@ -0,0 +1,40 @@ |
||||
function load(package) |
||||
package:add("deps", "libcap", "libelf", "zlib") |
||||
package:addenv("PATH", "sbin") |
||||
end |
||||
|
||||
function install(package) |
||||
|
||||
assert(package:is_plat("linux"), "bpftool: only support for linux!") |
||||
|
||||
local cflags = {} |
||||
local ldflags = {} |
||||
for _, dep in ipairs(package:orderdeps()) do |
||||
local fetchinfo = dep:fetch() |
||||
if fetchinfo then |
||||
for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do |
||||
table.insert(cflags, "-isystem " .. includedir) |
||||
end |
||||
for _, linkdir in ipairs(fetchinfo.linkdirs) do |
||||
table.insert(ldflags, "-L" .. linkdir) |
||||
end |
||||
for _, link in ipairs(fetchinfo.links) do |
||||
table.insert(ldflags, "-l" .. link) |
||||
end |
||||
end |
||||
end |
||||
|
||||
local configs = {} |
||||
table.insert(configs, "EXTRA_CFLAGS=" .. table.concat(cflags, " ")) |
||||
table.insert(configs, "LDFLAGS=" .. table.concat(ldflags, " ")) |
||||
|
||||
os.cd("tools/bpf/bpftool") |
||||
io.replace("Makefile", "prefix ?= /usr/local", "prefix ?= " .. package:installdir(), {plain = true}) |
||||
io.replace("Makefile", "bash_compdir ?= /usr/share", "bash_compdir ?= " .. package:installdir("share"), {plain = true}) |
||||
import("package.tools.make").build(package, configs) |
||||
os.vrunv("make", table.join("install", configs)) |
||||
end |
||||
|
||||
function test(package) |
||||
os.vrun("bpftool --version") |
||||
end |
@ -0,0 +1,31 @@ |
||||
function load(package) |
||||
package:add("deps", "libelf", "zlib") |
||||
end |
||||
|
||||
function install(package) |
||||
os.cd("tools/lib/bpf") |
||||
io.writefile("xmake.lua", [[ |
||||
add_rules("mode.debug", "mode.release") |
||||
add_requires("libelf", "zlib") |
||||
target("bpf") |
||||
set_kind("$(kind)") |
||||
add_files("*.c") |
||||
add_sysincludedirs("../../include", "../../include/uapi") |
||||
add_packages("libelf", "zlib") |
||||
add_headerfiles("*.h", {prefixdir = "bpf"}) |
||||
if is_plat("android") then |
||||
add_defines("__user=", "__force=", "__poll_t=uint32_t") |
||||
end |
||||
]]) |
||||
local configs = {buildir = "xmakebuild"} |
||||
if package:config("shared") then |
||||
configs.kind = "shared" |
||||
elseif package:config("pic") ~= false then |
||||
configs.cxflags = "-fPIC" |
||||
end |
||||
import("package.tools.xmake").install(package, configs) |
||||
end |
||||
|
||||
function test(package) |
||||
assert(package:has_cfuncs("bpf_object__open", {includes = "bpf/libbpf.h"})) |
||||
end |
Loading…
Reference in new issue