diff options
| author | ruki <[email protected]> | 2019-03-15 23:40:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-03-15 16:05:56 +0800 |
| commit | c548ab42140686edaa93b9b952e8f64241bf364c (patch) | |
| tree | 72c2431223727e91032ddd4788a71cc7b74d0439 | |
| parent | 3484d7d8458276c5bb5fd63de0b7aa733acff43c (diff) | |
pass configs to autoconf
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 74 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 45 |
4 files changed, 116 insertions, 26 deletions
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index ebe1b6edc..b58e0c4e8 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -246,9 +246,7 @@ function _add_package_configs(package) package:add("configs", "cflags", {builtin = true, description = "Set the C compiler flags."}) package:add("configs", "cxflags", {builtin = true, description = "Set the C/C++ compiler flags."}) package:add("configs", "cxxflags", {builtin = true, description = "Set the C++ compiler flags."}) - package:add("configs", "ldflags", {builtin = true, description = "Set the binary linker flags."}) - package:add("configs", "arflags", {builtin = true, description = "Set the static library archiver flags."}) - package:add("configs", "shflags", {builtin = true, description = "Set the shared library linker flags."}) + package:add("configs", "asflags", {builtin = true, description = "Set the assembler flags."}) package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", default = "MT", values = {"MT", "MD"}}) end diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 29e147636..c4858fa01 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -22,6 +22,56 @@ -- @file autoconf.lua -- +-- get configs +function _get_configs(package, configs) + local configs = configs or {} + table.insert(configs, "--prefix=" .. package:installdir()) + return configs +end + +-- enter environments +function _enter_envs(package) + + -- get old environments + local envs = {} + envs.CFLAGS = os.getenv("CFLAGS") + envs.CXXFLAGS = os.getenv("CXXFLAGS") + envs.ASFLAGS = os.getenv("ASFLAGS") + + -- set new environments + local cflags = package:config("cflags") + local cxflags = package:config("cxflags") + local cxxflags = package:config("cxxflags") + local asflags = package:config("asflags") + if package:plat() == "windows" then + local vs_runtime = package:config("vs_runtime") + if vs_runtime then + cxflags = (cxflags or "") .. " /" .. vs_runtime .. (package:debug() and "d" or "") + end + end + if cflags then + os.addenv("CFLAGS", cflags) + end + if cxflags then + os.addenv("CFLAGS", cxflags) + os.addenv("CXXFLAGS", cxflags) + end + if cxxflags then + os.addenv("CXXFLAGS", cxxflags) + end + if asflags then + os.addenv("ASFLAGS", asflags) + end + return envs +end + +-- leave environments +function _leave_envs(package, envs) + for k, v in pairs(envs) do + os.setenv(k, v) + end +end + -- install package function install(package, configs) @@ -34,12 +84,9 @@ function install(package, configs) end end - -- inherit require and option configs + -- pass configurations local argv = {} - if not configs or not configs.prefix then - table.insert(argv, "--prefix=" .. package:installdir()) - end - for name, value in pairs(configs) do + for name, value in pairs(_get_configs(package, configs)) do value = tostring(value):trim() if type(name) == "number" then if value ~= "" then @@ -50,15 +97,8 @@ function install(package, configs) end end - -- inherit flags from configs - local flags_prev = {} - for _, name in ipairs({"cflags", "cxxflags", "ldflags"}) do - local flags = package:config(name) or (configs and configs[name] or nil) - if flags then - flags_prev[name] = os.getenv(name:upper()) - os.addenv(name:upper(), flags) - end - end + -- enter environments + local envs = _enter_envs(package) -- do configure os.vrunv("./configure", argv) @@ -67,9 +107,7 @@ function install(package, configs) os.vrun("make -j4") os.vrun("make install") - -- restore flags - for name, flags in pairs(flags_prev) do - os.setenv(name:upper(), flags) - end + -- leave environments + _leave_envs(package, envs) end diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 005525d14..c139d3b6d 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -38,6 +38,23 @@ function _get_configs(package, configs) table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE="/' .. vs_runtime .. '"') end end + local cflags = package:config("cflags") + if cflags then + table.insert(configs, '-DCMAKE_C_FLAGS="' .. cflags .. '"') + end + local cxflags = package:config("cxflags") + if cxflags then + table.insert(configs, '-DCMAKE_C_FLAGS="' .. cxflags .. '"') + table.insert(configs, '-DCMAKE_CXX_FLAGS="' .. cxflags .. '"') + end + local cxxflags = package:config("cxxflags") + if cxxflags then + table.insert(configs, '-DCMAKE_CXX_FLAGS="' .. cxxflags .. '"') + end + local asflags = package:config("asflags") + if asflags then + table.insert(configs, '-DCMAKE_ASM_FLAGS="' .. asflags .. '"') + end return configs end @@ -54,6 +71,8 @@ function install(package, configs) table.insert(argv, "-A") table.insert(argv, "x64") end + + -- pass configurations for name, value in pairs(_get_configs(package, configs)) do value = tostring(value):trim() if type(name) == "number" then diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 042b0c468..cc0fe0d45 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -25,11 +25,40 @@ -- imports import("core.base.option") +-- get configs +function _get_configs(package, configs) + local configs = configs or {} + local cflags = package:config("cflags") + local cxflags = package:config("cxflags") + local cxxflags = package:config("cxxflags") + local asflags = package:config("asflags") + if package:plat() == "windows" then + local vs_runtime = package:config("vs_runtime") + if vs_runtime then + cxflags = (cxflags or "") .. " /" .. vs_runtime .. (package:debug() and "d" or "") + end + end + table.insert(configs, "--mode=" .. (package:debug() and "debug" or "release")) + if cflags then + table.insert(configs, '--cflags="' .. cflags .. '"') + end + if cxflags then + table.insert(configs, '--cxflags="' .. cxflags .. '"') + end + if cxxflags then + table.insert(configs, '--cxxflags="' .. cxxflags .. '"') + end + if asflags then + table.insert(configs, '--asflags="' .. asflags .. '"') + end + return configs +end + -- install package function install(package, configs) -- inherit builtin configs - local argv = {"f", "-y"} + local argv = {"f", "-y"} local names = {"plat", "arch", "ndk", "ndk_sdkver", "vs", "sdk", "bin", "cross", "ld", "sh", "ar", "cc", "cxx", "mm", "mxx"} for _, name in ipairs(names) do local value = get_config(name) @@ -37,11 +66,17 @@ function install(package, configs) table.insert(argv, "--" .. name .. "=" .. tostring(value)) end end - table.insert(argv, "--mode=" .. (package:debug() and "debug" or "release")) - -- inherit require and option configs - for name, value in pairs(table.join(package:configs() or {}, configs or {})) do - table.insert(argv, "--" .. name .. "=" .. tostring(value)) + -- pass configurations + for name, value in pairs(_get_configs(package, configs)) do + value = tostring(value):trim() + if type(name) == "number" then + if value ~= "" then + table.insert(argv, value) + end + else + table.insert(argv, "--" .. name .. "=" .. value) + end end if option.get("verbose") then table.insert(argv, "-v") |
