Commits

Andrew Gough  committed e10b292

Make GDC link order work on linux

  • Participants
  • Parent commits 6ebc454

Comments (0)

Files changed (2)

File src/actions/make/make_d.lua

 
 		_p('$(TARGET): $(FILES)')
 		_p('\t@echo Building %s...', prj.name)
-		_p('\t$(SILENT) $(BUILDCMD) $(FILES)')
+		_p('\t$(SILENT) $(BUILDCMD) $(FILES) $(LIBS)')
 		_p('\t$(POSTBUILDCMDS)')
 		_p('')
 
 		local deps = config.getlinks(cfg, "siblings", "fullpath")
 		_p('  LDDEPS    += %s', table.concat(make.esc(deps), " "))
 
-		_p('  BUILDCMD   = $(DC) $(DFLAGS) ' .. toolset.gettarget("$(TARGET)") .. ' $(INCLUDES) $(OBJECTS) $(ARCH) $(LIBS) $(LDFLAGS)')
+		_p('  BUILDCMD   = $(DC) $(DFLAGS) ' .. toolset.gettarget("$(TARGET)") .. ' $(INCLUDES) $(ARCH) $(LDFLAGS)')
 		_p('')
 	end
 

File src/tools/gdc.lua

 	{
 		ExtraWarnings   = "-w",
 		Optimize        = "-O2",
-		Symbols         = "-g",
+		Symbols         = "-g -fdebug",
 		SymbolsLikeC    = "-fdebug-c",
 		Deprecated      = "-fdeprecated",
 		Release         = "-frelease",
 	-- Returns a list of compiler flags, based on the supplied configuration.
 	--
 	function gdc.getflags(cfg)
-		local flags = gdc.getsysflags(cfg, 'flags')
+		local f = gdc.getsysflags(cfg, 'flags')
 
 		--table.insert( f, "-v" )
 		if cfg.kind == premake.STATICLIB then
-			table.insert( flags, "-static" )
+			table.insert( f, "-static" )
 		elseif cfg.kind == premake.SHAREDLIB then
 			table.insert( f, "-shared" )
 			if cfg.system ~= premake.WINDOWS then
-				table.insert( flags, "-fPIC" )
+				table.insert( f, "-fPIC" )
 			end
 		end
 
 		if premake.config.isdebugbuild( cfg ) then
-			table.insert( flags, "-debug" )
+			table.insert( f, flags.Symbols )
 		else
-			table.insert( flags, "-release" )
+			table.insert( f, flags.Release )
 		end
 
-		return flags
+		return f
 	end
 
 
 	-- Returns a list of linker flags for library names.
 	--
 
-	function gdc.getlinkflags(cfg)
-		local result = {}
-
-		for _, value in ipairs(premake.getlinks(cfg, "siblings", "object")) do
-			if (value.kind == "StaticLib") then
-				local pathstyle = premake.getpathstyle(value)
-				local namestyle = premake.getnamestyle(value)
-				local linktarget = premake.gettarget(value, "link",  pathstyle, namestyle, cfg.system)
-				local rebasedpath = path.rebase(linktarget.fullpath, value.location, cfg.location)
-				table.insert(result, rebasedpath)
-			elseif (value.kind == "SharedLib") then
-				table.insert(result, '-L-l' .. _MAKE.esc(value.linktarget.basename))
-			else
-				-- TODO When premake supports the creation of frameworks
-			end
-		end
-
-		for _, value in ipairs(premake.getlinks(cfg, "system", "basename")) do
-			if path.getextension(value) == ".framework" then
-				table.insert(result, '-L-framework -L' .. _MAKE.esc(path.getbasename(value)))
-			else
-				table.insert(result, '-L-l' .. _MAKE.esc(value))
-			end
-		end
-
-		return result
-	end
-
 	function gdc.getlinks(cfg)
 		local result = {}
 
 		local links = config.getlinks(cfg, "dependencies", "object")
+        if #links > 0 then
+            table.insert(result,"-Wl,--start-group" )
+        end
 		for _, link in ipairs(links) do
 			-- skip external project references, since I have no way
 			-- to know the actual output target path
 					-- name if one is present
 					table.insert(result, project.getrelative(cfg.project, linkinfo.abspath))
 				else
-					table.insert(result, "-L-l" .. linkinfo.basename)
+					table.insert(result, "-Wl,-l" .. linkinfo.basename)
 				end
 			end
 		end
+        if #links > 0 then
+            table.insert(result,"-Wl,--end-group" )
+        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))
+				table.insert(result, "-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)
+				table.insert(result, "-Wl,-l" .. link)
 			end
 		end
 
 	-- Decorate include file search paths for the gdc command line.
 	--
 
-	function gdc.getincludedirs(includedirs)
-		local result = { }
-		for _,dir in ipairs(includedirs) do
-			table.insert(result, "-I" .. _MAKE.esc(dir))
+	function gdc.getincludedirs(cfg)
+		local result = {}
+		for _, dir in ipairs(cfg.includedirs) do
+			table.insert(result, "-I" .. project.getrelative(cfg.project, dir))
 		end
 		return result
 	end