From 02b874db57832a7e7ab9be72bd98467d2d210453 Mon Sep 17 00:00:00 2001 From: starkos Date: Mon, 20 Apr 2009 19:06:48 +0000 Subject: [PATCH] Implemented platform flags for GCC; added "native" platform support --- samples/project/premake4.lua | 4 ++-- src/actions/make/make_cpp.lua | 11 +++++------ src/actions/make/make_solution.lua | 19 ++++++++++++------- src/base/api.lua | 8 +++++--- src/tools/gcc.lua | 18 +++++++++++------- src/tools/ow.lua | 1 + tests/test_configs.lua | 25 ++++++++++++------------- 7 files changed, 48 insertions(+), 38 deletions(-) diff --git a/samples/project/premake4.lua b/samples/project/premake4.lua index 49dff2ae..1f398182 100644 --- a/samples/project/premake4.lua +++ b/samples/project/premake4.lua @@ -1,6 +1,6 @@ solution "PremakeTestbox" configurations { "Debug", "Release" } - platforms { "x32", "xbox360" } + platforms { "native", "x64", "xbox360" } objdir "obj" @@ -27,7 +27,7 @@ solution "PremakeTestbox" include "CppSharedLib" include "CppStaticLib" - if _ACTION ~= "codeblocks" then + if _ACTION ~= "codeblocks" and _ACTION ~= "codelite" then include "CsSharedLib" include "CsConsoleApp" end diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index eda93bb2..e5a9ac6d 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -8,12 +8,15 @@ -- create a shortcut to the compiler interface local cc = premake[_OPTIONS.cc] + -- build a list of supported target platforms that also includes a generic build + local platforms = premake.filterplatforms(prj.solution, cc.platforms) + -- write a quick header _p('# %s project makefile autogenerated by Premake', premake.actions[_ACTION].shortname) -- set up the environment _p('ifndef config') - _p(' config=%s', _MAKE.esc(prj.configurations[1]:lower())) + _p(' config=%s%s', _MAKE.esc(prj.configurations[1]:lower()), cc.platforms[platforms[1]].suffix) _p('endif') _p('') @@ -22,14 +25,10 @@ _p('endif') _p('') - -- build a list of supported target platforms that also includes a generic build - local platforms = premake.filterplatforms(prj.solution, cc.platforms) - table.insert(platforms, 1, "") - -- list the configurations for _, platform in ipairs(platforms) do for cfg in premake.eachconfig(prj, platform) do - _p('ifeq ($(config),%s)', table.concat({ _MAKE.esc(cfg.name:lower()), cfg.platform}, ":")) + _p('ifeq ($(config),%s%s)', _MAKE.esc(cfg.name:lower()), cc.platforms[platform].suffix) _p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory)) _p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name)) _p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir)) diff --git a/src/actions/make/make_solution.lua b/src/actions/make/make_solution.lua index 8c9af4aa..56e525e6 100644 --- a/src/actions/make/make_solution.lua +++ b/src/actions/make/make_solution.lua @@ -8,15 +8,24 @@ -- create a shortcut to the compiler interface local cc = premake[_OPTIONS.cc] + -- build a list of supported target platforms that also includes a generic build + local platforms = premake.filterplatforms(sln, cc.platforms) + -- write a header showing the build options + local cfgpairs = { } + for _, platform in ipairs(platforms) do + for _, cfg in ipairs(sln.configurations) do + table.insert(cfgpairs, cfg .. cc.platforms[platform].suffix) + end + end _p('# %s solution makefile autogenerated by Premake', premake.actions[_ACTION].shortname) _p('# Usage: make [ config=config_name ]') - _p('# Where {config_name} is one of: %s.', table.implode(sln.configurations, '"', '"', ', '):lower()) + _p('# Where {config_name} is one of: %s.', table.implode(cfgpairs, '"', '"', ', '):lower()) _p('') -- set a default configuration _p('ifndef config') - _p(' config=%s', _MAKE.esc(sln.configurations[1]:lower())) + _p(' config=%s%s', _MAKE.esc(sln.configurations[1]:lower()), cc.platforms[platforms[1]].suffix) _p('endif') _p('export config') _p('') @@ -29,10 +38,6 @@ _p('all: $(PROJECTS)') _p('') - -- build a list of supported target platforms that also includes a generic build - local platforms = premake.filterplatforms(sln, cc.platforms) - table.insert(platforms, 1, "") - -- write the project build rules for _, prj in ipairs(sln.projects) do @@ -40,7 +45,7 @@ -- these dependencies change, the project needs to be rebuilt for _, platform in ipairs(platforms) do for cfg in premake.eachconfig(prj, platform) do - _p('ifeq ($(config),%s)', table.concat({ _MAKE.esc(cfg.name:lower()), cfg.platform}, ":")) + _p('ifeq ($(config),%s%s)', _MAKE.esc(cfg.name:lower()), cc.platforms[platform].suffix) _p(' DEPENDENCIES := %s', table.concat(_MAKE.esc(table.extract(premake.getdependencies(cfg), "name")), " ")) _p('endif') end diff --git a/src/base/api.lua b/src/base/api.lua index 697ff83e..14d71a11 100644 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -199,11 +199,13 @@ kind = "list", scope = "solution", allowed = { + "Native", "x32", "x64", - "ppc", - "ppc64", - "xbox360" + "Universal", + "Universal32", + "Universal64", + "Xbox360" } }, diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index ad82fb65..25265eed 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -32,15 +32,17 @@ -- --- Support platforms, mapped to GCC architectures +-- Support platforms, mapped to build configuration suffix -- premake.gcc.platforms = { - x32 = "i386", - x64 = "x64_86", - ppc = "ppc", - ppc64 = "ppc64", + Native = { suffix="", cflags="" }, + x32 = { suffix="32", cflags="-m32" }, + x64 = { suffix="64", cflags="-m64" }, + Universal = { suffix="univ", cflags="-arch i386 -arch x64_64 -arch ppc -arch ppc64" }, + Universal32 = { suffix="univ32", cflags="-arch i386 -arch ppc" }, + Universal64 = { suffix="univ64", cflags="-arch x64_64 -arch ppc64" }, } @@ -60,6 +62,7 @@ if (cfg.kind == "SharedLib" and not os.is("windows")) then table.insert(result, "-fPIC") end + table.insert(result, premake.gcc.platforms[cfg.platform].cflags) return result end @@ -93,7 +96,7 @@ if (os.is("windows") and cfg.kind == "WindowedApp") then table.insert(result, "-mwindows") end - + -- OS X has a bug, see http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html if (not cfg.flags.Symbols) then if (os.is("macosx")) then @@ -102,7 +105,8 @@ table.insert(result, "-s") end end - + + table.insert(result, premake.gcc.platforms[cfg.platform].cflags) return result end diff --git a/src/tools/ow.lua b/src/tools/ow.lua index 279e7501..4f1e8f5b 100644 --- a/src/tools/ow.lua +++ b/src/tools/ow.lua @@ -36,6 +36,7 @@ premake.ow.platforms = { + Native = { suffix="", cflags="" }, } diff --git a/tests/test_configs.lua b/tests/test_configs.lua index 0d9406d9..70a5e26a 100644 --- a/tests/test_configs.lua +++ b/tests/test_configs.lua @@ -34,27 +34,26 @@ end --- --- Make sure that values only get applied to the right configurations. --- - function T.configs.RootValues() - local cfg = premake.getconfig(prj).defines - test.istrue(#cfg == 1 and cfg[1] == "GLOBAL") -- maybe table.compare instead? + local r = premake.getconfig(prj).defines + test.isequal("GLOBAL", table.concat(r,":")) end + function T.configs.ConfigValues() - local cfg = premake.getconfig(prj, "Debug").defines - test.istrue(#cfg == 2 and cfg[1] == "GLOBAL" and cfg[2] == "DEBUG") + local r = premake.getconfig(prj, "Debug").defines + test.isequal("GLOBAL:DEBUG", table.concat(r,":")) end + function T.configs.PlatformValues() - local cfg = premake.getconfig(prj, "Debug", "x32").defines - test.istrue(#cfg == 3 and cfg[1] == "GLOBAL" and cfg[2] == "DEBUG" and cfg[3] == "X86_32") + local r = premake.getconfig(prj, "Debug", "x32").defines + test.isequal("GLOBAL:DEBUG:X86_32", table.concat(r,":")) end - function T.configs.DefaultPlaformNotInSolution() - local cfg = premake.getconfig(prj, "Debug", "xbox360").defines - test.isequal("GLOBAL:DEBUG", table.concat(cfg, ":")) + + function T.configs.PlaformNotInSolution() + local r = premake.getconfig(prj, "Debug", "xbox360").defines + test.isequal("GLOBAL", table.concat(cfg, ":")) end