Commits

Andrew Gough  committed 6ebc454

Make GDC work on MSYS/gmake

  • Participants
  • Parent commits 9c49aa9

Comments (0)

Files changed (9)

File src/actions/make/_make.lua

 		valid_tools     = {
 			cc     = { "gcc"   },
 			dotnet = { "mono", "msnet", "pnet" },
-			dc     = { "dmd" },
+			dc     = { "dmd", "gdc" },
 		},
 
 		onsolution = function(sln)

File src/actions/make/make_d.lua

 
     function d.generate(prj)
 
---        table_print( prj )
+		table_print( premake.tools.gdc )
 
         d.header(prj)
 
 
 	function d.config(cfg)
 
-		local toolset = premake.tools[cfg.toolset or "dmd"]
+		local toolset = premake.gettool(cfg)
+--		local toolset = premake.tools[cfg.toolset or "dmd"]
 		if not toolset then
 			error("Invalid toolset '" + cfg.toolset + "'")
 		end
 				if type (value) == "table" and not done [value] then
 					done [value] = true
 					io.stdout:write(string.format("[%s] => table\n", tostring (key)));
-					io.stdout:write(string.rep (" ", indent+4)) -- indent it
+					io.stdout:write(string.rep (" ", indent)) -- indent it
 					io.stdout:write("(\n");
-					table_print (value, indent + 7, done)
-					io.stdout:write(string.rep (" ", indent+4)) -- indent it
+					table_print (value, indent + 4, done)
+					io.stdout:write(string.rep (" ", indent)) -- indent it
 					io.stdout:write(")\n");
 				else
 					io.stdout:write(string.format("[%s] => %s\n",

File src/actions/vstudio/vs200x_vcproj.lua

 		
 					-- Build event blocks --
 					elseif block == "VCPreBuildEventTool" then
-						vc200x.buildstepsblock("VCPreBuildEventTool", cfg.prebuildcommands)
+						buildstepsblock("VCPreBuildEventTool", cfg.prebuildcommands)
 					elseif block == "VCPreLinkEventTool" then
-						vc200x.buildstepsblock("VCPreLinkEventTool", cfg.prelinkcommands)
+						buildstepsblock("VCPreLinkEventTool", cfg.prelinkcommands)
 					elseif block == "VCPostBuildEventTool" then
-						vc200x.buildstepsblock("VCPostBuildEventTool", cfg.postbuildcommands)
+						buildstepsblock("VCPostBuildEventTool", cfg.postbuildcommands)
 					-- End build event blocks --
 					
 					-- Xbox 360 custom sections --

File src/base/api.lua

 		scope = "config",
 		kind = "string",
 		allowed = {
-			"gcc"
+			"gcc",
+			"dmd",
+			"gdc"
 		},
 	}
 

File src/base/project.lua

 --
 
 	function premake.gettool(cfg)
-		if premake.iscppproject(cfg) then
+		local prj = cfg.project or cfg
+		
+		if premake.iscppproject(prj) then
 			if _OPTIONS.cc then
 				return premake[_OPTIONS.cc]
 			end
 				return premake[action.valid_tools.cc[1]]
 			end
 			return premake.gcc
-		elseif premake.isdproject(cfg) then
-            if _OPTIONS.dc then
-                return premake[ _OPTIONS.dc ]
+		elseif premake.isdproject(prj) then
+            if _OPTIONS.dc and premake.tools[_OPTIONS.dc] then
+                return premake.tools[ _OPTIONS.dc ]
             end
 			local action = premake.action.current()
-			if action.valid_tools then
-				return premake[action.valid_tools.dc[1]]
+			if action.valid_tools and premake.tools[action.valid_tools.dc[1]] then
+				return premake.tools[action.valid_tools.dc[1]]
 			end
 			return premake.tools.dmd
 		else
 --
 
 	function premake.isdproject(prj)
-		return (prj.language == "D")
+		local language = prj.language or prj.solution.language
+		return (language == "D")
 	end
 	

File src/host/os_chdir.c

 
 #include "premake.h"
 
-
 int os_chdir(lua_State* L)
 {
 	int z;

File src/host/os_uuid.c

 
 	lua_pushstring(L, uuid);
 	return 1;
+
 }

File src/tools/dmd.lua

+
 --
 -- dmd.lua
--- Provides GCC-specific configuration strings.
--- Copyright (c) 2002-2011 Jason Perkins and the Premake project
+-- Provides DMD-specific configuration strings.
 --
 
+	premake.tools.dmd = { }
+	local dmd = {}
 
-	premake.tools.dmd = { }
-	local dmd = premake.tools.dmd
 	local project = premake5.project
 	local config = premake5.config
-
-	premake.dmd = dmd
+	
 --
 -- Set default tools
 --
-
-	dmd.dc    = premake.DMD
-	dmd.ar    = "ar"
-
+		dmd.optlink = {}
+		dmd.gcc = {}
 
 --
--- Translation of Premake flags into GCC flags
+-- Translation of Premake flags into DMD flags
 --
 
 	local flags =
 		SymbolsLikeC    = "-gc",
 		Release         = "-release",
 		Documentation   = "-D",
-		PIC             = "-fPIC",
+-- GCC:		PIC             = "-fPIC",
 		Inline          = "-inline",
 		GenerateHeader  = "-H",
 		GenerateMap     = "-map",
 	}
 
 
