2014-12-08 16:47:55 +00:00
|
|
|
--
|
2009-04-11 11:33:32 +00:00
|
|
|
-- make_cpp.lua
|
|
|
|
-- Generate a C/C++ project makefile.
|
2014-12-08 17:44:51 +00:00
|
|
|
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
|
2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
|
2014-12-08 17:44:51 +00:00
|
|
|
local p = premake
|
|
|
|
|
|
|
|
p.make.cpp = {}
|
|
|
|
|
|
|
|
local make = p.make
|
|
|
|
local cpp = p.make.cpp
|
|
|
|
local project = p.project
|
|
|
|
local config = p.config
|
|
|
|
local fileconfig = p.fileconfig
|
2012-04-30 20:42:03 +00:00
|
|
|
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
---
|
2017-04-25 05:44:13 +00:00
|
|
|
-- Add namespace for element definition lists for p.callarray()
|
2013-08-11 18:22:24 +00:00
|
|
|
---
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
cpp.elements = {}
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
--
|
|
|
|
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
|
|
|
|
--
|
2012-05-08 22:08:42 +00:00
|
|
|
|
2015-07-27 13:14:32 +00:00
|
|
|
cpp.elements.makefile = function(prj)
|
|
|
|
return {
|
|
|
|
make.header,
|
|
|
|
make.phonyRules,
|
|
|
|
make.cppConfigs,
|
|
|
|
make.cppObjects,
|
|
|
|
make.shellType,
|
|
|
|
make.cppTargetRules,
|
|
|
|
make.cppCleanRules,
|
|
|
|
make.preBuildRules,
|
|
|
|
make.preLinkRules,
|
|
|
|
make.pchRules,
|
|
|
|
make.cppFileRules,
|
|
|
|
make.cppDependencies,
|
2015-12-18 18:46:45 +00:00
|
|
|
}
|
2015-07-27 13:14:32 +00:00
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.cpp.generate(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.eol("\n")
|
|
|
|
p.callArray(cpp.elements.makefile, prj)
|
2012-04-30 20:42:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-05-18 00:41:28 +00:00
|
|
|
--
|
|
|
|
-- Write out the settings for a particular configuration.
|
|
|
|
--
|
|
|
|
|
2015-07-27 13:14:32 +00:00
|
|
|
cpp.elements.configuration = function(cfg)
|
|
|
|
return {
|
|
|
|
make.cppTools,
|
|
|
|
make.target,
|
|
|
|
make.objdir,
|
|
|
|
make.pch,
|
|
|
|
make.defines,
|
|
|
|
make.includes,
|
|
|
|
make.forceInclude,
|
|
|
|
make.cppFlags,
|
|
|
|
make.cFlags,
|
|
|
|
make.cxxFlags,
|
|
|
|
make.resFlags,
|
|
|
|
make.libs,
|
|
|
|
make.ldDeps,
|
|
|
|
make.ldFlags,
|
|
|
|
make.linkCmd,
|
2015-12-18 18:46:45 +00:00
|
|
|
make.exePaths,
|
2015-07-27 13:14:32 +00:00
|
|
|
make.preBuildCmds,
|
|
|
|
make.preLinkCmds,
|
|
|
|
make.postBuildCmds,
|
|
|
|
make.cppAllRules,
|
|
|
|
make.settings,
|
2015-12-18 18:46:45 +00:00
|
|
|
}
|
2015-07-27 13:14:32 +00:00
|
|
|
end
|
2013-08-11 18:22:24 +00:00
|
|
|
|
|
|
|
function make.cppConfigs(prj)
|
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
-- identify the toolset used by this configurations (would be nicer if
|
|
|
|
-- this were computed and stored with the configuration up front)
|
2012-05-18 00:41:28 +00:00
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local toolset = p.tools[_OPTIONS.cc or cfg.toolset or "gcc"]
|
2013-08-11 18:22:24 +00:00
|
|
|
if not toolset then
|
2015-07-22 17:21:54 +00:00
|
|
|
error("Invalid toolset '" .. cfg.toolset .. "'")
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
2012-05-18 00:41:28 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
_x('ifeq ($(config),%s)', cfg.shortname)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.callArray(cpp.elements.configuration, cfg, toolset)
|
2013-08-11 18:22:24 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2012-05-18 00:41:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-12-18 18:46:45 +00:00
|
|
|
function make.exePaths(cfg)
|
|
|
|
local dirs = project.getrelative(cfg.project, cfg.bindirs)
|
|
|
|
if #dirs > 0 then
|
|
|
|
_p(' EXECUTABLE_PATHS = "%s"', table.concat(dirs, ":"))
|
|
|
|
_p(' EXE_PATHS = export PATH=$(EXECUTABLE_PATHS):$$PATH;')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-14 19:55:46 +00:00
|
|
|
--
|
|
|
|
-- Build command for a single file.
|
|
|
|
--
|
|
|
|
|
2013-05-02 12:36:11 +00:00
|
|
|
function cpp.buildcommand(prj, objext, node)
|
|
|
|
local iscfile = node and path.iscfile(node.abspath) or false
|
|
|
|
local flags = iif(prj.language == "C" or iscfile, '$(CC) $(ALL_CFLAGS)', '$(CXX) $(ALL_CXXFLAGS)')
|
2014-12-08 16:47:55 +00:00
|
|
|
_p('\t$(SILENT) %s $(FORCE_INCLUDE) -o "$@" -MF "$(@:%%.%s=%%.d)" -c "$<"', flags, objext)
|
2012-06-14 19:55:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-19 19:58:16 +00:00
|
|
|
--
|
|
|
|
-- Output the list of file building rules.
|
|
|
|
--
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.cppFileRules(prj)
|
2012-06-19 19:58:16 +00:00
|
|
|
local tr = project.getsourcetree(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.tree.traverse(tr, {
|
2012-06-19 19:58:16 +00:00
|
|
|
onleaf = function(node, depth)
|
2012-06-29 13:05:20 +00:00
|
|
|
-- check to see if this file has custom rules
|
|
|
|
local rules
|
|
|
|
for cfg in project.eachconfig(prj) do
|
2013-07-12 15:07:26 +00:00
|
|
|
local filecfg = fileconfig.getconfig(node, cfg)
|
|
|
|
if fileconfig.hasCustomBuildRule(filecfg) then
|
2012-06-29 13:05:20 +00:00
|
|
|
rules = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if it has custom rules, need to break them out
|
|
|
|
-- into individual configurations
|
|
|
|
if rules then
|
2013-08-11 18:22:24 +00:00
|
|
|
cpp.customFileRules(prj, node)
|
2012-06-29 13:05:20 +00:00
|
|
|
else
|
2013-08-11 18:22:24 +00:00
|
|
|
cpp.standardFileRules(prj, node)
|
2012-06-19 19:58:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function cpp.standardFileRules(prj, node)
|
2012-06-29 13:05:20 +00:00
|
|
|
-- C/C++ file
|
|
|
|
if path.iscppfile(node.abspath) then
|
2013-06-21 21:32:33 +00:00
|
|
|
_x('$(OBJDIR)/%s.o: %s', node.objname, node.relpath)
|
2012-06-29 13:05:20 +00:00
|
|
|
_p('\t@echo $(notdir $<)')
|
2017-01-05 14:33:51 +00:00
|
|
|
make.mkdir('$(OBJDIR)')
|
2013-05-02 12:36:11 +00:00
|
|
|
cpp.buildcommand(prj, "o", node)
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-29 13:05:20 +00:00
|
|
|
-- resource file
|
|
|
|
elseif path.isresourcefile(node.abspath) then
|
2013-06-21 21:32:33 +00:00
|
|
|
_x('$(OBJDIR)/%s.res: %s', node.objname, node.relpath)
|
2012-06-29 13:05:20 +00:00
|
|
|
_p('\t@echo $(notdir $<)')
|
2017-01-05 14:33:51 +00:00
|
|
|
make.mkdir('$(OBJDIR)')
|
2013-01-23 16:50:54 +00:00
|
|
|
_p('\t$(SILENT) $(RESCOMP) $< -O coff -o "$@" $(ALL_RESFLAGS)')
|
2012-06-29 13:05:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function cpp.customFileRules(prj, node)
|
2012-06-29 13:05:20 +00:00
|
|
|
for cfg in project.eachconfig(prj) do
|
2013-07-12 15:07:26 +00:00
|
|
|
local filecfg = fileconfig.getconfig(node, cfg)
|
2012-07-04 18:13:01 +00:00
|
|
|
if filecfg then
|
2013-05-22 15:15:48 +00:00
|
|
|
_x('ifeq ($(config),%s)', cfg.shortname)
|
2013-04-09 19:12:04 +00:00
|
|
|
|
|
|
|
local output = project.getrelative(prj, filecfg.buildoutputs[1])
|
2014-09-26 13:24:23 +00:00
|
|
|
local dependencies = filecfg.relpath
|
|
|
|
if filecfg.buildinputs and #filecfg.buildinputs > 0 then
|
|
|
|
local inputs = project.getrelative(prj, filecfg.buildinputs)
|
2014-12-08 17:44:51 +00:00
|
|
|
dependencies = dependencies .. " " .. table.concat(p.esc(inputs), " ")
|
2014-09-26 13:24:23 +00:00
|
|
|
end
|
2014-12-08 17:44:51 +00:00
|
|
|
_p('%s: %s', output, dependencies)
|
2013-04-09 19:12:04 +00:00
|
|
|
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
|
2014-11-29 19:51:49 +00:00
|
|
|
|
2017-04-18 16:37:29 +00:00
|
|
|
local cmds = os.translateCommandsAndPaths(filecfg.buildcommands, cfg.project.basedir, cfg.project.location)
|
2014-11-29 19:51:49 +00:00
|
|
|
for _, cmd in ipairs(cmds) do
|
2015-12-18 18:46:45 +00:00
|
|
|
if cfg.bindirs and #cfg.bindirs > 0 then
|
|
|
|
_p('\t$(SILENT) $(EXE_PATHS) %s', cmd)
|
|
|
|
else
|
|
|
|
_p('\t$(SILENT) %s', cmd)
|
|
|
|
end
|
2012-07-04 18:13:01 +00:00
|
|
|
end
|
|
|
|
_p('endif')
|
2012-06-29 13:05:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-19 19:58:16 +00:00
|
|
|
|
2012-06-15 22:42:10 +00:00
|
|
|
--
|
|
|
|
-- List the objects file for the project, and each configuration.
|
|
|
|
--
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.cppObjects(prj)
|
2012-06-22 13:27:03 +00:00
|
|
|
-- create lists for intermediate files, at the project level and
|
|
|
|
-- for each configuration
|
2014-09-27 15:30:42 +00:00
|
|
|
local root = { objects={}, resources={}, customfiles={} }
|
2013-01-23 16:50:54 +00:00
|
|
|
local configs = {}
|
2012-06-15 22:42:10 +00:00
|
|
|
for cfg in project.eachconfig(prj) do
|
2014-09-27 15:30:42 +00:00
|
|
|
configs[cfg] = { objects={}, resources={}, customfiles={} }
|
2012-06-15 22:42:10 +00:00
|
|
|
end
|
2012-06-22 13:27:03 +00:00
|
|
|
|
|
|
|
-- now walk the list of files in the project
|
2012-06-15 22:42:10 +00:00
|
|
|
local tr = project.getsourcetree(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.tree.traverse(tr, {
|
2012-06-15 22:42:10 +00:00
|
|
|
onleaf = function(node, depth)
|
2012-06-29 13:05:20 +00:00
|
|
|
-- figure out what configurations contain this file, and
|
|
|
|
-- if it uses custom build rules
|
2012-07-04 16:52:25 +00:00
|
|
|
local incfg = {}
|
2012-06-29 13:05:20 +00:00
|
|
|
local inall = true
|
|
|
|
local custom = false
|
2012-06-15 22:42:10 +00:00
|
|
|
for cfg in project.eachconfig(prj) do
|
2013-07-12 15:07:26 +00:00
|
|
|
local filecfg = fileconfig.getconfig(node, cfg)
|
2013-02-07 15:58:31 +00:00
|
|
|
if filecfg and not filecfg.flags.ExcludeFromBuild then
|
2012-06-29 13:05:20 +00:00
|
|
|
incfg[cfg] = filecfg
|
2013-07-12 15:07:26 +00:00
|
|
|
custom = fileconfig.hasCustomBuildRule(filecfg)
|
2012-06-29 13:05:20 +00:00
|
|
|
else
|
|
|
|
inall = false
|
2012-06-15 22:42:10 +00:00
|
|
|
end
|
|
|
|
end
|
2012-06-22 13:27:03 +00:00
|
|
|
|
2012-06-29 13:05:20 +00:00
|
|
|
if not custom then
|
|
|
|
-- identify the file type
|
|
|
|
local kind
|
|
|
|
if path.iscppfile(node.abspath) then
|
|
|
|
kind = "objects"
|
|
|
|
elseif path.isresourcefile(node.abspath) then
|
|
|
|
kind = "resources"
|
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-29 13:05:20 +00:00
|
|
|
-- skip files that aren't compiled
|
|
|
|
if not custom and not kind then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- assign a unique object file name to avoid collisions
|
2013-06-21 21:32:33 +00:00
|
|
|
objectname = "$(OBJDIR)/" .. node.objname .. iif(kind == "objects", ".o", ".res")
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-29 13:05:20 +00:00
|
|
|
-- if this file exists in all configurations, write it to
|
|
|
|
-- the project's list of files, else add to specific cfgs
|
|
|
|
if inall then
|
|
|
|
table.insert(root[kind], objectname)
|
|
|
|
else
|
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
if incfg[cfg] then
|
|
|
|
table.insert(configs[cfg][kind], objectname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-15 22:42:10 +00:00
|
|
|
else
|
|
|
|
for cfg in project.eachconfig(prj) do
|
2012-06-29 13:05:20 +00:00
|
|
|
local filecfg = incfg[cfg]
|
2013-01-23 16:50:54 +00:00
|
|
|
if filecfg then
|
2013-04-09 19:12:04 +00:00
|
|
|
local output = project.getrelative(prj, filecfg.buildoutputs[1])
|
2016-11-21 20:07:49 +00:00
|
|
|
if path.isobjectfile(output) and (filecfg.linkbuildoutputs == true or filecfg.linkbuildoutputs == nil) then
|
2012-06-29 13:05:20 +00:00
|
|
|
table.insert(configs[cfg].objects, output)
|
2014-09-27 15:30:42 +00:00
|
|
|
else
|
|
|
|
table.insert(configs[cfg].customfiles, output)
|
2012-06-29 13:05:20 +00:00
|
|
|
end
|
2012-06-15 22:42:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-15 22:42:10 +00:00
|
|
|
end
|
|
|
|
})
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-22 13:27:03 +00:00
|
|
|
-- now I can write out the lists, project level first...
|
2012-06-29 13:05:20 +00:00
|
|
|
function listobjects(var, list)
|
2012-06-22 13:27:03 +00:00
|
|
|
_p('%s \\', var)
|
|
|
|
for _, objectname in ipairs(list) do
|
2013-05-22 15:15:48 +00:00
|
|
|
_x('\t%s \\', objectname)
|
2012-06-22 13:27:03 +00:00
|
|
|
end
|
|
|
|
_p('')
|
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-22 13:27:03 +00:00
|
|
|
listobjects('OBJECTS :=', root.objects, 'o')
|
|
|
|
listobjects('RESOURCES :=', root.resources, 'res')
|
2014-09-27 15:30:42 +00:00
|
|
|
listobjects('CUSTOMFILES :=', root.customfiles)
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-22 13:27:03 +00:00
|
|
|
-- ...then individual configurations, as needed
|
2012-06-15 22:42:10 +00:00
|
|
|
for cfg in project.eachconfig(prj) do
|
2012-06-22 13:27:03 +00:00
|
|
|
local files = configs[cfg]
|
2014-09-27 15:30:42 +00:00
|
|
|
if #files.objects > 0 or #files.resources > 0 or #files.customfiles > 0 then
|
2013-05-22 15:15:48 +00:00
|
|
|
_x('ifeq ($(config),%s)', cfg.shortname)
|
2012-06-22 13:27:03 +00:00
|
|
|
if #files.objects > 0 then
|
2012-06-29 13:05:20 +00:00
|
|
|
listobjects(' OBJECTS +=', files.objects)
|
2012-06-22 13:27:03 +00:00
|
|
|
end
|
|
|
|
if #files.resources > 0 then
|
2012-06-29 13:05:20 +00:00
|
|
|
listobjects(' RESOURCES +=', files.resources)
|
2012-06-15 22:42:10 +00:00
|
|
|
end
|
2014-09-27 15:30:42 +00:00
|
|
|
if #files.customfiles > 0 then
|
|
|
|
listobjects(' CUSTOMFILES +=', files.customfiles)
|
|
|
|
end
|
2012-06-15 22:42:10 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
---------------------------------------------------------------------------
|
2012-06-12 19:57:45 +00:00
|
|
|
--
|
2013-08-11 18:22:24 +00:00
|
|
|
-- Handlers for individual makefile elements
|
2012-06-12 19:57:45 +00:00
|
|
|
--
|
2013-08-11 18:22:24 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function make.cFlags(cfg, toolset)
|
2014-11-19 17:29:19 +00:00
|
|
|
_p(' ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS)%s', make.list(table.join(toolset.getcflags(cfg), cfg.buildoptions)))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cppAllRules(cfg, toolset)
|
2017-04-25 05:44:13 +00:00
|
|
|
if cfg.system == p.MACOSX and cfg.kind == p.WINDOWEDAPP then
|
2017-01-05 11:43:10 +00:00
|
|
|
_p('all: prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
|
2013-08-11 18:22:24 +00:00
|
|
|
_p('\t@:')
|
|
|
|
_p('')
|
|
|
|
_p('$(dir $(TARGETDIR))PkgInfo:')
|
|
|
|
_p('$(dir $(TARGETDIR))Info.plist:')
|
|
|
|
else
|
2017-01-05 11:43:10 +00:00
|
|
|
_p('all: prebuild prelink $(TARGET)')
|
2013-08-11 18:22:24 +00:00
|
|
|
_p('\t@:')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cppFlags(cfg, toolset)
|
2013-10-03 14:47:14 +00:00
|
|
|
_p(' ALL_CPPFLAGS += $(CPPFLAGS)%s $(DEFINES) $(INCLUDES)', make.list(toolset.getcppflags(cfg)))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
2012-06-12 19:57:45 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
|
|
|
|
function make.cxxFlags(cfg, toolset)
|
2016-11-07 08:22:03 +00:00
|
|
|
_p(' ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS)%s', make.list(table.join(toolset.getcxxflags(cfg), cfg.buildoptions)))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cppCleanRules(prj)
|
|
|
|
_p('clean:')
|
|
|
|
_p('\t@echo Cleaning %s', prj.name)
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_p('\t$(SILENT) rm -f $(TARGET)')
|
|
|
|
_p('\t$(SILENT) rm -rf $(OBJDIR)')
|
|
|
|
_p('else')
|
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGET)) del $(subst /,\\\\,$(TARGET))')
|
|
|
|
_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cppDependencies(prj)
|
|
|
|
-- include the dependencies, built by GCC (with the -MMD flag)
|
|
|
|
_p('-include $(OBJECTS:%%.o=%%.d)')
|
|
|
|
_p('ifneq (,$(PCH))')
|
|
|
|
_p(' -include $(OBJDIR)/$(notdir $(PCH)).d')
|
|
|
|
_p('endif')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cppTargetRules(prj)
|
2015-09-16 05:16:20 +00:00
|
|
|
_p('$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES)')
|
2013-08-11 18:22:24 +00:00
|
|
|
_p('\t@echo Linking %s', prj.name)
|
2017-01-05 14:33:51 +00:00
|
|
|
make.mkdir('$(TARGETDIR)')
|
2013-08-11 18:22:24 +00:00
|
|
|
_p('\t$(SILENT) $(LINKCMD)')
|
|
|
|
_p('\t$(POSTBUILDCMDS)')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.cppTools(cfg, toolset)
|
|
|
|
local tool = toolset.gettoolname(cfg, "cc")
|
|
|
|
if tool then
|
2015-06-06 04:20:01 +00:00
|
|
|
_p(' ifeq ($(origin CC), default)')
|
|
|
|
_p(' CC = %s', tool)
|
|
|
|
_p(' endif' )
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
tool = toolset.gettoolname(cfg, "cxx")
|
|
|
|
if tool then
|
2015-06-06 04:20:01 +00:00
|
|
|
_p(' ifeq ($(origin CXX), default)')
|
|
|
|
_p(' CXX = %s', tool)
|
|
|
|
_p(' endif' )
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
tool = toolset.gettoolname(cfg, "ar")
|
|
|
|
if tool then
|
2015-06-06 04:20:01 +00:00
|
|
|
_p(' ifeq ($(origin AR), default)')
|
|
|
|
_p(' AR = %s', tool)
|
|
|
|
_p(' endif' )
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
2013-09-27 00:52:06 +00:00
|
|
|
|
|
|
|
tool = toolset.gettoolname(cfg, "rc")
|
|
|
|
if tool then
|
|
|
|
_p(' RESCOMP = %s', tool)
|
|
|
|
end
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.defines(cfg, toolset)
|
2016-01-18 19:11:50 +00:00
|
|
|
_p(' DEFINES +=%s', make.list(table.join(toolset.getdefines(cfg.defines, cfg), toolset.getundefines(cfg.undefines))))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-13 14:56:01 +00:00
|
|
|
function make.forceInclude(cfg, toolset)
|
2013-08-11 18:22:24 +00:00
|
|
|
local includes = toolset.getforceincludes(cfg)
|
2013-08-13 14:56:01 +00:00
|
|
|
if not cfg.flags.NoPCH and cfg.pchheader then
|
2016-11-02 05:27:57 +00:00
|
|
|
table.insert(includes, 1, "-include $(OBJDIR)/$(notdir $(PCH))")
|
2013-08-13 14:56:01 +00:00
|
|
|
end
|
2013-08-11 18:22:24 +00:00
|
|
|
_x(' FORCE_INCLUDE +=%s', make.list(includes))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.includes(cfg, toolset)
|
2015-10-10 17:24:19 +00:00
|
|
|
local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs)
|
2013-08-11 18:22:24 +00:00
|
|
|
_p(' INCLUDES +=%s', make.list(includes))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.ldDeps(cfg, toolset)
|
|
|
|
local deps = config.getlinks(cfg, "siblings", "fullpath")
|
2017-04-25 05:44:13 +00:00
|
|
|
_p(' LDDEPS +=%s', make.list(p.esc(deps)))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.ldFlags(cfg, toolset)
|
2016-08-17 15:48:41 +00:00
|
|
|
local flags = table.join(toolset.getLibraryDirectories(cfg), toolset.getrunpathdirs(cfg, cfg.runpathdirs), toolset.getldflags(cfg), cfg.linkoptions)
|
2014-05-24 00:10:34 +00:00
|
|
|
_p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(flags))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.libs(cfg, toolset)
|
|
|
|
local flags = toolset.getlinks(cfg)
|
2016-08-17 15:48:41 +00:00
|
|
|
_p(' LIBS +=%s', make.list(flags, true))
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.linkCmd(cfg, toolset)
|
2017-04-25 05:44:13 +00:00
|
|
|
if cfg.kind == p.STATICLIB then
|
|
|
|
if cfg.architecture == p.UNIVERSAL then
|
2015-06-24 23:03:10 +00:00
|
|
|
_p(' LINKCMD = libtool -o "$@" $(OBJECTS)')
|
2013-08-11 18:22:24 +00:00
|
|
|
else
|
2016-06-03 15:00:14 +00:00
|
|
|
_p(' LINKCMD = $(AR) ' .. (toolset.arargs or '-rcs') ..' "$@" $(OBJECTS)')
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
2017-04-25 05:44:13 +00:00
|
|
|
elseif cfg.kind == p.UTILITY then
|
2015-10-01 02:34:46 +00:00
|
|
|
-- Empty LINKCMD for Utility (only custom build rules)
|
|
|
|
_p(' LINKCMD =')
|
2013-08-11 18:22:24 +00:00
|
|
|
else
|
|
|
|
-- this was $(TARGET) $(LDFLAGS) $(OBJECTS)
|
|
|
|
-- but had trouble linking to certain static libs; $(OBJECTS) moved up
|
|
|
|
-- $(LDFLAGS) moved to end (http://sourceforge.net/p/premake/patches/107/)
|
|
|
|
-- $(LIBS) moved to end (http://sourceforge.net/p/premake/bugs/279/)
|
|
|
|
|
2017-01-31 20:10:40 +00:00
|
|
|
local cc = iif(p.languages.isc(cfg.language), "CC", "CXX")
|
2015-06-24 23:03:10 +00:00
|
|
|
_p(' LINKCMD = $(%s) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)', cc)
|
2013-08-11 18:22:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function make.pch(cfg, toolset)
|
2013-08-13 14:56:01 +00:00
|
|
|
-- If there is no header, or if PCH has been disabled, I can early out
|
|
|
|
if not cfg.pchheader or cfg.flags.NoPCH then
|
|
|
|
return
|
|
|
|
end
|
2012-06-12 19:57:45 +00:00
|
|
|
|
2013-08-13 14:56:01 +00:00
|
|
|
-- Visual Studio requires the PCH header to be specified in the same way
|
|
|
|
-- it appears in the #include statements used in the source code; the PCH
|
|
|
|
-- source actual handles the compilation of the header. GCC compiles the
|
|
|
|
-- header file directly, and needs the file's actual file system path in
|
|
|
|
-- order to locate it.
|
|
|
|
|
|
|
|
-- To maximize the compatibility between the two approaches, see if I can
|
|
|
|
-- locate the specified PCH header on one of the include file search paths
|
|
|
|
-- and, if so, adjust the path automatically so the user doesn't have
|
|
|
|
-- add a conditional configuration to the project script.
|
|
|
|
|
|
|
|
local pch = cfg.pchheader
|
2015-12-26 18:26:29 +00:00
|
|
|
local found = false
|
2016-05-02 23:55:50 +00:00
|
|
|
|
|
|
|
-- test locally in the project folder first (this is the most likely location)
|
|
|
|
local testname = path.join(cfg.project.basedir, pch)
|
|
|
|
if os.isfile(testname) then
|
|
|
|
pch = project.getrelative(cfg.project, testname)
|
|
|
|
found = true
|
|
|
|
else
|
|
|
|
-- else scan in all include dirs.
|
|
|
|
for _, incdir in ipairs(cfg.includedirs) do
|
|
|
|
testname = path.join(incdir, pch)
|
|
|
|
if os.isfile(testname) then
|
|
|
|
pch = project.getrelative(cfg.project, testname)
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
end
|
2013-08-13 14:56:01 +00:00
|
|
|
end
|
2012-06-12 19:57:45 +00:00
|
|
|
end
|
2016-05-02 23:55:50 +00:00
|
|
|
|
2015-12-26 18:26:29 +00:00
|
|
|
if not found then
|
|
|
|
pch = project.getrelative(cfg.project, path.getabsolute(pch))
|
|
|
|
end
|
2013-08-13 14:56:01 +00:00
|
|
|
|
2013-08-15 17:44:54 +00:00
|
|
|
_x(' PCH = %s', pch)
|
2013-08-13 14:56:01 +00:00
|
|
|
_p(' GCH = $(OBJDIR)/$(notdir $(PCH)).gch')
|
2012-06-12 19:57:45 +00:00
|
|
|
end
|
|
|
|
|
2013-08-13 14:56:01 +00:00
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.pchRules(prj)
|
2012-06-12 19:57:45 +00:00
|
|
|
_p('ifneq (,$(PCH))')
|
2014-06-05 16:11:03 +00:00
|
|
|
_p('$(OBJECTS): $(GCH) $(PCH)')
|
2012-06-12 19:57:45 +00:00
|
|
|
_p('$(GCH): $(PCH)')
|
|
|
|
_p('\t@echo $(notdir $<)')
|
2017-06-01 17:05:53 +00:00
|
|
|
make.mkdir('$(OBJDIR)')
|
2013-08-13 14:56:01 +00:00
|
|
|
|
2013-10-03 14:47:14 +00:00
|
|
|
local cmd = iif(prj.language == "C", "$(CC) -x c-header $(ALL_CFLAGS)", "$(CXX) -x c++-header $(ALL_CXXFLAGS)")
|
2014-02-14 20:22:32 +00:00
|
|
|
_p('\t$(SILENT) %s -o "$@" -MF "$(@:%%.gch=%%.d)" -c "$<"', cmd)
|
2013-08-13 14:56:01 +00:00
|
|
|
|
2012-06-12 19:57:45 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
function make.resFlags(cfg, toolset)
|
|
|
|
local resflags = table.join(toolset.getdefines(cfg.resdefines), toolset.getincludedirs(cfg, cfg.resincludedirs), cfg.resoptions)
|
|
|
|
_p(' ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)%s', make.list(resflags))
|
2012-06-12 19:57:45 +00:00
|
|
|
end
|