summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-06-14 22:43:19 +0800
committerruki <[email protected]>2024-06-14 22:43:19 +0800
commit8c65293ec7f60a3f6e72247b079c2dd458b72461 (patch)
tree7b3372b10a5b77486afb29310318a9f04f3490d9
parentc997b30ff40becdf6219e19e7273c10a16764f23 (diff)
add install/build cmds
-rw-r--r--xmake/plugins/pack/deb/main.lua115
-rw-r--r--xmake/scripts/xpack/deb/debian/control4
-rwxr-xr-xxmake/scripts/xpack/deb/debian/rules60
3 files changed, 162 insertions, 17 deletions
diff --git a/xmake/plugins/pack/deb/main.lua b/xmake/plugins/pack/deb/main.lua
index 91aa55add..bf28be243 100644
--- a/xmake/plugins/pack/deb/main.lua
+++ b/xmake/plugins/pack/deb/main.lua
@@ -39,6 +39,74 @@ function _get_archivefile(package)
return path.absolute(path.join(package:buildir(), package:name() .. "_" .. package:version() .. ".orig.tar.gz"))
end
+-- translate the file path
+function _translate_filepath(package, filepath)
+ return filepath:replace(package:install_rootdir(), "%{buildroot}/%{_exec_prefix}", {plain = true})
+end
+
+-- get install command
+function _get_customcmd(package, installcmds, cmd)
+ local opt = cmd.opt or {}
+ local kind = cmd.kind
+ if kind == "cp" then
+ local srcfiles = os.files(cmd.srcpath)
+ for _, srcfile in ipairs(srcfiles) do
+ -- the destination is directory? append the filename
+ local dstfile = _translate_filepath(package, cmd.dstpath)
+ if #srcfiles > 1 or path.islastsep(dstfile) then
+ if opt.rootdir then
+ dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir))
+ else
+ dstfile = path.join(dstfile, path.filename(srcfile))
+ end
+ end
+ table.insert(installcmds, string.format("install -Dpm0644 \"%s\" \"%s\"", srcfile, dstfile))
+ end
+ elseif kind == "rm" then
+ local filepath = _translate_filepath(package, cmd.filepath)
+ table.insert(installcmds, string.format("rm -f \"%s\"", filepath))
+ elseif kind == "rmdir" then
+ local dir = _translate_filepath(package, cmd.dir)
+ table.insert(installcmds, string.format("rm -rf \"%s\"", dir))
+ elseif kind == "mv" then
+ local srcpath = _translate_filepath(package, cmd.srcpath)
+ local dstpath = _translate_filepath(package, cmd.dstpath)
+ table.insert(installcmds, string.format("mv \"%s\" \"%s\"", srcfile, dstfile))
+ elseif kind == "cd" then
+ local dir = _translate_filepath(package, cmd.dir)
+ table.insert(installcmds, string.format("cd \"%s\"", dir))
+ elseif kind == "mkdir" then
+ local dir = _translate_filepath(package, cmd.dir)
+ table.insert(installcmds, string.format("mkdir -p \"%s\"", dir))
+ elseif cmd.program then
+ local argv = {}
+ for _, arg in ipairs(cmd.argv) do
+ if path.instance_of(arg) then
+ arg = arg:clone():set(_translate_filepath(package, arg:rawstr())):str()
+ elseif path.is_absolute(arg) then
+ arg = _translate_filepath(package, arg)
+ end
+ table.insert(argv, arg)
+ end
+ table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, argv))))
+ end
+end
+
+-- get build commands
+function _get_buildcmds(package, buildcmds, cmds)
+ for _, cmd in ipairs(cmds) do
+ _get_customcmd(package, buildcmds, cmd)
+ end
+end
+
+-- get install commands
+function _get_installcmds(package, installcmds, cmds)
+ for _, cmd in ipairs(cmds) do
+ _get_customcmd(package, installcmds, cmd)
+ end
+end
+
+
-- get specvars
function _get_specvars(package)
local specvars = table.clone(package:specvars())
@@ -49,6 +117,53 @@ function _get_specvars(package)
specvars.PACKAGE_DATE = datestr or ""
local author = package:get("author") or "unknown <[email protected]>"
specvars.PACKAGE_COPYRIGHT = os.date("%Y") .. " " .. author
+ specvars.PACKAGE_INSTALLCMDS = function ()
+ local prefixdir = package:get("prefixdir")
+ package:set("prefixdir", nil)
+ local installcmds = {}
+ _get_installcmds(package, installcmds, batchcmds.get_installcmds(package):cmds())
+ for _, component in table.orderpairs(package:components()) do
+ if component:get("default") ~= false then
+ _get_installcmds(package, installcmds, batchcmds.get_installcmds(component):cmds())
+ end
+ end
+ package:set("prefixdir", prefixdir)
+ return table.concat(installcmds, "\n")
+ end
+ specvars.PACKAGE_BUILDCMDS = function ()
+ local buildcmds = {}
+ _get_buildcmds(package, buildcmds, batchcmds.get_buildcmds(package):cmds())
+ return table.concat(buildcmds, "\n")
+ end
+ specvars.PACKAGE_BUILDREQUIRES = function ()
+ local requires = {}
+ local buildrequires = package:get("buildrequires")
+ if buildrequires then
+ for _, buildrequire in ipairs(buildrequires) do
+ table.insert(requires, " " .. buildrequire .. ",")
+ end
+ else
+ local programs = hashset.new()
+ for _, cmd in ipairs(batchcmds.get_buildcmds(package):cmds()) do
+ local program = cmd.program
+ if program then
+ programs:insert(program)
+ end
+ end
+ local map = {
+ xmake = "xmake",
+ cmake = "cmake",
+ make = "make"
+ }
+ for _, program in programs:keys() do
+ local requirename = map[program]
+ if requirename then
+ table.insert(requires, " " .. requirename .. ",")
+ end
+ end
+ end
+ return table.concat(requires, "\n")
+ end
return specvars
end
diff --git a/xmake/scripts/xpack/deb/debian/control b/xmake/scripts/xpack/deb/debian/control
index 1443bb33e..2d54d9fd6 100644
--- a/xmake/scripts/xpack/deb/debian/control
+++ b/xmake/scripts/xpack/deb/debian/control
@@ -1,8 +1,10 @@
Source: ${PACKAGE_NAME}
-Section: unknown
+Section: devel
Priority: optional
Maintainer: ${PACKAGE_MAINTAINER}
Build-Depends: debhelper-compat (= 13)
+Build-Depends-Arch:
+ ${PACKAGE_BUILDREQUIRES}
Standards-Version: 4.6.0
Homepage: ${PACKAGE_HOMEPAGE}
#Vcs-Browser: https://salsa.debian.org/debian/xmake
diff --git a/xmake/scripts/xpack/deb/debian/rules b/xmake/scripts/xpack/deb/debian/rules
index 59ea751e6..595df8ca4 100755
--- a/xmake/scripts/xpack/deb/debian/rules
+++ b/xmake/scripts/xpack/deb/debian/rules
@@ -1,25 +1,53 @@
#!/usr/bin/make -f
-# See debhelper(7) (uncomment to enable)
-# output every command that modifies files on the build system.
+
#export DH_VERBOSE = 1
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ touch configure-stamp
-# see FEATURE AREAS in dpkg-buildflags(1)
-#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
+build: build-stamp
+build-stamp: configure-stamp
+ dh_testdir
+ ${PACKAGE_BUILDCMDS}
+ touch $@
-# see ENVIRONMENT in dpkg-buildflags(1)
-# package maintainers to append CFLAGS
-#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
-# package maintainers to append LDFLAGS
-#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ dh_clean
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+ ${PACKAGE_INSTALLCMDS}
-%:
- dh $@
+distclean: clean
+uninstall:
+ ${PACKAGE_UNINSTALLCMDS}
-# dh_make generated override targets
-# This is example for Cmake (See https://bugs.debian.org/641051 )
-#override_dh_auto_configure:
-# dh_auto_configure -- \
-# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
+binary-indep: build install
+# We have nothing to do by default.
+# # Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installdocs
+ dh_installexamples
+ dh_installman
+ dh_link
+ dh_strip
+ dh_compress
+ dh_fixperms
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install uninstall configure