diff options
| author | ruki <[email protected]> | 2019-04-17 00:35:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-04-16 21:33:39 +0800 |
| commit | 579503c667ffaab3c78a53dba32d2ec7207c2e65 (patch) | |
| tree | c89f016320ee3b3ca65a5c531380e71f0ffbf2aa | |
| parent | ad7e4fce0945c59cc2a5ed63b1db2085472bcfa3 (diff) | |
improve xmake package
| -rw-r--r-- | xmake/actions/package/main.lua | 58 | ||||
| -rw-r--r-- | xmake/plugins/macro/macros/package.lua | 17 |
2 files changed, 24 insertions, 51 deletions
diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index 743c72482..d90a97001 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -37,22 +37,22 @@ function _package_library(target) local targetname = target:name() -- copy the library file to the output directory - os.cp(target:targetfile(), format("%s/%s.pkg/lib/$(mode)/$(plat)/$(arch)/%s", outputdir, targetname, path.filename(target:targetfile()))) + os.cp(target:targetfile(), format("%s/%s.pkg/$(plat)/$(arch)/$(mode)/lib/%s", outputdir, targetname, path.filename(target:targetfile()))) -- copy the symbol file to the output directory local symbolfile = target:symbolfile() if os.isfile(symbolfile) then - os.cp(symbolfile, format("%s/%s.pkg/lib/$(mode)/$(plat)/$(arch)/%s", outputdir, targetname, path.filename(symbolfile))) + os.cp(symbolfile, format("%s/%s.pkg/$(plat)/$(arch)/$(mode)/lib/%s", outputdir, targetname, path.filename(symbolfile))) end - -- copy the config.h to the output directory + -- copy the config.h to the output directory (deprecated) local configheader = target:configheader() if configheader then - os.cp(configheader, format("%s/%s.pkg/inc/$(plat)/%s", outputdir, targetname, path.filename(configheader))) + os.cp(configheader, format("%s/%s.pkg/$(plat)/$(arch)/$(mode)/include/%s", outputdir, targetname, path.filename(configheader))) end -- copy headers - local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/inc", outputdir, targetname)) + local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/$(plat)/$(arch)/$(mode)/include", outputdir, targetname)) if srcheaders and dstheaders then local i = 1 for _, srcheader in ipairs(srcheaders) do @@ -67,44 +67,16 @@ function _package_library(target) -- make xmake.lua local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w") if file then - - -- the xmake.lua content - local content = [[ --- the [targetname] package -option("[targetname]") - - -- show menu - set_showmenu(true) - - -- set category - set_category("package") - - -- set description - set_description("The [targetname] package") - - -- set language: c99, c++11 - set_languages("c99", "cxx11") - - -- add defines to config.h if checking ok - add_defines_h("$(prefix)_PACKAGE_HAVE_[TARGETNAME]") - - -- add links for checking - add_links("[targetname]") - - -- add link directories - add_linkdirs("lib/$(mode)/$(plat)/$(arch)") - - -- add c includes for checking - add_cincludes("[targetname]/[targetname].h") - - -- add include directories - add_includedirs("inc/$(plat)", "inc") -]] - - -- save file - file:write((content:gsub("%[targetname%]", targetname):gsub("%[TARGETNAME%]", targetname:upper()))) - - -- exit file + file:print("option(\"%s\")", targetname) + file:print(" set_showmenu(true)") + file:print(" set_category(\"package\")") + file:print(" add_links(\"%s\")", target:basename()) + file:write(" add_linkdirs(\"$(plat)/$(arch)/$(mode)/lib\")\n") + file:write(" add_includedirs(\"$(plat)/$(arch)/$(mode)/include\")\n") + local languages = target:get("languages") + if languages then + file:print(" set_languages(\"%s\")", table.concat(table.wrap(languages), "\", \"")) + end file:close() end end diff --git a/xmake/plugins/macro/macros/package.lua b/xmake/plugins/macro/macros/package.lua index 41dc7b61c..e58ca0f61 100644 --- a/xmake/plugins/macro/macros/package.lua +++ b/xmake/plugins/macro/macros/package.lua @@ -85,16 +85,17 @@ function main(argv) for _, target in pairs(project.targets()) do -- get all modes - local modedirs = os.match(format("%s/%s.pkg/lib/*", outputdir, target:name()), true) - for _, modedir in ipairs(modedirs) do - - -- get mode - local mode = path.basename(modedir) + local modes = {} + for _, modedir in ipairs(os.dirs(format("%s/%s.pkg/*/*/*", outputdir, target:name()))) do + table.insert(modes, path.basename(modedir)) + end + print(modes) + for _, mode in ipairs(table.unique(modes)) do -- make lipo arguments local lipoargs = nil for _, arch in ipairs(archs) do - local archfile = format("%s/%s.pkg/lib/%s/%s/%s/%s", outputdir, target:name(), mode, plat, arch:trim(), path.filename(target:targetfile())) + local archfile = format("%s/%s.pkg/%s/%s/%s/lib/%s", outputdir, target:name(), plat, arch:trim(), mode, path.filename(target:targetfile())) if os.isfile(archfile) then lipoargs = format("%s -arch %s %s", lipoargs or "", arch, archfile) end @@ -102,10 +103,10 @@ function main(argv) if lipoargs then -- make full lipo arguments - lipoargs = format("-create %s -output %s/%s.pkg/lib/%s/%s/universal/%s", lipoargs, outputdir, target:name(), mode, plat, path.filename(target:targetfile())) + lipoargs = format("-create %s -output %s/%s.pkg/%s/universal/%s/lib/%s", lipoargs, outputdir, target:name(), plat, mode, path.filename(target:targetfile())) -- make universal directory - os.mkdir(format("%s/%s.pkg/lib/%s/%s/universal", outputdir, target:name(), mode, plat)) + os.mkdir(format("%s/%s.pkg/%s/universal/%s/lib", outputdir, target:name(), plat, mode)) -- package all archs os.execv("xmake", {"l", "lipo", lipoargs}) |
