Forráskód Böngészése

libelfin: add package (#4767)

* libelfin: add package

* port to xmake

* limit plat

* fix codegen
star9029 1 éve
szülő
commit
eecec2c597
2 módosított fájl, 99 hozzáadás és 0 törlés
  1. 73 0
      packages/l/libelfin/port/xmake.lua
  2. 26 0
      packages/l/libelfin/xmake.lua

+ 73 - 0
packages/l/libelfin/port/xmake.lua

@@ -0,0 +1,73 @@
+add_requires("python 3.x", {kind = "binary"})
+
+add_rules("mode.debug", "mode.release")
+
+set_languages("c++11")
+
+target("elf++")
+    set_kind("$(kind)")
+    add_files("elf/*.cc")
+    add_headerfiles("elf/elf++.hh", "elf/data.hh", "elf/common.hh", {prefixdir = "libelfin/elf"})
+
+    on_load(function (target)
+        local filename = "elf/to_string.cc"
+        local file = io.open(filename, "w")
+        file:print("// Automatically generated by xmake at " .. os.date("%y-%m-%d"))
+        file:print("// DO NOT EDIT")
+        file:print("")
+        file:print([[#include "data.hh"]])
+        file:print([[#include "to_hex.hh"]])
+        file:print("")
+        file:print("ELFPP_BEGIN_NAMESPACE")
+        file:print("")
+
+        local python = assert(import("lib.detect.find_tool")("python3"), "python not found!")
+        local result = try { function()
+            return os.iorunv(python.program,
+                {"elf/enum-print.py", "-u", "--hex", "--no-type", "--mask", "shf", "--mask", "pf", "-x", "loos", "-x", "hios", "-x", "loproc", "-x", "hiproc"},
+                {stdin = "elf/data.hh"})
+        end }
+        if result then
+            file:print(result)
+        end
+
+        file:print("ELFPP_END_NAMESPACE")
+        file:close()
+        target:add("files", path.join(os.projectdir(), filename))
+    end)
+
+target("dwarf++")
+    set_kind("$(kind)")
+    add_files("dwarf/*.cc")
+    add_headerfiles("dwarf/dwarf++.hh", "dwarf/data.hh", "dwarf/small_vector.hh", {prefixdir = "libelfin/dwarf"})
+
+    on_load(function (target)
+        local filename = "dwarf/to_string.cc"
+        local file = io.open(filename, "w")
+        file:print("// Automatically generated by xmake at " .. os.date("%y-%m-%d"))
+        file:print("// DO NOT EDIT")
+        file:print("")
+        file:print([[#include "internal.hh"]])
+        file:print("")
+        file:print("DWARFPP_BEGIN_NAMESPACE")
+        file:print("")
+
+        local python = assert(import("lib.detect.find_tool")("python3"), "python not found!")
+        local result = try { function() return os.iorunv(python.program, {"elf/enum-print.py"}, {stdin = "dwarf/dwarf++.hh"}) end}
+        if result then
+            file:print(result)
+        end
+
+        result = try { function()
+            return os.iorunv(python.program,
+                {"elf/enum-print.py", "-s", "_", "-u", "--hex", "-x", "hi_user", "-x", "lo_user"},
+                {stdin = "dwarf/data.hh"})
+        end }
+        if result then
+            file:print(result)
+        end
+
+        file:print("DWARFPP_END_NAMESPACE")
+        file:close()
+        target:add("files", path.join(os.projectdir(), filename))
+    end)

+ 26 - 0
packages/l/libelfin/xmake.lua

@@ -0,0 +1,26 @@
+package("libelfin")
+    set_homepage("https://github.com/aclements/libelfin")
+    set_description("C++11 ELF/DWARF parser")
+    set_license("MIT")
+
+    add_urls("https://github.com/aclements/libelfin/archive/e0172767b79b76373044118ef0272b49b02a0894.tar.gz",
+             "https://github.com/aclements/libelfin.git")
+    -- 2024.03.11
+    add_versions("v0.3", "0fb80f8a36b9b2563bd193ace5866972e739af306955e539310dc9dd870aef6c")
+
+    add_deps("python 3.x", {kind = "binary"})
+
+    on_install("!windows and !mingw", function (package)
+        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        import("package.tools.xmake").install(package)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <libelfin/elf/elf++.hh>
+            void test() {
+                int fd = 0;
+                elf::elf ef(elf::create_mmap_loader(fd));
+            }
+        ]]}, {configs = {languages = "c++11"}}))
+    end)