Merge pull request #623 from h0tw1r3/master

Improve cross compile support [Jeffrey Clark]
This commit is contained in:
Miodrag Milanović 2016-02-15 19:55:52 +01:00
commit 2b781d87b1
7 changed files with 234 additions and 60 deletions

View File

@ -69,12 +69,13 @@
# SDL_INSTALL_ROOT = /opt/sdl2
# SDL_FRAMEWORK_PATH = $(HOME)/Library/Frameworks
# SDL_LIBVER = sdl
# MACOSX_USE_LIBSDL = 1
# USE_LIBSDL = 1
# CYGWIN_BUILD = 1
# BUILDDIR = build
# TARGETOS = windows
# CROSS_BUILD = 1
# TOOLCHAIN =
# OVERRIDE_CC = cc
# OVERRIDE_CXX = c++
# OVERRIDE_LD = ld
@ -270,9 +271,9 @@ WINDRES := $(MINGW32)/bin/windres
endif
else
ifeq ($(ARCHITECTURE),_x64)
WINDRES := x86_64-w64-mingw32-windres
WINDRES := $(word 1,$(TOOLCHAIN) x86_64-w64-mingw32-)windres
else
WINDRES := i686-w64-mingw32-windres
WINDRES := $(word 1,$(TOOLCHAIN) i686-w64-mingw32-)windres
endif
endif
@ -407,6 +408,9 @@ endif
PARAMS+= --distro=$(DISTRO)
ifdef TOOLCHAIN
PARAMS += --TOOLCHAIN='$(TOOLCHAIN)'
endif
ifdef OVERRIDE_CC
PARAMS += --CC='$(OVERRIDE_CC)'
ifndef CROSS_BUILD
@ -627,8 +631,8 @@ ifdef SDL_FRAMEWORK_PATH
PARAMS += --SDL_FRAMEWORK_PATH='$(SDL_FRAMEWORK_PATH)'
endif
ifdef MACOSX_USE_LIBSDL
PARAMS += --MACOSX_USE_LIBSDL='$(MACOSX_USE_LIBSDL)'
ifdef USE_LIBSDL
PARAMS += --USE_LIBSDL='$(USE_LIBSDL)'
endif
ifdef LDOPTS
@ -777,12 +781,12 @@ endif
ifeq ($(OS),windows)
ifeq (posix,$(SHELLTYPE))
GCC_VERSION := $(shell $(subst @,,$(CC)) -dumpversion 2> /dev/null)
CLANG_VERSION := $(shell $(subst @,,$(CC)) --version 2> /dev/null| head -n 1 | grep clang | sed "s/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$$/\1/" | head -n 1)
GCC_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) -dumpversion 2> /dev/null)
CLANG_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) --version 2> /dev/null| head -n 1 | grep clang | sed "s/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$$/\1/" | head -n 1)
PYTHON_AVAILABLE := $(shell $(PYTHON) --version > /dev/null 2>&1 && echo python)
else
GCC_VERSION := $(shell $(subst @,,$(CC)) -dumpversion 2> NUL)
CLANG_VERSION := $(shell $(subst @,,$(CC)) --version 2> NUL| head -n 1 | grep clang | sed "s/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$$/\1/" | head -n 1)
GCC_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) -dumpversion 2> NUL)
CLANG_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) --version 2> NUL| head -n 1 | grep clang | sed "s/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$$/\1/" | head -n 1)
PYTHON_AVAILABLE := $(shell $(PYTHON) --version > NUL 2>&1 && echo python)
endif
ifdef MSBUILD
@ -799,9 +803,9 @@ MSBUILD_PARAMS += /p:Platform=win32
endif
endif
else
GCC_VERSION := $(shell $(subst @,,$(CC)) -dumpversion 2> /dev/null)
GCC_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) -dumpversion 2> /dev/null)
ifneq ($(OS),solaris)
CLANG_VERSION := $(shell $(subst @,,$(CC)) --version 2> /dev/null | head -n 1 | grep -e 'version [0-9]\.[0-9]\(\.[0-9]\)\?' -o | grep -e '[0-9]\.[0-9]\(\.[0-9]\)\?' -o | tail -n 1)
CLANG_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) --version 2> /dev/null | head -n 1 | grep -e 'version [0-9]\.[0-9]\(\.[0-9]\)\?' -o | grep -e '[0-9]\.[0-9]\(\.[0-9]\)\?' -o | tail -n 1)
endif
PYTHON_AVAILABLE := $(shell $(PYTHON) --version > /dev/null 2>&1 && echo python)
endif
@ -1236,10 +1240,13 @@ $(GENIE): $(GENIE_SRC)
3rdparty/genie/src/hosts/%.c:
clean:
.PHONY: genieclean
genieclean:
$(SILENT) $(MAKE) $(MAKEPARAMS) -C 3rdparty/genie/build/gmake.$(GENIEOS) -f genie.make clean
clean: genieclean
@echo Cleaning...
-@rm -rf $(BUILDDIR)
$(SILENT) $(MAKE) $(MAKEPARAMS) -C 3rdparty/genie/build/gmake.$(GENIEOS) -f genie.make clean
$(SILENT) $(MAKE) -C $(SRC)/devices/cpu/m68000 clean
GEN_FOLDERS := $(GENDIR)/$(TARGET)/layout/ $(GENDIR)/$(TARGET)/$(SUBTARGET)/
@ -1257,8 +1264,10 @@ endif
$(GEN_FOLDERS):
-$(call MKDIR,$@)
genie: $(GENIE)
generate: \
$(GENIE) \
genie \
$(GEN_FOLDERS) \
$(patsubst $(SRC)/%.lay,$(GENDIR)/%.lh,$(LAYOUTS)) \
$(SRC)/devices/cpu/m68000/m68kops.cpp

