Make GMake target rules configuration dependent

This commit is contained in:
Jason Perkins 2012-06-22 17:15:17 -04:00
parent 6928b3c7bb
commit 67ba45c1c3
6 changed files with 135 additions and 58 deletions

View File

@ -28,7 +28,6 @@
excludes
{
"src/premake.lua",
"src/host/lua-5.1.4/src/lua.c",
"src/host/lua-5.1.4/src/luac.c",
"src/host/lua-5.1.4/src/print.c",

View File

@ -132,6 +132,33 @@
end
--
-- Rules for file ops based on the shell type. Can't use defines and $@ because
-- it screws up the escaping of spaces and parethesis (anyone know a solution?)
--
function make.copyrule(source, target)
_p('%s: %s', target, source)
_p('\t@echo Copying $(notdir %s)', target)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) cp -fR %s %s', source, target)
_p('else')
_p('\t$(SILENT) copy /Y $(subst /,\\\\,%s) $(subst /,\\\\,%s)', source, target)
_p('endif')
end
function make.mkdirrule(dirname)
_p('%s:', dirname)
_p('\t@echo Creating %s', dirname)
_p('ifeq (posix,$(SHELLTYPE))')
_p('\t$(SILENT) mkdir -p %s', dirname)
_p('else')
_p('\t$(SILENT) mkdir $(subst /,\\\\,%s)', dirname)
_p('endif')
_p('')
end
--
-- Write out raw makefile rules for a configuration.
--

View File

@ -16,16 +16,12 @@
--
function make.cpp.generate(prj)
--[[
-- create a shortcut to the compiler interface
local cc = premake.gettool(prj)
-- build a list of supported target platforms that also includes a generic build
local platforms = premake.filterplatforms(prj.solution, cc.platforms, "Native")
--]]
cpp.header(prj)
-- main build rule(s)
_p('.PHONY: clean prebuild prelink')
_p('')
for cfg in project.eachconfig(prj) do
cpp.config(cfg)
end
@ -43,41 +39,19 @@
_p('endif')
_p('')
-- main build rule(s)
_p('.PHONY: clean prebuild prelink')
_p('')
--[[
if os.is("MacOSX") and prj.kind == "WindowedApp" then
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
else
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
end
-- common build target rules
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
_p('\t@:')
_p('')
-- target build rule
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)')
_p('')
-- Create destination directories. Can't use $@ for this because it loses the
-- escaping, causing issues with spaces and parenthesis
_p('$(TARGETDIR):')
premake.make_mkdirrule("$(TARGETDIR)")
_p('$(OBJDIR):')
premake.make_mkdirrule("$(OBJDIR)")
-- Mac OS X specific targets
if os.is("MacOSX") and prj.kind == "WindowedApp" then
_p('$(dir $(TARGETDIR))PkgInfo:')
_p('$(dir $(TARGETDIR))Info.plist:')
_p('')
end
--]]
make.mkdirrule("$(TARGETDIR)")
make.mkdirrule("$(OBJDIR)")
-- clean target
_p('clean:')
@ -108,8 +82,6 @@
-- include the dependencies, built by GCC (with the -MMD flag)
_p('-include $(OBJECTS:%%.o=%%.d)')
print("** Warning: GMake C++ project have not been ported yet")
end
@ -180,6 +152,10 @@
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
end
_p(' endef')
_p('')
-- write the target building rule
-- cpp.targetrules(cfg)
-- write out config-level makesettings blocks
make.settings(cfg, toolset)
@ -210,31 +186,20 @@
if path.iscppfile(node.abspath) then
local objectname = project.getfileobject(prj, node.abspath)
_p('$(OBJDIR)/%s.o: %s', make.esc(objectname), make.esc(node.relpath))
_p('')
_p('\t@echo $(notdir $<)')
cpp.buildcommand(prj)
elseif path.isresourcefile(node.abspath) then
local objectname = project.getfileobject(prj, node.abspath)
_p('$(OBJDIR)/%s.res: %s', make.esc(objectname), make.esc(node.relpath))
_p('\t@echo $(notdir $<)')
_p('\t$(SILENT) $(RESCOMP) $< -O coff -o "$@" $(RESFLAGS)')
end
end
})
--[[
-- per-file rules
for _, file in ipairs(prj.files) do
if path.iscppfile(file) then
_p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
_p('\t@echo $(notdir $<)')
cpp.buildcommand_old(path.iscfile(file))
elseif (path.getextension(file) == ".rc") then
_p('$(OBJDIR)/%s.res: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
_p('\t@echo $(notdir $<)')
_p('\t$(SILENT) $(RESCOMP) $< -O coff -o "$@" $(RESFLAGS)')
end
end
_p('')
--]]
end
--
-- Compile flags
--
@ -424,6 +389,29 @@
end
--
-- The main build target rules.
--
function cpp.targetrules(cfg)
local macapp = (cfg.system == premake.MACOSX and cfg.kind == premake.WINDOWEDAPP)
if macapp then
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
else
_p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
end
_p('\t@:')
_p('')
if macapp then
_p('$(dir $(TARGETDIR))PkgInfo:')
_p('$(dir $(TARGETDIR))Info.plist:')
_p('')
end
end
--
-- System specific toolset configuration.
--

View File

@ -35,8 +35,11 @@
prepare()
test.capture [[
$(OBJDIR)/hello.o: src/greetings/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<"
$(OBJDIR)/hello1.o: src/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<"
]]
end

View File

@ -0,0 +1,59 @@
--
-- tests/actions/make/cpp/test_target_rules.lua
-- Validate the makefile target building rules.
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
T.make_cpp_target_rules = { }
local suite = T.make_cpp_target_rules
local cpp = premake.make.cpp
local project = premake5.project
--
-- Setup
--
local sln, prj
function suite.setup()
sln, prj = test.createsolution()
end
local function prepare()
local cfg = project.getconfig(prj, "Debug")
cpp.targetrules(cfg)
end
--
-- Check the default, normal format of the rules.
--
function suite.defaultRules()
prepare()
test.capture [[
all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
@:
]]
end
--
-- Check rules for an OS X Cocoa application.
--
function suite.osxWindowedAppRules()
system "MacOSX"
kind "WindowedApp"
prepare()
test.capture [[
all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist
@:
$(dir $(TARGETDIR))PkgInfo:
$(dir $(TARGETDIR))Info.plist:
]]
end

View File

@ -163,6 +163,7 @@
dofile("actions/make/cpp/test_make_linking.lua")
dofile("actions/make/cpp/test_objects.lua")
dofile("actions/make/cpp/test_ps3.lua")
dofile("actions/make/cpp/test_target_rules.lua")
dofile("actions/make/cpp/test_wiidev.lua")
-- Xcode3 tests