This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Finished porting solutions to next-gen GMake action

  • Loading branch information...
1 parent 1652007 commit 3af8f54d850eb4dc52e385bd3bc800bc22fd4762 @starkos starkos committed May 8, 2012
Showing with 231 additions and 76 deletions.
  1. +15 −11 src/actions/make/_make.lua
  2. +165 −3 src/actions/make/make_cpp.lua
  3. +51 −62 src/actions/make/make_solution.lua
View
@@ -6,6 +6,7 @@
premake.make = { }
local make = premake.make
+ local solution = premake.solution
local project = premake5.project
--
@@ -38,7 +39,7 @@
if premake.isdotnetproject(prj) then
premake.generate(prj, makefile, make.generate_csharp)
else
- premake.generate(prj, makefile, make.generate_cpp)
+ premake.generate(prj, makefile, make.cpp.generate)
end
end,
@@ -53,21 +54,24 @@
--
--- Output the default configuration for a project.
--- @return
--- True if a default configuration is written, false if the project
--- does not contain any supported configurations.
+-- Write out the default configuration rule for a solution or project.
+-- @param target
+-- The solution or project object for which a makefile is being generated.
--
- function make.defaultconfig(prj)
- -- I don't actually loop, just getting the first config
- for cfg in project.eachconfig(prj) do
+ function make.defaultconfig(target)
+ -- find the configuration iterator function
+ local eachconfig = iif(target.project, project.eachconfig, solution.eachconfig)
+ local iter = eachconfig(target)
+
+ -- grab the first configuration and write the block
+ local cfg = iter()
+ if cfg then
_p('ifndef config')
_p(' config=%s', make.esc(cfg.shortname))
_p('endif')
_p('export config')
_p('')
- return true
end
end
@@ -111,8 +115,8 @@
count = count + 1
end
- if (searchprjs) then
- for _,prj in ipairs(sln.projects) do
+ if searchprjs then
+ for _, prj in ipairs(sln.projects) do
if prj.location == this.location then
count = count + 1
end
@@ -10,17 +10,179 @@
--
-
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
-
--
+ 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)
+
+ --[[
+ premake.gmake_cpp_header(prj, cc, platforms)
+
+ for _, platform in ipairs(platforms) do
+ for cfg in premake.eachconfig(prj, platform) do
+ premake.gmake_cpp_config(cfg, cc)
+ end
+ end
+
+ -- list intermediate files
+ _p('OBJECTS := \\')
+ for _, file in ipairs(prj.files) do
+ if path.iscppfile(file) then
+ _p('\t$(OBJDIR)/%s.o \\', _MAKE.esc(path.getbasename(file)))
+ end
+ end
+ _p('')
+
+ _p('RESOURCES := \\')
+ for _, file in ipairs(prj.files) do
+ if path.isresourcefile(file) then
+ _p('\t$(OBJDIR)/%s.res \\', _MAKE.esc(path.getbasename(file)))
+ end
+ end
+ _p('')
+
+ -- identify the shell type
+ _p('SHELLTYPE := msdos')
+ _p('ifeq (,$(ComSpec)$(COMSPEC))')
+ _p(' SHELLTYPE := posix')
+ _p('endif')
+ _p('ifeq (/bin,$(findstring /bin,$(SHELL)))')
+ _p(' SHELLTYPE := posix')
+ _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
+ _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
- function make.generate_cpp(prj)
+ -- clean target
+ _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('')
+
+ -- custom build step targets
+ _p('prebuild:')
+ _p('\t$(PREBUILDCMDS)')
+ _p('')
+
+ _p('prelink:')
+ _p('\t$(PRELINKCMDS)')
+ _p('')
+
+ -- precompiler header rule
+ cpp.pchrules(prj)
+
+ -- 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(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('')
+
+ -- 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
+--
+-- Write out the C++ makefile header.
+--
+
+ function cpp.header(prj)
+ -- a little help for the uninitiated
+ _p('# %s C/C++ project makefile autogenerated by Premake', premake.action.current().shortname)
+ _p('')
+
+ make.defaultconfig(prj)
+
+ _p('ifndef verbose')
+ _p(' SILENT = @')
+ _p('endif')
+ _p('')
+
+ --[[
+ _p('ifndef CC')
+ _p(' CC = %s', cc.cc)
+ _p('endif')
+ _p('')
+
+ _p('ifndef CXX')
+ _p(' CXX = %s', cc.cxx)
+ _p('endif')
+ _p('')
+
+ _p('ifndef AR')
+ _p(' AR = %s', cc.ar)
+ _p('endif')
+ _p('')
+
+ _p('ifndef RESCOMP')
+ _p(' ifdef WINDRES')
+ _p(' RESCOMP = $(WINDRES)')
+ _p(' else')
+ _p(' RESCOMP = windres')
+ _p(' endif')
+ _p('endif')
+ _p('')
+ --]]
+ end
+
-----------------------------------------------------------------------------
-- Everything below this point is a candidate for deprecation
Oops, something went wrong.

0 comments on commit 3af8f54

Please sign in to comment.