View File

@ -197,6 +197,11 @@ newoption {
description = "LD replacement",
}
newoption {
trigger = "TOOLCHAIN",
description = "Toolchain prefix"
}
newoption {
trigger = "PROFILE",
description = "Enable profiling.",
@ -427,6 +432,10 @@ if(_OPTIONS["USE_BGFX"]~=nil) then
USE_BGFX = tonumber(_OPTIONS["USE_BGFX"])
end
if(_OPTIONS["TOOLCHAIN"] == nil) then
_OPTIONS['TOOLCHAIN'] = ""
end
GEN_DIR = MAME_BUILD_DIR .. "generated/"
if (_OPTIONS["target"] == nil) then return false end
@ -1300,10 +1309,7 @@ else
startproject (_OPTIONS["subtarget"])
end
mainProject(_OPTIONS["target"],_OPTIONS["subtarget"])
if (_OPTIONS["STRIP_SYMBOLS"]=="1") then
strip()
end
strip()
if _OPTIONS["with-tools"] then
group "tools"

View File

@ -280,6 +280,11 @@ end
buildoptions {
"-Wno-enum-conversion",
}
if _OPTIONS["targetos"]=="macosx" then
buildoptions_c {
"-Wno-unknown-attributes",
}
end
end
configuration { }

View File

@ -54,14 +54,20 @@ function maintargetosdoptions(_target,_subtarget)
end
if _OPTIONS["targetos"]=="windows" then
if _OPTIONS["SDL_LIBVER"]=="sdl2" then
links {
"SDL2.dll",
}
if _OPTIONS["USE_LIBSDL"]~="1" then
if _OPTIONS["SDL_LIBVER"]=="sdl2" then
links {
"SDL2.dll",
}
else
links {
"SDL.dll",
}
end
else
links {
"SDL.dll",
}
local str = backtick(sdlconfigcmd() .. " --libs | sed 's/ -lSDLmain//'")
addlibfromstring(str)
addoptionsfromstring(str)
end
links {
"psapi",
@ -93,6 +99,11 @@ function maintargetosdoptions(_target,_subtarget)
configuration { "mingw*" or "vs*" }
targetprefix "sdl"
if USE_BGFX == 1 then
links {
"psapi"
}
end
configuration { }
end
@ -100,7 +111,7 @@ end
function sdlconfigcmd()
if not _OPTIONS["SDL_INSTALL_ROOT"] then
return _OPTIONS["SDL_LIBVER"] .. "-config"
return _OPTIONS['TOOLCHAIN'] .. "pkg-config " .. _OPTIONS["SDL_LIBVER"]
else
return path.join(_OPTIONS["SDL_INSTALL_ROOT"],"bin",_OPTIONS["SDL_LIBVER"]) .. "-config"
end
@ -192,16 +203,16 @@ if not _OPTIONS["SDL_FRAMEWORK_PATH"] then
end
newoption {
trigger = "MACOSX_USE_LIBSDL",
description = "Use SDL library on OS (rather than framework)",
trigger = "USE_LIBSDL",
description = "Use SDL library on OS (rather than framework/dll)",
allowed = {
{ "0", "Use framework" },
{ "0", "Use framework/dll" },
{ "1", "Use library" },
},
}
if not _OPTIONS["MACOSX_USE_LIBSDL"] then
_OPTIONS["MACOSX_USE_LIBSDL"] = "0"
if not _OPTIONS["USE_LIBSDL"] then
_OPTIONS["USE_LIBSDL"] = "0"
end
@ -255,7 +266,7 @@ if BASE_TARGETOS=="unix" then
"-weak_framework Metal",
}
end
if _OPTIONS["MACOSX_USE_LIBSDL"]~="1" then
if _OPTIONS["USE_LIBSDL"]~="1" then
linkoptions {
"-F" .. _OPTIONS["SDL_FRAMEWORK_PATH"],
}
@ -269,7 +280,7 @@ if BASE_TARGETOS=="unix" then
}
end
else
local str = backtick(sdlconfigcmd() .. " --libs | sed 's/-lSDLmain//'")
local str = backtick(sdlconfigcmd() .. " --libs --static | sed 's/-lSDLmain//'")
addlibfromstring(str)
addoptionsfromstring(str)
end
@ -529,14 +540,20 @@ if _OPTIONS["with-tools"] then
}
if _OPTIONS["targetos"] == "windows" then
if _OPTIONS["SDL_LIBVER"] == "sdl2" then
links {
"SDL2.dll",
}
if _OPTIONS["USE_LIBSDL"]~="1" then
if _OPTIONS["SDL_LIBVER"] == "sdl2" then
links {
"SDL2.dll",
}
else
links {
"SDL.dll",
}
end
else
links {
"SDL.dll",
}
local str = backtick(sdlconfigcmd() .. " --libs | sed 's/ -lSDLmain//'")
addlibfromstring(str)
addoptionsfromstring(str)
end
links {
"psapi",
@ -553,6 +570,13 @@ if _OPTIONS["with-tools"] then
MAME_DIR .. "src/osd/sdl/SDLMain_tmpl.mm",
}
end
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
end
@ -594,4 +618,6 @@ if _OPTIONS["targetos"] == "macosx" and _OPTIONS["with-tools"] then
files {
MAME_DIR .. "src/osd/sdl/aueffectutil.mm",
}
strip()
end

