diff options
| author | ruki <[email protected]> | 2015-06-29 15:21:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-29 15:21:41 +0800 |
| commit | ac86a19928d72a69a1ddd4802479393c717352e4 (patch) | |
| tree | 9391f03ed6c6d11bbe62af0a2b96d8e42bd6295d /xmake/scripts | |
| parent | b61940ce9d77a09d86c0e45cf32255f2dd91bc78 (diff) | |
add xmake.lua for package library
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_package.lua | 15 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/base/package.lua | 89 | ||||
| -rw-r--r-- | xmake/scripts/base/rule.lua | 4 |
4 files changed, 91 insertions, 19 deletions
diff --git a/xmake/scripts/action/_package.lua b/xmake/scripts/action/_package.lua index af7cac9bf..6743a140d 100644 --- a/xmake/scripts/action/_package.lua +++ b/xmake/scripts/action/_package.lua @@ -134,6 +134,12 @@ function _package._makeconf(target_name, target) -- save kind configs_target.kind = target.kind + -- save the output directory + configs_target.outputdir = options.outputdir or config.get("buildir") + + -- save the header files + configs_target.headers = target.headers + -- save the target directory configs_arch.targetdir = rule.backupdir(target_name, arch) @@ -143,15 +149,6 @@ function _package._makeconf(target_name, target) -- save the target file configs_arch.targetfile = _package._backup(configs_arch.targetdir, rule.targetfile(target_name, target)) - -- save the output directory - configs_arch.outputdir = options.outputdir or config.get("buildir") - - -- save the header files - configs_arch.headerfiles = rule.headerfiles(target) - - -- save the header directory - configs_arch.headerdir = target.headerdir - -- save the package script configs_target.pkgscript = target.pkgscript if type(configs_target.pkgscript) == "string" and os.isfile(configs_target.pkgscript) then diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index e6121d8a2..a42a71788 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -192,7 +192,7 @@ function makefile._make_target(file, name, target) file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", verbose)) file:write(string.format("\t@xmake l mkdir %s\n", path.directory(targetfile))) file:write(string.format("\t@%s\n", cmd)) - if srcheaders then + if srcheaders and dstheaders then local i = 1 for _, srcheader in ipairs(srcheaders) do local dstheader = dstheaders[i] diff --git a/xmake/scripts/base/package.lua b/xmake/scripts/base/package.lua index 6c02e1821..3af35b0eb 100644 --- a/xmake/scripts/base/package.lua +++ b/xmake/scripts/base/package.lua @@ -37,6 +37,10 @@ function package._done_library(target) -- check assert(target and target.name and target.archs) + -- the output directory + local outputdir = target.outputdir + assert(outputdir) + -- the plat and mode local plat = config.get("plat") local mode = config.get("mode") @@ -46,16 +50,83 @@ function package._done_library(target) for arch, info in pairs(target.archs) do -- check - assert(info.targetdir and info.targetfile and info.outputdir) + assert(info.targetdir and info.targetfile) -- copy the library file to the output directory - local ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), string.format("%s/%s.pkg/lib/%s/%s/%s/%s", info.outputdir, target.name, mode, plat, arch, path.filename(info.targetfile))) - - -- ok? + local ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), string.format("%s/%s.pkg/lib/%s/%s/%s/%s", outputdir, target.name, mode, plat, arch, path.filename(info.targetfile))) if not ok then utils.error(errors) return -1 end + + -- copy the config.h to the output directory + if info.config_h then + local ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.config_h), string.format("%s/%s.pkg/inc/%s/%s", outputdir, target.name, plat, path.filename(info.config_h))) + if not ok then + utils.error(errors) + return -1 + end + end + end + + -- copy headers + if target.headers then + local srcheaders, dstheaders = rule.headerfiles(target, string.format("%s/%s.pkg/inc", outputdir, target.name)) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + local ok, errors = os.cp(srcheader, dstheader) + if not ok then + utils.error(errors) + return -1 + end + end + i = i + 1 + end + end + end + + -- make xmake.lua + local file = io.open(string.format("%s/%s.pkg/xmake.lua", outputdir, target.name), "w") + if file then + + -- the xmake.lua template content + local template = [[ +-- add [targetname] package +add_option("[targetname]") + + -- show menu + set_option_showmenu(true) + + -- set category + set_option_category("package") + + -- set description + set_option_description("The [targetname] package") + + -- add defines to config.h if checking ok + add_option_defines_h_if_ok("$(prefix)_PACKAGE_HAVE_[TARGETNAME]") + + -- add links for checking + add_option_links("[targetname]") + + -- add link directories + add_option_linkdirs("lib/$(mode)/$(plat)/$(arch)") + + -- add c includes for checking + add_option_cincludes("[targetname]/[targetname].h") + + -- add include directories + add_option_includedirs("inc", "inc/$(plat)/$(arch)") +]] + + -- save file + file:write(template:gsub("%[targetname%]", target.name):gsub("%[TARGETNAME%]", target.name:upper())) + + -- exit file + file:close() end -- ok @@ -68,6 +139,10 @@ function package._done_binary(target) -- check assert(target and target.archs) + -- the output directory + local outputdir = target.outputdir + assert(outputdir) + -- the count of architectures local count = 0 for _, _ in pairs(target.archs) do count = count + 1 end @@ -78,13 +153,13 @@ function package._done_binary(target) for arch, info in pairs(target.archs) do -- check - assert(info.targetdir and info.targetfile and info.outputdir) + assert(info.targetdir and info.targetfile) -- copy the binary file to the output directory if count == 1 then - ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), info.outputdir) + ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), outputdir) else - ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), string.format("%s/%s", info.outputdir, rule.filename(path.basename(info.targetfile) .. "_" .. arch, "binary"))) + ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), string.format("%s/%s", outputdir, rule.filename(path.basename(info.targetfile) .. "_" .. arch, "binary"))) end -- ok? diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua index bafc054bc..cff18ed16 100644 --- a/xmake/scripts/base/rule.lua +++ b/xmake/scripts/base/rule.lua @@ -203,7 +203,7 @@ function rule.sourcefiles(target) end -- get the header files from the given target -function rule.headerfiles(target) +function rule.headerfiles(target, headerdir) -- check assert(target) @@ -213,7 +213,7 @@ function rule.headerfiles(target) if not headers then return end -- get the headerdir - local headerdir = target.headerdir or config.get("buildir") + if not headerdir then headerdir = target.headerdir or config.get("buildir") end assert(headerdir) -- get the source pathes and destinate pathes |
