2009-04-11 11:33:32 +00:00
|
|
|
--
|
|
|
|
-- make_cpp.lua
|
|
|
|
-- Generate a C/C++ project makefile.
|
|
|
|
-- Copyright (c) 2002-2009 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
function premake.make_cpp(prj)
|
|
|
|
-- create a shortcut to the compiler interface
|
|
|
|
local cc = premake[_OPTIONS.cc]
|
|
|
|
|
2009-04-20 19:06:48 +00:00
|
|
|
-- build a list of supported target platforms that also includes a generic build
|
2009-04-21 20:00:17 +00:00
|
|
|
local platforms = premake.filterplatforms(prj.solution, cc.platforms, "Native")
|
2009-04-20 19:06:48 +00:00
|
|
|
|
2009-04-11 11:33:32 +00:00
|
|
|
-- write a quick header
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('# %s project makefile autogenerated by Premake', premake.actions[_ACTION].shortname)
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- set up the environment
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef config')
|
2009-04-20 19:06:48 +00:00
|
|
|
_p(' config=%s%s', _MAKE.esc(prj.configurations[1]:lower()), cc.platforms[platforms[1]].suffix)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('ifndef verbose')
|
|
|
|
_p(' SILENT = @')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- list the configurations
|
2009-04-14 19:41:30 +00:00
|
|
|
for _, platform in ipairs(platforms) do
|
|
|
|
for cfg in premake.eachconfig(prj, platform) do
|
2009-04-23 23:05:24 +00:00
|
|
|
premake.gmake_cpp_config(cfg)
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- list intermediate files
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('OBJECTS := \\')
|
2009-04-11 11:33:32 +00:00
|
|
|
for _, file in ipairs(prj.files) do
|
|
|
|
if path.iscppfile(file) then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(OBJDIR)/%s.o \\', _MAKE.esc(path.getbasename(file)))
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('RESOURCES := \\')
|
2009-04-11 11:33:32 +00:00
|
|
|
for _, file in ipairs(prj.files) do
|
|
|
|
if path.isresourcefile(file) then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(OBJDIR)/%s.res \\', _MAKE.esc(path.getbasename(file)))
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- set up support commands like mkdir, rmdir, etc. based on the shell
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('SHELLTYPE := msdos')
|
|
|
|
_p('ifeq (,$(ComSpec)$(COMSPEC))')
|
|
|
|
_p(' SHELLTYPE := posix')
|
|
|
|
_p('endif')
|
|
|
|
_p('ifeq (/bin,$(findstring /bin,$(SHELL)))')
|
|
|
|
_p(' SHELLTYPE := posix')
|
|
|
|
_p('endif')
|
|
|
|
_p('ifeq (posix,$(SHELLTYPE))')
|
|
|
|
_p(' define MKDIR_RULE')
|
|
|
|
_p('\t@echo Creating $@')
|
|
|
|
_p('\t$(SILENT) mkdir -p $@')
|
|
|
|
_p(' endef')
|
|
|
|
_p('else')
|
|
|
|
_p(' define MKDIR_RULE')
|
|
|
|
_p('\t@echo Creating $@')
|
|
|
|
_p('\t$(SILENT) mkdir $(subst /,\\\\,$@)')
|
|
|
|
_p(' endef')
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- main build rule(s)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('.PHONY: clean prebuild prelink')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
if os.is("MacOSX") and prj.kind == "WindowedApp" then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(OBJECTS) $(RESOURCES) prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
|
2009-04-11 11:33:32 +00:00
|
|
|
else
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(OBJECTS) $(RESOURCES) prelink $(TARGET)')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES)')
|
|
|
|
_p('\t@echo Linking %s', prj.name)
|
|
|
|
_p('\t@$(LINKCMD)')
|
|
|
|
_p('\t$(POSTBUILDCMDS)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- create destination directories
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(TARGETDIR):')
|
|
|
|
_p('\t$(MKDIR_RULE)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(OBJDIR):')
|
|
|
|
_p('\t$(MKDIR_RULE)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- Mac OS X specific targets
|
|
|
|
if os.is("MacOSX") and prj.kind == "WindowedApp" then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(dir $(TARGETDIR))PkgInfo:')
|
|
|
|
_p('$(dir $(TARGETDIR))Info.plist:')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- clean target
|
2009-04-11 11:49:07 +00:00
|
|
|
_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('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- custom build step targets
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('prebuild:')
|
|
|
|
_p('\t$(PREBUILDCMDS)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('prelink:')
|
|
|
|
_p('\t$(PRELINKCMDS)')
|
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- per-file rules
|
|
|
|
for _, file in ipairs(prj.files) do
|
|
|
|
if path.iscppfile(file) then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
|
|
|
|
_p('\t@echo $(notdir $<)')
|
2009-04-11 11:33:32 +00:00
|
|
|
if (path.iscfile(file)) then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(SILENT) $(CC) $(CFLAGS) -o $@ -c $<')
|
2009-04-11 11:33:32 +00:00
|
|
|
else
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\t$(SILENT) $(CXX) $(CXXFLAGS) -o $@ -c $<')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
elseif (path.getextension(file) == ".rc") then
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('$(OBJDIR)/%s.res: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
|
|
|
|
_p('\t@echo $(notdir $<)')
|
|
|
|
_p('\t$(SILENT) windres $< -O coff -o $@ $(RESFLAGS)')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('')
|
2009-04-11 11:33:32 +00:00
|
|
|
|
|
|
|
-- include the dependencies, built by GCC (with the -MMD flag)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('-include $(OBJECTS:%%.o=%%.d)')
|
2009-04-11 11:33:32 +00:00
|
|
|
end
|
2009-04-23 18:26:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write a block of configuration settings.
|
|
|
|
--
|
|
|
|
|
|
|
|
function premake.gmake_cpp_config(cfg)
|
|
|
|
local cc = premake[_OPTIONS.cc]
|
|
|
|
local platform = cc.platforms[cfg.platform or "Native"].suffix
|
|
|
|
|
|
|
|
_p('ifeq ($(config),%s%s)', _MAKE.esc(cfg.name:lower()), platform)
|
|
|
|
_p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory))
|
|
|
|
_p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name))
|
|
|
|
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))
|
|
|
|
_p(' DEFINES += %s', table.concat(cc.getdefines(cfg.defines), " "))
|
|
|
|
_p(' INCLUDES += %s', table.concat(cc.getincludedirs(cfg.includedirs), " "))
|
|
|
|
_p(' CPPFLAGS += %s $(DEFINES) $(INCLUDES)', cc.getcppflags(cfg))
|
|
|
|
_p(' CFLAGS += $(CPPFLAGS) $(ARCH) %s', table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " "))
|
|
|
|
_p(' CXXFLAGS += $(CFLAGS) %s', table.concat(cc.getcxxflags(cfg), " "))
|
|
|
|
_p(' LDFLAGS += %s', table.concat(table.join(cc.getldflags(cfg), cc.getlinkflags(cfg), cfg.linkoptions), " "))
|
|
|
|
_p(' RESFLAGS += $(DEFINES) $(INCLUDES) %s', table.concat(table.join(cc.getdefines(cfg.resdefines), cc.getincludedirs(cfg.resincludedirs), cfg.resoptions), " "))
|
|
|
|
_p(' LDDEPS += %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "siblings", "fullpath")), " "))
|
|
|
|
|
|
|
|
if cfg.kind == "StaticLib" then
|
|
|
|
_p(' LINKCMD = ar -rcs $(TARGET) $(OBJECTS)')
|
|
|
|
else
|
|
|
|
_p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH)', iif(cfg.language == "C", "CC", "CXX"))
|
|
|
|
end
|
|
|
|
|
|
|
|
_p(' define PREBUILDCMDS')
|
|
|
|
if #cfg.prebuildcommands > 0 then
|
|
|
|
_p('\t@echo Running pre-build commands')
|
|
|
|
_p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
|
|
|
|
_p(' define PRELINKCMDS')
|
|
|
|
if #cfg.prelinkcommands > 0 then
|
|
|
|
_p('\t@echo Running pre-link commands')
|
|
|
|
_p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
|
|
|
|
_p(' define POSTBUILDCMDS')
|
|
|
|
if #cfg.postbuildcommands > 0 then
|
|
|
|
_p('\t@echo Running post-build commands')
|
|
|
|
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
|
|
|
|
end
|
|
|
|
_p(' endef')
|
|
|
|
|
|
|
|
_p('endif')
|
|
|
|
_p('')
|
|
|
|
end
|