View File

@ -81,7 +81,7 @@ if BASE_TARGETOS=="unix" then
"SDLMAME_UNIX",
}
if _OPTIONS["targetos"]=="macosx" then
if _OPTIONS["MACOSX_USE_LIBSDL"]~="1" then
if _OPTIONS["USE_LIBSDL"]~="1" then
buildoptions {
"-F" .. _OPTIONS["SDL_FRAMEWORK_PATH"],
}

View File

@ -50,6 +50,13 @@ files {
MAME_DIR .. "src/tools/romcmp.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- chdman
--------------------------------------------------
@ -104,6 +111,13 @@ files {
MAME_DIR .. "src/version.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- jedutil
--------------------------------------------------
@ -145,6 +159,13 @@ files {
MAME_DIR .. "src/tools/jedutil.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- unidasm
--------------------------------------------------
@ -201,6 +222,12 @@ files {
MAME_DIR .. "src/emu/emucore.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- ldresample
@ -255,6 +282,13 @@ files {
MAME_DIR .. "src/tools/ldresample.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- ldverify
--------------------------------------------------
@ -308,6 +342,13 @@ files {
MAME_DIR .. "src/tools/ldverify.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- regrep
--------------------------------------------------
@ -349,6 +390,13 @@ files {
MAME_DIR .. "src/tools/regrep.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- srcclean
---------------------------------------------------
@ -390,6 +438,13 @@ files {
MAME_DIR .. "src/tools/srcclean.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- src2html
--------------------------------------------------
@ -431,6 +486,13 @@ files {
MAME_DIR .. "src/tools/src2html.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- split
--------------------------------------------------
@ -483,6 +545,13 @@ files {
MAME_DIR .. "src/tools/split.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- pngcmp
--------------------------------------------------
@ -524,6 +593,13 @@ files {
MAME_DIR .. "src/tools/pngcmp.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- nltool
--------------------------------------------------
@ -578,6 +654,13 @@ files {
MAME_DIR .. "src/lib/netlist/prg/nltool.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- nlwav
--------------------------------------------------
@ -610,6 +693,13 @@ files {
MAME_DIR .. "src/lib/netlist/prg/nlwav.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- castool
--------------------------------------------------
@ -664,6 +754,13 @@ files {
MAME_DIR .. "src/tools/castool.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- floptool
--------------------------------------------------
@ -719,6 +816,13 @@ files {
MAME_DIR .. "src/tools/floptool.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()
--------------------------------------------------
-- imgtool
--------------------------------------------------
@ -822,3 +926,10 @@ files {
MAME_DIR .. "src/tools/imgtool/modules/bml3.cpp",
MAME_DIR .. "src/tools/imgtool/modules/hp48.cpp",
}
configuration { "mingw*" or "vs*" }
targetextension ".exe"
configuration { }
strip()

View File

@ -4,6 +4,11 @@
--
local naclToolchain = ""
local toolchainPrefix = ""
if _OPTIONS['TOOLCHAIN'] then
toolchainPrefix = _OPTIONS["TOOLCHAIN"]
end
newoption {
trigger = "gcc",
@ -204,15 +209,18 @@ function toolchain(_buildDir, _subDir)
if not os.getenv("MINGW32") then
print("Set MINGW32 envrionment variable.")
end
premake.gcc.cc = "$(MINGW32)/bin/i686-w64-mingw32-gcc"
premake.gcc.cxx = "$(MINGW32)/bin/i686-w64-mingw32-g++"
if not toolchainPrefix then
toolchainPrefix = "$(MINGW32)/bin/i686-w64-mingw32-"
end
premake.gcc.cc = toolchainPrefix .. "gcc"
premake.gcc.cxx = toolchainPrefix .. "g++"
-- work around GCC 4.9.2 not having proper linker for LTO=1 usage
local version_4_ar = str_to_version(_OPTIONS["gcc_version"])
if (version_4_ar < 50000) then
premake.gcc.ar = "$(MINGW32)/bin/ar"
premake.gcc.ar = toolchainPrefix .. "ar"
end
if (version_4_ar >= 50000) then
premake.gcc.ar = "$(MINGW32)/bin/gcc-ar"
premake.gcc.ar = toolchainPrefix .. "gcc-ar"
end
location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-mingw32-gcc")
end
@ -221,20 +229,22 @@ function toolchain(_buildDir, _subDir)
if not os.getenv("MINGW64") then
print("Set MINGW64 envrionment variable.")
end
premake.gcc.cc = "$(MINGW64)/bin/x86_64-w64-mingw32-gcc"
premake.gcc.cxx = "$(MINGW64)/bin/x86_64-w64-mingw32-g++"
if not toolchainPrefix then
toolchainPrefix = "$(MINGW64)/bin/x86_64-w64-mingw32-"
end
premake.gcc.cc = toolchainPrefix .. "gcc"
premake.gcc.cxx = toolchainPrefix .. "g++"
-- work around GCC 4.9.2 not having proper linker for LTO=1 usage
local version_4_ar = str_to_version(_OPTIONS["gcc_version"])
if (version_4_ar < 50000) then
premake.gcc.ar = "$(MINGW64)/bin/ar"
premake.gcc.ar = toolchainPrefix .. "ar"
end
if (version_4_ar >= 50000) then
premake.gcc.ar = "$(MINGW64)/bin/gcc-ar"
premake.gcc.ar = toolchainPrefix .. "gcc-ar"
end
location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-mingw64-gcc")
end
if "mingw-clang" == _OPTIONS["gcc"] then
premake.gcc.cc = "clang"
premake.gcc.cxx = "clang++"
@ -283,18 +293,17 @@ function toolchain(_buildDir, _subDir)
if "osx" == _OPTIONS["gcc"] then
if os.is("linux") then
local osxToolchain = "x86_64-apple-darwin13-"
premake.gcc.cc = osxToolchain .. "clang"
premake.gcc.cxx = osxToolchain .. "clang++"
premake.gcc.ar = osxToolchain .. "ar"
premake.gcc.cc = toolchainPrefix .. "clang"
premake.gcc.cxx = toolchainPrefix .. "clang++"
premake.gcc.ar = toolchainPrefix .. "ar"
end
location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-osx")
end
if "osx-clang" == _OPTIONS["gcc"] then
premake.gcc.cc = "clang"
premake.gcc.cxx = "clang++"
premake.gcc.ar = "ar"
premake.gcc.cc = toolchainPrefix .. "clang"
premake.gcc.cxx = toolchainPrefix .. "clang++"
premake.gcc.ar = toolchainPrefix .. "ar"
location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-osx-clang")
end
@ -911,6 +920,15 @@ function toolchain(_buildDir, _subDir)
end
function strip()
if not _OPTIONS["STRIP_SYMBOLS"]=="1" then
return true
end
configuration { "osx-*", "Release" }
postbuildcommands {
"$(SILENT) echo Stripping symbols.",
"$(SILENT) " .. (_OPTIONS['TOOLCHAIN'] and toolchainPrefix) .. "strip \"$(TARGET)\"",
}
configuration { "android-arm", "Release" }
postbuildcommands {
@ -939,13 +957,12 @@ function strip()
configuration { "mingw*", "x64", "Release" }
postbuildcommands {
"$(SILENT) echo Stripping symbols.",
"$(SILENT) $(MINGW64)/bin/strip -s \"$(TARGET)\"",
"$(SILENT) " .. (_OPTIONS['TOOLCHAIN'] and toolchainPrefix or "$(MINGW64)/bin/") .. "strip -s \"$(TARGET)\"",
}
configuration { "mingw*", "x32", "Release" }
postbuildcommands {
"$(SILENT) echo Stripping symbols.",
"$(SILENT) $(MINGW32)/bin/strip -s \"$(TARGET)\""
"$(SILENT) " .. (_OPTIONS['TOOLCHAIN'] and toolchainPrefix or "$(MINGW32)/bin/") .. "strip -s \"$(TARGET)\"",
}
configuration { "pnacl" }