+-- /////////////////////////////////////////////////////////////////////////
+-- DMD + GCC toolchain						
+-- /////////////////////////////////////////////////////////////////////////
+
 --
--- DMD flags
+-- dmd.gcc flags
 --
 
-	dmd.sysflags = 
+	dmd.gcc.sysflags = 
 	{
 		universal = {
 			flags    = "",
 		}
 	}
 
-	function dmd.getsysflags(cfg, field)
+	function dmd.gcc.getsysflags(cfg, field)
 		local result = {}
 
 		-- merge in system-level flags
-		local system = dmd.sysflags[cfg.system]
+		local system = dmd.gcc.sysflags[cfg.system]
 		if system then
 			result = table.join(result, system[field])
 		end
 
 		-- merge in architecture-level flags
-		local arch = dmd.sysflags[cfg.architecture]
+		local arch = dmd.gcc.sysflags[cfg.architecture]
 		if arch then
 			result = table.join(result, arch[field])
 		end
 -- Returns the target name specific to compiler
 --
 
-	function dmd.gettarget(name)
+	function dmd.gcc.gettarget(name)
 		return "-of" .. name
 	end
 
 -- Returns the object directory name specific to compiler
 --
 
-	function dmd.getobjdir(name)
+	function dmd.gcc.getobjdir(name)
 		return "-od" .. name
 	end
 
 -- Returns a list of compiler flags, based on the supplied configuration.
 --
 
-	function dmd.getflags(cfg)
-		local flags = dmd.getsysflags(cfg, 'flags')
+	function dmd.gcc.getflags(cfg)
+		local flags = dmd.gcc.getsysflags(cfg, 'flags')
 
 		--table.insert( f, "-v" )
 		if cfg.kind == premake.STATICLIB then
 	-- Returns a list of linker flags, based on the supplied configuration.
 	--
 
-	function dmd.getldflags(cfg)
+	function dmd.gcc.getldflags(cfg)
 		local flags = {}
 
-		local sysflags = dmd.getsysflags(cfg, 'ldflags')
+		local sysflags = dmd.gcc.getsysflags(cfg, 'ldflags')
 		flags = table.join(flags, sysflags)
 
 		return flags
 	-- Return a list of library search paths.
 	--
 
-	function dmd.getlibdirflags(cfg)
+	function dmd.gcc.getlibdirflags(cfg)
 		local result = {}
 
 		for _, value in ipairs(premake.getlinks(cfg, "all", "directory")) do
 	-- Returns a list of linker flags for library names.
 	--
 
-	function dmd.getlinks(cfg)
+	function dmd.gcc.getlinks(cfg)
 		local result = {}
 
 		local links = config.getlinks(cfg, "dependencies", "object")
 
 
 	--
-	-- Decorate defines for the DMD command line.
+	-- Decorate defines for the dmd.gcc command line.
 	--
 
-	function dmd.getdefines(defines)
+	function dmd.gcc.getdefines(defines)
 		local result = { }
 		for _,def in ipairs(defines) do
 			table.insert(result, '-version=' .. def)
 	-- Decorate include file search paths for the GCC command line.
 	--
 
-	function dmd.getincludedirs(cfg)
+	function dmd.gcc.getincludedirs(cfg)
 		local result = {}
 		for _, dir in ipairs(cfg.includedirs) do
 			table.insert(result, "-I" .. project.getrelative(cfg.project, dir))
 		return result
 	end
 
