diff options
| author | ruki <[email protected]> | 2021-03-11 00:43:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-03-11 00:43:27 +0800 |
| commit | dc85d553a8d5ec0214f535d1d4ef584218bb50fa (patch) | |
| tree | 17caa5576ab97d44d38a72c7bd0bba00ae4d4069 /xmake | |
| parent | 035f310d1076abdab7f3f43d925431e1b906b08c (diff) | |
add bpf rule
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/rules/platform/linux/bpf/xmake.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/xmake/rules/platform/linux/bpf/xmake.lua b/xmake/rules/platform/linux/bpf/xmake.lua new file mode 100644 index 000000000..d9bec3fc6 --- /dev/null +++ b/xmake/rules/platform/linux/bpf/xmake.lua @@ -0,0 +1,43 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- add *.bpf.c for linux bpf program +-- @see https://github.com/xmake-io/xmake/issues/1274 +rule("platform.linux.bpf") + set_extensions(".bpf.c") + on_config(function (target) + local headerdir = path.join(target:autogendir(), "rules", "bpf") + target:add("includedirs", headerdir) + end) + before_buildcmd_file(function (target, batchcmds, sourcefile, opt) + local headerfile = path.join(target:autogendir(), "rules", "bpf", (path.filename(sourcefile):gsub("%.bpf%.c", ".skel.h"))) + local objectfile = path.join(target:autogendir(), "rules", "bpf", (path.filename(sourcefile):gsub("%.bpf%.c", ".bpf.o"))) + target:add("includedirs", path.directory(headerfile)) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.bpf %s", sourcefile) + batchcmds:mkdir(path.directory(objectfile)) + batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g"}, defines = "__TARGET_ARCH_x86"}}}) + batchcmds:mkdir(path.directory(headerfile)) + batchcmds:vrunv("llvm-strip", {"-g", objectfile}) + batchcmds:vrunv("bpftool", {"gen", "skeleton", objectfile}, {stdout = headerfile}) + batchcmds:add_depfiles(sourcefile) + batchcmds:set_depmtime(os.mtime(headerfile)) + batchcmds:set_depcache(target:dependfile(headerfile)) + end) + |
