Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Make GMake target rules configuration dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
starkos committed Jun 22, 2012
1 parent 98cd8a7 commit d80ecd9
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 58 deletions.
1 change: 0 additions & 1 deletion premake4.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


excludes excludes
{ {
"src/premake.lua",
"src/host/lua-5.1.4/src/lua.c", "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/luac.c",
"src/host/lua-5.1.4/src/print.c", "src/host/lua-5.1.4/src/print.c",
Expand Down
27 changes: 27 additions & 0 deletions src/actions/make/_make.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@
end 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. -- Write out raw makefile rules for a configuration.
-- --
Expand Down
100 changes: 44 additions & 56 deletions src/actions/make/make_cpp.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
-- --


function make.cpp.generate(prj) 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) cpp.header(prj)


-- main build rule(s)
_p('.PHONY: clean prebuild prelink')
_p('')

for cfg in project.eachconfig(prj) do for cfg in project.eachconfig(prj) do
cpp.config(cfg) cpp.config(cfg)
end end
Expand All @@ -43,41 +39,19 @@
_p('endif') _p('endif')
_p('') _p('')


-- main build rule(s) -- common build target rules
_p('.PHONY: clean prebuild prelink') _p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
_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
_p('\t@:') _p('\t@:')
_p('') _p('')


-- target build rule
_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)') _p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
_p('\t@echo Linking %s', prj.name) _p('\t@echo Linking %s', prj.name)
_p('\t$(SILENT) $(LINKCMD)') _p('\t$(SILENT) $(LINKCMD)')
_p('\t$(POSTBUILDCMDS)') _p('\t$(POSTBUILDCMDS)')
_p('') _p('')


-- Create destination directories. Can't use $@ for this because it loses the make.mkdirrule("$(TARGETDIR)")
-- escaping, causing issues with spaces and parenthesis make.mkdirrule("$(OBJDIR)")
_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
--]]


-- clean target -- clean target
_p('clean:') _p('clean:')
Expand Down Expand Up @@ -108,8 +82,6 @@


-- include the dependencies, built by GCC (with the -MMD flag) -- include the dependencies, built by GCC (with the -MMD flag)
_p('-include $(OBJECTS:%%.o=%%.d)') _p('-include $(OBJECTS:%%.o=%%.d)')

print("** Warning: GMake C++ project have not been ported yet")
end end




Expand Down Expand Up @@ -180,7 +152,11 @@
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t")) _p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
end end
_p(' endef') _p(' endef')

_p('')

-- write the target building rule
-- cpp.targetrules(cfg)

-- write out config-level makesettings blocks -- write out config-level makesettings blocks
make.settings(cfg, toolset) make.settings(cfg, toolset)


Expand Down Expand Up @@ -209,32 +185,21 @@
onleaf = function(node, depth) onleaf = function(node, depth)
if path.iscppfile(node.abspath) then if path.iscppfile(node.abspath) then
local objectname = project.getfileobject(prj, node.abspath) local objectname = project.getfileobject(prj, node.abspath)
_p('$(OBJDIR)/%s.o: %s', make.esc(objectname), make.esc(node.relpath)) _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
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('') _p('')
--]]

end end





-- --
-- Compile flags -- Compile flags
-- --
Expand Down Expand Up @@ -424,6 +389,29 @@
end 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. -- System specific toolset configuration.
-- --
Expand Down
5 changes: 4 additions & 1 deletion tests/actions/make/cpp/test_file_rules.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
prepare() prepare()
test.capture [[ test.capture [[
$(OBJDIR)/hello.o: src/greetings/hello.cpp $(OBJDIR)/hello.o: src/greetings/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<"
$(OBJDIR)/hello1.o: src/hello.cpp $(OBJDIR)/hello1.o: src/hello.cpp
@echo $(notdir $<)
$(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<"
]] ]]
end end
59 changes: 59 additions & 0 deletions tests/actions/make/cpp/test_target_rules.lua
Original file line number Original file line Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/premake4.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
dofile("actions/make/cpp/test_make_linking.lua") dofile("actions/make/cpp/test_make_linking.lua")
dofile("actions/make/cpp/test_objects.lua") dofile("actions/make/cpp/test_objects.lua")
dofile("actions/make/cpp/test_ps3.lua") dofile("actions/make/cpp/test_ps3.lua")
dofile("actions/make/cpp/test_target_rules.lua")
dofile("actions/make/cpp/test_wiidev.lua") dofile("actions/make/cpp/test_wiidev.lua")


-- Xcode3 tests -- Xcode3 tests
Expand Down

0 comments on commit d80ecd9

Please sign in to comment.