+
+-- /////////////////////////////////////////////////////////////////////////
+-- DMD + OPTLINK toolchain						
+-- /////////////////////////////////////////////////////////////////////////
+
+	dmd.optlink.sysflags = 
+	{
+		universal = {
+			flags    = "",
+			ldflags  = "", 
+		},
+		x32 = { 
+			flags    = "",
+			ldflags  = "", 
+		},
+		x64 = { 
+			flags    = "",
+			ldflags  = "",
+		}
+	}
+
+	function dmd.optlink.getsysflags(cfg, field)
+		local result = {}
+
+		-- merge in system-level flags
+		local system = dmd.optlink.sysflags[cfg.system]
+		if system then
+			result = table.join(result, system[field])
+		end
+
+		-- merge in architecture-level flags
+		local arch = dmd.optlink.sysflags[cfg.architecture]
+		if arch then
+			result = table.join(result, arch[field])
+		end
+
+		return result
+	end
+
+	-- gettarget is common
+	dmd.optlink.gettarget = dmd.gcc.gettarget
+	-- getobjdir is common
+	dmd.optlink.getobjdir = dmd.gcc.getobjdir
+	-- getdefines is common
+	dmd.optlink.getdefines = dmd.gcc.getdefines
+
+	--
+	-- Returns a list of compiler flags, based on the supplied configuration.
+	--
+
+	function dmd.optlink.getflags(cfg)
+		local flags = dmd.optlink.getsysflags(cfg, 'flags')
+
+		--table.insert( f, "-v" )
+		if cfg.kind == premake.STATICLIB then
+			table.insert( flags, "-lib" )
+		elseif cfg.kind == premake.SHAREDLIB then
+			table.insert( flags, "-shared" )
+			if cfg.system ~= premake.WINDOWS then
+				table.insert( flags, "-fPIC" )
+			end
+		end
+
+		if premake.config.isdebugbuild( cfg ) then
+			table.insert( flags, "-debug" )
+		else
+			table.insert( flags, "-release" )
+		end
+
+		return flags
+	end
+
+
+	--
+	-- Returns a list of linker flags, based on the supplied configuration.
+	--
+
+	function dmd.optlink.getldflags(cfg)
+		local flags = {}
+
+		local sysflags = dmd.optlink.getsysflags(cfg, 'ldflags')
+		flags = table.join(flags, sysflags)
+
+		return flags
+	end
+
+
+	--
+	-- Return a list of library search paths.
+	--
+
+	function dmd.optlink.getlibdirflags(cfg)
+		local result = {}
+
+--		for _, value in ipairs(premake.getlinks(cfg, "all", "directory")) do
+--			table.insert(result, '-L-L' .. _MAKE.esc(value))
+--		end
+
+		return result
+	end
+
+	--
+	-- Returns a list of linker flags for library names.
+	--
+
+	function dmd.optlink.getlinks(cfg)
+		local result = {}
+
+		local links = config.getlinks(cfg, "dependencies", "object")
+		for _, link in ipairs(links) do
+			-- skip external project references, since I have no way
+			-- to know the actual output target path
+			if not link.project.externalname then
+				local linkinfo = config.getlinkinfo(link)
+				if link.kind == premake.STATICLIB then
+					table.insert(result, project.getrelative(cfg.project, linkinfo.abspath))
+				end
+			end
+		end
+
+		-- The "-l" flag is fine for system libraries
+		links = config.getlinks(cfg, "system", "basename")
+		for _, link in ipairs(links) do
+			if path.isobjectfile(link) then
+				table.insert(result, link)
+			elseif path.hasextension(link, premake.systems[cfg.system].staticlib.extension) then
+				table.insert(result, link)
+			end
+		end
+
+		return result
+
+	end
+
+	--
+	-- Decorate include file search paths for the GCC command line.
+	--
+
+	function dmd.optlink.getincludedirs(cfg)
+		local result = {}
+		for _, dir in ipairs(cfg.includedirs) do
+			table.insert(result, "-I" .. project.getrelative(cfg.project, dir))
+		end
+		return result
+	end
+
+
+	-- if we are compiling on windows, we need to specialise to OPTLINK as the linker
+-- OR!!!			if cfg.system ~= premake.WINDOWS then
+	if string.match( os.getversion().description, "Windows" ) ~= nil then
+		premake.tools.dmd = dmd.optlink
+		dmd.sysflags = dmd.optlink.sysflags
+	else
+		premake.tools.dmd = dmd.gcc
+		dmd.sysflags = dmd.gcc.sysflags
+	end
+	

File src/tools/gdc.lua

 	-- Copyright (c) 2002-2011 Jason Perkins and the Premake project
 	--
 
+	premake.tools.gdc = { }
 
-	premake.gdc = { }
-
+	local gdc = premake.tools.gdc
+	local project = premake5.project
+	local config = premake5.config
+	
 
 	--
 	-- Set default tools
 	--
 
-	premake.gdc.dc    = "gdc"
+	gdc.dc    = "gdc"
 
 
 	--
 	-- Map platforms to flags
 	--
 
-	premake.gdc.platforms = 
+	gdc.sysflags = 
 	{
-		Native = {
+		universal = {
 			flags    = "",
 			ldflags  = "", 
 		},
 		}
 	}
 
-	local platforms = premake.gdc.platforms
+	local sysflags = gdc.sysflags
 
 	--
 	-- Returns the target name specific to compiler
 	--
 
-	function premake.gdc.gettarget(name)
+	function gdc.gettarget(name)
 		return "-o " .. name
 	end
 
 	-- Returns the object directory name specific to compiler
 	--
 
