Added custom options, support for CodeBlocks/OpenWatcom (r596:606)
This commit is contained in:
parent
79f26b0063
commit
b4c4129b53
@ -20,8 +20,9 @@
|
||||
"base/project.lua",
|
||||
"base/config.lua",
|
||||
"base/functions.lua",
|
||||
"base/gcc.lua",
|
||||
"base/cmdline.lua",
|
||||
"base/gcc.lua",
|
||||
"base/ow.lua",
|
||||
|
||||
-- this one must be last
|
||||
"_premake_main.lua"
|
||||
|
@ -16,10 +16,15 @@
|
||||
--
|
||||
|
||||
local function showhelp()
|
||||
-- sort the lists of actions and options
|
||||
actions = { }
|
||||
for name,_ in pairs(premake.actions) do table.insert(actions, name) end
|
||||
table.sort(actions)
|
||||
|
||||
options = { }
|
||||
for name,_ in pairs(premake.options) do table.insert(options, name) end
|
||||
table.sort(options)
|
||||
|
||||
printf("Premake %s, a build script generator", _PREMAKE_VERSION)
|
||||
printf(_PREMAKE_COPYRIGHT)
|
||||
printf("%s %s", _VERSION, _COPYRIGHT)
|
||||
@ -27,21 +32,33 @@
|
||||
printf("Usage: premake4 [options] action [arguments]")
|
||||
printf("")
|
||||
|
||||
printf("OPTIONS")
|
||||
printf("")
|
||||
for _,name in ipairs(options) do
|
||||
local opt = premake.options[name]
|
||||
local trigger = opt.trigger
|
||||
local description = opt.description
|
||||
|
||||
if (opt.value) then trigger = trigger .. "=" .. opt.value end
|
||||
if (opt.allowed) then description = description .. "; one of:" end
|
||||
|
||||
printf(" --%-15s %s", trigger, description)
|
||||
if (opt.allowed) then
|
||||
table.sort(opt.allowed, function(a,b) return a[1] < b[1] end)
|
||||
for _, value in ipairs(opt.allowed) do
|
||||
printf(" %-14s %s", value[1], value[2])
|
||||
end
|
||||
end
|
||||
printf("")
|
||||
end
|
||||
|
||||
printf("ACTIONS")
|
||||
printf("")
|
||||
for _,name in ipairs(actions) do
|
||||
printf(" %-17s %s", name, premake.actions[name].description)
|
||||
printf(" %-17s %s", name, premake.actions[name].description)
|
||||
end
|
||||
printf("")
|
||||
|
||||
printf("OPTIONS")
|
||||
printf("")
|
||||
printf(" --file=name Process the specified Premake script file")
|
||||
printf(" --help Display this information")
|
||||
printf(" --scripts=path Search for additional scripts on the given path")
|
||||
printf(" --version Display version information")
|
||||
printf("")
|
||||
|
||||
printf("For additional information, see http://industriousone.com/premake")
|
||||
end
|
||||
|
||||
@ -113,18 +130,28 @@
|
||||
end
|
||||
|
||||
|
||||
-- Prep the session, and then hand off control to the action
|
||||
-- Validate the command-line arguments. This has to happen after the
|
||||
-- script has run to allow for project-specific options
|
||||
|
||||
local action = premake.actions[name]
|
||||
if (not premake.actions[_ACTION]) then
|
||||
error("Error: No such action '".._ACTION.."'", 0)
|
||||
error("Error: no such action '".._ACTION.."'", 0)
|
||||
end
|
||||
|
||||
ok, err = premake.checkoptions()
|
||||
if (not ok) then error("Error: " .. err, 0) end
|
||||
|
||||
|
||||
-- Sanity check the current project setup
|
||||
|
||||
ok, err = premake.checktools()
|
||||
if (not ok) then error("Error: " .. err, 0) end
|
||||
|
||||
ok, err = premake.checkprojects()
|
||||
if (not ok) then error("Error: " .. err, 0) end
|
||||
|
||||
|
||||
-- Hand over control to the action
|
||||
premake.doaction(_ACTION)
|
||||
return 0
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
valid_languages = { "C", "C++" },
|
||||
|
||||
valid_tools = {
|
||||
cc = { "gcc" },
|
||||
cc = { "gcc", "ow" },
|
||||
},
|
||||
|
||||
solutiontemplates = {
|
||||
|
@ -1,10 +1,11 @@
|
||||
<% local cc = premake[_OPTIONS.cc] %>
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="<%= premake.esc(this.name) %>" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Option compiler="<%= _OPTIONS.cc %>" />
|
||||
<Build>
|
||||
<% for cfg in premake.eachconfig(this) do %>
|
||||
<Target title="<%= premake.esc(cfg.name) %>">
|
||||
@ -19,49 +20,19 @@
|
||||
<% elseif (cfg.kind == "SharedApp") then %>
|
||||
<Option type="3" />
|
||||
<% end %>
|
||||
<Option compiler="gcc" />
|
||||
<Option compiler="<%= _OPTIONS.cc %>" />
|
||||
<% if (cfg.kind == "SharedLib") then %>
|
||||
<Option createDefFile="0" />
|
||||
<Option createStaticLib="<%= iif(cfg.flags.NoImportLib, 0, 1) %> />
|
||||
<Option createStaticLib="<%= iif(cfg.flags.NoImportLib, 0, 1) %>" />
|
||||
<% end %>
|
||||
<Compiler>
|
||||
<% if cfg.flags.ExtraWarnings then %>
|
||||
<Add option="-Wall" />
|
||||
<% end %>
|
||||
<% if cfg.flags.FatalWarnings then %>
|
||||
<Add option="-Werror" />
|
||||
<% end %>
|
||||
<% if cfg.flags.NoExceptions then %>
|
||||
<Add option="--no-exceptions" />
|
||||
<% end %>
|
||||
<% if cfg.flags.NoFramePointer then %>
|
||||
<Add option="-fomit-frame-pointer" />
|
||||
<% end %>
|
||||
<% if cfg.flags.NoRTTI then %>
|
||||
<Add option="--no-rtti" />
|
||||
<% end %>
|
||||
<% if cfg.flags.Symbols then %>
|
||||
<Add option="-g" />
|
||||
<% end %>
|
||||
<% if cfg.flags.OptimizeSize then %>
|
||||
<Add option="-Os" />
|
||||
<% end %>
|
||||
<% if cfg.flags.OptimizeSpeed then %>
|
||||
<Add option="-O3" />
|
||||
<% end %>
|
||||
<% if cfg.flags.Optimize and not cfg.flags.OptimizeSize and not cfg.flags.OptimizeSpeed then %>
|
||||
<Add option="-O" />
|
||||
<% for _,flag in ipairs(table.join(cc.getcflags(cfg), cc.getcxxflags(cfg), cc.getdefines(cfg.defines), cfg.buildoptions)) do %>
|
||||
<Add option="<%= premake.esc(flag) %>" />
|
||||
<% end %>
|
||||
<% if not cfg.flags.NoPCH and cfg.pchheader then %>
|
||||
<Add option="-Winvalid-pch" />
|
||||
<Add option="-include "<%= premake.esc(cfg.pchheader) %>"" />
|
||||
<% end %>
|
||||
<% for _,v in ipairs(cfg.defines) do %>
|
||||
<Add option="-D<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
<% for _,v in ipairs(cfg.buildoptions) do %>
|
||||
<Add option="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
<% for _,v in ipairs(cfg.includedirs) do %>
|
||||
<Add directory="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
@ -73,14 +44,10 @@
|
||||
<% for _,v in ipairs(cfg.linkoptions) do %>
|
||||
<Add option="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
<% for _,v in ipairs(cfg.libdirs) do %>
|
||||
<% for _,v in ipairs(premake.getlibdirs(cfg)) do %>
|
||||
<Add directory="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
<% local dirs, links = premake.gcc.getlinks(cfg) %>
|
||||
<% for _,v in ipairs(dirs) do %>
|
||||
<Add directory="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
<% for _,v in ipairs(links) do %>
|
||||
<% for _,v in ipairs(premake.getlibnames(cfg)) do %>
|
||||
<Add library="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
</Linker>
|
||||
@ -112,7 +79,7 @@
|
||||
<% if path.getextension(fname) == ".rc" then %>
|
||||
<Option compilerVar="WINDRES" />
|
||||
<% else %>
|
||||
<Option compilerVar="<%= iif(this.language == "C", "CC", "CPP") %>" />
|
||||
<Option compilerVar="<%= cc.getcompilervar(this) %>" />
|
||||
<% if (not this.flags.NoPCH and fname == this.pchheader) then %>
|
||||
<Option compile="1" />
|
||||
<Option weight="0" />
|
||||
|
@ -15,20 +15,16 @@
|
||||
<% end %>
|
||||
</Compiler>
|
||||
<Linker Required="yes" Options="<%= table.concat(table.join(premake.gcc.getldflags(cfg), cfg.linkoptions), ";") %>">
|
||||
<% local dirs, links = premake.gcc.getlinks(cfg) %>
|
||||
<% for _,v in ipairs(dirs) do %>
|
||||
<% for _,v in ipairs(premake.getlibdirs(cfg)) do %>
|
||||
<LibraryPath Value="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
<% for _,v in ipairs(links) do %>
|
||||
<% for _,v in ipairs(premake.getlibnames(cfg)) do %>
|
||||
<Library Value="<%= premake.esc(v) %>" />
|
||||
<% end %>
|
||||
</Linker>
|
||||
<% if premake.findfile(cfg, ".rc") then %>
|
||||
<ResourceCompiler Required="yes" Options="<%= table.implode(table.join(cfg.defines,cfg.resdefines), "-D", ";", "") %><%= table.concat(cfg.resoptions, ";") %>">
|
||||
<% for _,v in ipairs(cfg.includedirs) do %>
|
||||
<IncludePath Value="<%= premake.esc(v) %>"/>
|
||||
<% end %>
|
||||
<% for _,v in ipairs(cfg.resincludedirs) do %>
|
||||
<% for _,v in ipairs(table.join(cfg.includedirs, cfg.resincludedirs)) do %>
|
||||
<IncludePath Value="<%= premake.esc(v) %>"/>
|
||||
<% end %>
|
||||
</ResourceCompiler>
|
||||
|
@ -1,3 +1,4 @@
|
||||
<% local cc = premake[_OPTIONS.cc] %>
|
||||
# <%= premake.actions[_ACTION].shortname %> project makefile autogenerated by Premake
|
||||
|
||||
ifndef CONFIG
|
||||
@ -6,16 +7,17 @@ endif
|
||||
|
||||
<% for cfg in premake.eachconfig(this) do %>
|
||||
ifeq ($(CONFIG),<%= _MAKE.esc(cfg.name)%>)
|
||||
TARGETDIR = <%= _MAKE.esc(path.getdirectory(cfg.target)) %>
|
||||
TARGET = $(TARGETDIR)/<%= _MAKE.esc(path.getname(premake.gettargetfile(cfg, "target", nil, true))) %>
|
||||
<% local target = premake.gettargetfile(cfg, "target", nil, true) %>
|
||||
TARGETDIR = <%= _MAKE.esc(path.getdirectory(target)) %>
|
||||
TARGET = $(TARGETDIR)/<%= _MAKE.esc(path.getname(target)) %>
|
||||
OBJDIR = <%= _MAKE.esc(premake.getobjdir(cfg)) %>
|
||||
DEFINES += <%= premake[_OPTIONS.cc].make_defines(cfg) %>
|
||||
INCLUDES += <%= premake[_OPTIONS.cc].make_includes(cfg) %>
|
||||
CPPFLAGS += <%= premake[_OPTIONS.cc].make_cppflags(cfg) %> $(DEFINES) $(INCLUDES)
|
||||
CFLAGS += $(CPPFLAGS) $(ARCH) <%= premake[_OPTIONS.cc].make_cflags(cfg) %> <%= table.concat(cfg.buildoptions, " ") %>
|
||||
CXXFLAGS += $(CFLAGS) <%= premake[_OPTIONS.cc].make_cxxflags(cfg) %>
|
||||
LDFLAGS += <%= premake[_OPTIONS.cc].make_ldflags(cfg) %> <%= table.concat(cfg.linkoptions, " ") %>
|
||||
RESFLAGS += $(DEFINES) $(INCLUDES) <%= table.concat(cfg.resoptions, " ") %>
|
||||
DEFINES += <%= table.concat(cc.getdefines(cfg.defines), " ") %>
|
||||
INCLUDES += <%= table.concat(cc.getincludedirs(cfg.includedirs), " ") %>
|
||||
CPPFLAGS += <%= cc.getcppflags(cfg) %> $(DEFINES) $(INCLUDES)
|
||||
CFLAGS += $(CPPFLAGS) $(ARCH) <%= table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " ") %>
|
||||
CXXFLAGS += $(CFLAGS) <%= table.concat(cc.getcxxflags(cfg), " ") %>
|
||||
LDFLAGS += <%= table.concat(table.join(cc.getldflags(cfg), cc.getlinkflags(cfg), cfg.linkoptions), " ") %>
|
||||
RESFLAGS += $(DEFINES) $(INCLUDES) <%= table.concat(table.join(cc.getdefines(cfg.resdefines), cc.getincludedirs(cfg.resincludedirs), cfg.resoptions), " ") %>
|
||||
LDDEPS += <%= table.concat(_MAKE.gettargetdeps(cfg), " ") %>
|
||||
<% if cfg.kind == "StaticLib" then %>
|
||||
LINKCMD = ar -rcs $(TARGET) $(OBJECTS) $(ARCH)
|
||||
@ -118,12 +120,21 @@ prelink:
|
||||
$(PRELINKCMDS)
|
||||
|
||||
<% for _, file in ipairs(this.files) do %>
|
||||
<% if path.iscppfile(file) then %>
|
||||
<% if path.iscppfile(file) then %>
|
||||
$(OBJDIR)/<%= _MAKE.esc(path.getbasename(file)) %>.o: <%= _MAKE.esc(file) %>
|
||||
@echo $(notdir $<)
|
||||
@<%= premake[_OPTIONS.cc].make_file_rule(file) %>
|
||||
<% if (path.iscfile(file)) then %>
|
||||
@$(CC) $(CFLAGS) -o $@ -c $<
|
||||
<% else %>
|
||||
@$(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
<% elseif (path.getextension(file) == ".rc") then %>
|
||||
$(OBJDIR)/<%= _MAKE.esc(path.getbasename(file)) %>.res: <%= _MAKE.esc(file) %>
|
||||
@echo $(notdir $<)
|
||||
@windres $< -O coff -o $@ $(RESFLAGS)
|
||||
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
-include $(OBJECTS:%.o=%.d)
|
||||
|
@ -29,10 +29,11 @@
|
||||
<% end %>
|
||||
<Configurations>
|
||||
<% for cfg in premake.eachconfig(this) do %>
|
||||
<% local target = premake.gettargetfile(cfg, "target", "windows") %>
|
||||
<Configuration
|
||||
Name="<%= premake.esc(cfg.name) %>|Win32"
|
||||
OutputDirectory="<%= premake.esc(path.translate(path.getdirectory(cfg.target), "\\")) %>"
|
||||
IntermediateDirectory="<%= premake.esc(path.translate(premake.getobjdir(cfg)), "\\") %>"
|
||||
OutputDirectory="<%= premake.esc(path.translate(path.getdirectory(target), "\\")) %>"
|
||||
IntermediateDirectory="<%= premake.esc(path.translate(premake.getobjdir(cfg), "\\")) %>"
|
||||
ConfigurationType="<%= _VS.cfgtype(cfg) %>"
|
||||
CharacterSet="<%= iif(cfg.flags.Unicode, 1, 2) %>"
|
||||
<% if cfg.flags.Managed then %>
|
||||
@ -134,7 +135,7 @@
|
||||
<% if #cfg.links > 0 then %>
|
||||
AdditionalDependencies="<%= table.concat(premake.getlibraries(cfg), " ") %>"
|
||||
<% end %>
|
||||
OutputFile="$(OutDir)\<%= path.getname(cfg.target) %>"
|
||||
OutputFile="$(OutDir)\<%= path.getname(target) %>"
|
||||
LinkIncremental="<%= iif(_VS.optimization(cfg) == 0, 2, 1) %>"
|
||||
AdditionalLibraryDirectories="<%= table.concat(premake.esc(cfg.libdirs) , ";") %>"
|
||||
<% local deffile = premake.findfile(cfg, ".def"); if deffile then %>
|
||||
@ -161,7 +162,7 @@
|
||||
TargetMachine="1"
|
||||
<% else %>
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)\\<%= path.getname(cfg.target) %>"
|
||||
OutputFile="$(OutDir)\\<%= path.getname(target) %>"
|
||||
<% end %>
|
||||
/>
|
||||
<% elseif (block == "VCManagedResourceCompilerTool") then %>
|
||||
|
@ -10,6 +10,12 @@
|
||||
"description",
|
||||
"trigger",
|
||||
}
|
||||
|
||||
local requiredoptionfields =
|
||||
{
|
||||
"description",
|
||||
"trigger"
|
||||
}
|
||||
|
||||
|
||||
--
|
||||
@ -29,6 +35,98 @@
|
||||
error("action needs a " .. missing, 2)
|
||||
end
|
||||
|
||||
-- add it to the master list
|
||||
premake.actions[a.trigger] = a
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Define a new option.
|
||||
--
|
||||
|
||||
function newoption(opt)
|
||||
-- some sanity checking
|
||||
local missing
|
||||
for _, field in ipairs(requiredactionfields) do
|
||||
if (not opt[field]) then
|
||||
missing = field
|
||||
end
|
||||
end
|
||||
|
||||
if (missing) then
|
||||
error("action needs a " .. missing, 2)
|
||||
end
|
||||
|
||||
-- add it to the master list
|
||||
premake.options[opt.trigger] = opt
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Built-in command line options
|
||||
--
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "cc",
|
||||
value = "compiler",
|
||||
description = "Choose a C/C++ compiler set",
|
||||
allowed = {
|
||||
{ "gcc", "GNU GCC compiler (gcc/g++)" },
|
||||
{ "ow", "OpenWatcom compiler" },
|
||||
}
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "dotnet",
|
||||
value = "value",
|
||||
description = "Choose a .NET compiler set",
|
||||
allowed = {
|
||||
{ "ms", "Microsoft .NET (csc)" },
|
||||
{ "mono", "Novell Mono (mcs)" },
|
||||
{ "pnet", "Portable.NET (cscc)" },
|
||||
}
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "file",
|
||||
value = "filename",
|
||||
description = "Process the specified Premake script file"
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "help",
|
||||
description = "Display this information"
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "os",
|
||||
value = "value",
|
||||
description = "Generate files for a different operating system",
|
||||
allowed = {
|
||||
{ "bsd", "OpenBSD, NetBSD, or FreeBSD" },
|
||||
{ "linux", "Linux" },
|
||||
{ "macosx", "Apple Mac OS X" },
|
||||
{ "windows", "Microsoft Windows" },
|
||||
}
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "scripts",
|
||||
value = "path",
|
||||
description = "Search for additional scripts on the given path"
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "version",
|
||||
description = "Display version information"
|
||||
}
|
||||
|
@ -132,9 +132,6 @@
|
||||
cfg.name = cfgname
|
||||
cfg.project = prj
|
||||
|
||||
-- precompute common calculated values
|
||||
cfg.target = premake.gettargetfile(cfg, "target")
|
||||
|
||||
meta.__cfgcache[cachekey] = cfg
|
||||
return cfg
|
||||
end
|
||||
@ -197,6 +194,33 @@
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Split the list of libraries into directories and names.
|
||||
-- See bug #1729227 for background on why the path must be split.
|
||||
--
|
||||
|
||||
function premake.getlibdirs(cfg)
|
||||
local result = table.join(cfg.libdirs)
|
||||
for _, link in ipairs(premake.getlibraries(cfg)) do
|
||||
local dir = path.getdirectory(link)
|
||||
if (dir ~= "" and not table.contains(result, dir)) then
|
||||
table.insert(result, dir)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function premake.getlibnames(cfg)
|
||||
local result = { }
|
||||
for _, link in ipairs(premake.getlibraries(cfg)) do
|
||||
local name = path.getbasename(link)
|
||||
table.insert(result, path.getbasename(link))
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Return an object directory for the specified configuration which
|
||||
|
171
src/base/gcc.lua
171
src/base/gcc.lua
@ -4,12 +4,6 @@
|
||||
-- Copyright (c) 2002-2008 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
--
|
||||
-- I don't know if this is the right breakdown or API to individual compilers
|
||||
-- yet so treat it all as experimental. I won't know until I get the change
|
||||
-- to implement a few different compilers across different toolset actions.
|
||||
--
|
||||
|
||||
|
||||
premake.gcc = { }
|
||||
|
||||
@ -37,26 +31,27 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- CFLAGS
|
||||
-- Returns the compiler ID used by Code::Blocks.
|
||||
--
|
||||
|
||||
function premake.gcc.make_cflags(cfg)
|
||||
local flags = table.translate(cfg.flags, cflags)
|
||||
|
||||
if (cfg.kind == "SharedLib" and not os.is("windows")) then
|
||||
table.insert(flags, "-fPIC")
|
||||
end
|
||||
|
||||
return table.concat(flags, " ")
|
||||
function premake.gcc.getcompilervar(cfg)
|
||||
return iif(cfg.language == "C", "CC", "CPP")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Returns a list of compiler flags, based on the supplied configuration.
|
||||
--
|
||||
|
||||
function premake.gcc.getcppflags(cfg)
|
||||
-- if $(ARCH) contains multiple targets, then disable the incompatible automatic
|
||||
-- dependency generation. This allows building universal binaries on MacOSX, sorta.
|
||||
return "$(if $(word 2, $(ARCH)), , -MMD)"
|
||||
end
|
||||
|
||||
function premake.gcc.getcflags(cfg)
|
||||
local result = table.translate(cfg.flags, cflags)
|
||||
if (cfg.kind == "SharedLib" and not os.is("windows")) then
|
||||
@ -112,129 +107,45 @@
|
||||
|
||||
|
||||
--
|
||||
-- Process the list of libraries for a configuration. Returns a list of linker
|
||||
-- search paths, followed by a list of link names. Not all compilers need to
|
||||
-- split up links this way; in that case, return an empty list of search paths
|
||||
-- and keep the library paths intact.
|
||||
-- See bug #1729227 for background on why the path must be split for GCC.
|
||||
-- Returns a list of linker flags for library search directories and
|
||||
-- library names.
|
||||
--
|
||||
|
||||
function premake.gcc.getlinks(cfg)
|
||||
local dirs = { }
|
||||
local names = { }
|
||||
for _, link in ipairs(premake.getlibraries(cfg)) do
|
||||
local dir = path.getdirectory(link)
|
||||
local name = path.getbasename(link)
|
||||
|
||||
if (dir ~= "" and not table.contains(cfg.libdirs, dir) and not table.contains(dirs, dir)) then
|
||||
table.insert(dirs, dir)
|
||||
end
|
||||
|
||||
table.insert(names, name)
|
||||
function premake.gcc.getlinkflags(cfg)
|
||||
local result = { }
|
||||
for _, value in ipairs(premake.getlibdirs(cfg)) do
|
||||
table.insert(result, '-L "' .. value .. '"')
|
||||
end
|
||||
|
||||
return dirs, names
|
||||
for _, value in ipairs(premake.getlibnames(cfg)) do
|
||||
table.insert(result, '-l "' .. value .. '"')
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- CPPFLAGS
|
||||
--
|
||||
|
||||
function premake.gcc.make_cppflags(cfg)
|
||||
-- if $(ARCH) contains multiple targets, then disable the incompatible automatic
|
||||
-- dependency generation. This allows building universal binaries on MacOSX, sorta.
|
||||
return "$(if $(word 2, $(ARCH)), , -MMD)"
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- CXXFLAGS
|
||||
--
|
||||
|
||||
function premake.gcc.make_cxxflags(cfg)
|
||||
local flags = table.translate(cfg.flags, cxxflags)
|
||||
return table.concat(flags, " ")
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- DEFINES and INCLUDES
|
||||
-- Decorate defines for the GCC command line.
|
||||
--
|
||||
|
||||
function premake.gcc.make_defines(cfg)
|
||||
return table.implode(cfg.defines, '-D "', '"', ' ')
|
||||
|
||||
function premake.gcc.getdefines(defines)
|
||||
local result = { }
|
||||
for _,def in ipairs(defines) do
|
||||
table.insert(result, '-D' .. def)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
|
||||
function premake.gcc.make_includes(cfg)
|
||||
return table.implode(cfg.includedirs, '-I "', '"', ' ')
|
||||
--
|
||||
-- Decorate include file search paths for the GCC command line.
|
||||
--
|
||||
|
||||
function premake.gcc.getincludedirs(includedirs)
|
||||
local result = { }
|
||||
for _,dir in ipairs(includedirs) do
|
||||
table.insert(result, '-I "' .. dir .. '"')
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- LDFLAGS
|
||||
--
|
||||
|
||||
function premake.gcc.make_ldflags(cfg)
|
||||
local flags = { }
|
||||
|
||||
if (cfg.kind == "SharedLib") then
|
||||
if (not os.is("macosx")) then
|
||||
table.insert(flags, "-shared")
|
||||
end
|
||||
|
||||
-- create import library for DLLs under Windows
|
||||
if (os.is("windows") and not cfg.flags.NoImportLib) then
|
||||
table.insert(flags, '-Wl,--out-implib="' .. premake.gettargetfile(cfg, "implib", "linux") .. '"')
|
||||
end
|
||||
end
|
||||
|
||||
if (os.is("windows") and cfg.kind == "WindowedApp") then
|
||||
table.insert(flags, "-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
|
||||
table.insert(flags, "-Wl,-x")
|
||||
else
|
||||
table.insert(flags, "-s")
|
||||
end
|
||||
end
|
||||
|
||||
if (os.is("macosx") and table.contains(flags, "Dylib")) then
|
||||
table.insert(flags, "-dynamiclib -flat_namespace")
|
||||
end
|
||||
|
||||
-- need to split path from libraries to avoid runtime errors (see bug #1729227)
|
||||
local dirs = { }
|
||||
local names = { }
|
||||
for _, link in ipairs(premake.getlibraries(cfg)) do
|
||||
local dir = path.getdirectory(link)
|
||||
local name = path.getbasename(link)
|
||||
|
||||
if (dir ~= "" and not table.contains(cfg.libdirs, dir) and not table.contains(dirs, dir)) then
|
||||
table.insert(dirs, dir)
|
||||
end
|
||||
|
||||
table.insert(names, name)
|
||||
end
|
||||
|
||||
return table.concat(flags, " ") .. table.implode(cfg.libdirs, ' -L "', '"').. table.implode(dirs, ' -L "', '"') .. table.implode(names, ' -l "', '"')
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- SOURCE FILE RULES
|
||||
--
|
||||
|
||||
function premake.gcc.make_file_rule(file)
|
||||
if (path.iscfile(file)) then
|
||||
return "$(CC) $(CFLAGS) -o $@ -c $<"
|
||||
else
|
||||
return "$(CXX) $(CXXFLAGS) -o $@ -c $<"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,9 +20,11 @@
|
||||
premake = { }
|
||||
|
||||
|
||||
-- The list of registered actions
|
||||
-- The list of registered actions and options
|
||||
|
||||
premake.actions = { }
|
||||
premake.options = { }
|
||||
|
||||
|
||||
|
||||
--
|
||||
|
@ -20,7 +20,7 @@
|
||||
for tool, values in pairs(action.valid_tools) do
|
||||
if (_OPTIONS[tool]) then
|
||||
if (not table.contains(values, _OPTIONS[tool])) then
|
||||
return nil, "the " .. action.shortname .. " action does not support /" .. tool .. "=" .. _OPTIONS[tool]
|
||||
return nil, "the " .. action.shortname .. " action does not support /" .. tool .. "=" .. _OPTIONS[tool] .. " (yet)"
|
||||
end
|
||||
else
|
||||
_OPTIONS[tool] = values[1]
|
||||
@ -31,7 +31,36 @@
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Validate the command-line options.
|
||||
--
|
||||
|
||||
function premake.checkoptions()
|
||||
for key, value in pairs(_OPTIONS) do
|
||||
-- is this a valid option?
|
||||
local opt = premake.options[key]
|
||||
if (not opt) then
|
||||
return false, "invalid option '" .. key .. "'"
|
||||
end
|
||||
|
||||
-- does it need a value?
|
||||
if (opt.value and value == "") then
|
||||
return false, "no value specified for option '" .. key .. "'"
|
||||
end
|
||||
|
||||
-- is the value allowed?
|
||||
if (opt.allowed) then
|
||||
for _, match in ipairs(opt.allowed) do
|
||||
if (match[1] == value) then return true end
|
||||
end
|
||||
return false, "invalid value '" .. value .. "' for option '" .. key .. "'"
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Check to see if a value exists in a list of values, using a
|
||||
-- case-insensitive match. If the value does exist, the canonical
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user