Skip to content
Browse files

Make GMake target rules configuration dependent

  • Loading branch information...
1 parent 98cd8a7 commit d80ecd966fb247648b36722168dbb71363187677 @starkos starkos committed Jun 22, 2012
View
1 premake4.lua
@@ -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
27 src/actions/make/_make.lua
@@ -133,6 +133,33 @@
--
+-- 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
100 src/actions/make/make_cpp.lua
@@ -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,7 +152,11 @@
_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)
@@ -209,32 +185,21 @@
onleaf = function(node, depth)
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('$(OBJDIR)/%s.o: %s', make.esc(objectname), make.esc(node.relpath))
+ _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
--
@@ -425,6 +390,29 @@
--
+-- 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
5 tests/actions/make/cpp/test_file_rules.lua
@@ -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
59 tests/actions/make/cpp/test_target_rules.lua
@@ -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
1 tests/premake4.lua
@@ -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

0 comments on commit d80ecd9

Please sign in to comment.
Something went wrong with that request. Please try again.