-	function premake.gdc.getobjdir(name)
+	function gdc.getobjdir(name)
 		return "-fod=" .. name
 	end
 
+	function gdc.getsysflags(cfg, field)
+		local result = {}
+
+		-- merge in system-level flags
+		local system = sysflags[cfg.system]
+		if system then
+			result = table.join(result, system[field])
+		end
+
+		-- merge in architecture-level flags
+		local arch = sysflags[cfg.architecture]
+		if arch then
+			result = table.join(result, arch[field])
+		end
+
+		return result
+	end
+
+
 
 	--
 	-- Returns a list of compiler flags, based on the supplied configuration.
 	--
-
-	function premake.gdc.getflags(cfg)
-		local f = table.translate(cfg.flags, flags)
-
-		table.insert(f, platforms[cfg.platform].flags)
+	function gdc.getflags(cfg)
+		local flags = gdc.getsysflags(cfg, 'flags')
 
 		--table.insert( f, "-v" )
-		if cfg.kind == "StaticLib" then
-			table.insert( f, "-static" )
-		elseif cfg.kind == "SharedLib" and cfg.system ~= "windows" then
-			table.insert( f, "-fPIC -shared" )
+		if cfg.kind == premake.STATICLIB then
+			table.insert( flags, "-static" )
+		elseif cfg.kind == premake.SHAREDLIB then
+			table.insert( f, "-shared" )
+			if cfg.system ~= premake.WINDOWS then
+				table.insert( flags, "-fPIC" )
+			end
 		end
 
 		if premake.config.isdebugbuild( cfg ) then
-			table.insert( f, "-fdebug" )
+			table.insert( flags, "-debug" )
 		else
-			table.insert( f, "-frelease" )
+			table.insert( flags, "-release" )
 		end
-		return f
+
+		return flags
 	end
 
+
 	--
 	-- Returns a list of linker flags, based on the supplied configuration.
 	--
 
-	function premake.gdc.getldflags(cfg)
+	function gdc.getldflags(cfg)
 		local result = {}
 
-		table.insert(result, platforms[cfg.platform].ldflags)
+		local sysflags = gdc.getsysflags(cfg, 'ldflags')
+		table.join(result, sysflags)
 
 		return result
 	end
 	-- Return a list of library search paths.
 	--
 
-	function premake.gdc.getlibdirflags(cfg)
+	function gdc.getlibdirflags(cfg)
 		local result = {}
 
 		for _, value in ipairs(premake.getlinks(cfg, "all", "directory")) do
 	-- Returns a list of linker flags for library names.
 	--
 
-	function premake.gdc.getlinkflags(cfg)
+	function gdc.getlinkflags(cfg)
 		local result = {}
 
 		for _, value in ipairs(premake.getlinks(cfg, "siblings", "object")) do
 		return result
 	end
 
+	function gdc.getlinks(cfg)
+		local result = {}
+
+		local links = config.getlinks(cfg, "dependencies", "object")
+		for _, link in ipairs(links) do
+			-- skip external project references, since I have no way
+			-- to know the actual output target path
+			if not link.project.externalname then
+				local linkinfo = config.getlinkinfo(link)
+				if link.kind == premake.STATICLIB then
+					-- Don't use "-l" flag when linking static libraries; instead use 
+					-- path/libname.a to avoid linking a shared library of the same
+					-- name if one is present
+					table.insert(result, project.getrelative(cfg.project, linkinfo.abspath))
+				else
+					table.insert(result, "-L-l" .. linkinfo.basename)
+				end
+			end
+		end
+
+		-- The "-l" flag is fine for system libraries
+		links = config.getlinks(cfg, "system", "basename")
+		for _, link in ipairs(links) do
+			if path.isframework(link) then
+				table.insert(result, "-L-framework " .. path.getbasename(link))
+			elseif path.isobjectfile(link) then
+				table.insert(result, link)
+			elseif path.hasextension(link, premake.systems[cfg.system].staticlib.extension) then
+				table.insert(result, link)
+			else
+				table.insert(result, "-L-l" .. link)
+			end
+		end
+
+		return result
+
+	end
+
 
 	--
 	-- Decorate defines for the gdc command line.
 	--
 
-	function premake.gdc.getdefines(defines)
+	function gdc.getdefines(defines)
 		local result = { }
 		for _,def in ipairs(defines) do
 			table.insert(result, '-fversion=' .. def)
 	-- Decorate include file search paths for the gdc command line.
 	--
 
-	function premake.gdc.getincludedirs(includedirs)
+	function gdc.getincludedirs(includedirs)
 		local result = { }
 		for _,dir in ipairs(includedirs) do
 			table.insert(result, "-I" .. _MAKE.esc(dir))