Skip to content

Commit d4fe267

Browse files
committed
Make cross-compilation for windows possible using mingw
1 parent 85f6e45 commit d4fe267

8 files changed

Lines changed: 67 additions & 38 deletions

File tree

bam.lua

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
CheckVersion("0.4")
22

3+
target_family = os.getenv("TARGET_FAMILY")
4+
if target_family then
5+
family = target_family
6+
end
7+
target_platform = os.getenv("TARGET_PLATFORM")
8+
if target_platform then
9+
platform = target_platform
10+
end
11+
target_arch = os.getenv("TARGET_ARCH")
12+
if target_arch then
13+
arch = target_arch
14+
end
15+
316
Import("configure.lua")
417
Import("other/sdl/sdl.lua")
518
Import("other/freetype/freetype.lua")
@@ -28,7 +41,7 @@ config:Finalize("config.lua")
2841

2942
-- data compiler
3043
function Script(name)
31-
if family == "windows" then
44+
if family == "windows" and target_family ~= "windows" then
3245
return str_replace(name, "/", "\\")
3346
end
3447
return "python " .. name
@@ -67,14 +80,20 @@ DuplicateDirectoryStructure("src", "src", "objs")
6780
]]
6881

6982
function ResCompile(scriptfile)
83+
windres = os.getenv("WINDRES")
84+
if not windres then
85+
windres = "windres"
86+
end
87+
7088
scriptfile = Path(scriptfile)
7189
if config.compiler.driver == "cl" then
7290
output = PathBase(scriptfile) .. ".res"
7391
AddJob(output, "rc " .. scriptfile, "rc /fo " .. output .. " " .. scriptfile)
7492
elseif config.compiler.driver == "gcc" then
7593
output = PathBase(scriptfile) .. ".coff"
76-
AddJob(output, "windres " .. scriptfile, "windres -i " .. scriptfile .. " -o " .. output)
94+
AddJob(output, windres .. " " .. scriptfile, windres .. " -i " .. scriptfile .. " -o " .. output)
7795
end
96+
7897
AddDependency(output, scriptfile)
7998
return output
8099
end
@@ -128,36 +147,36 @@ server_sql_depends = {}
128147

129148
if family == "windows" then
130149
if platform == "win32" then
131-
table.insert(client_depends, CopyToDirectory(".", "other\\freetype\\lib32\\freetype.dll"))
132-
table.insert(client_depends, CopyToDirectory(".", "other\\sdl\\lib32\\SDL.dll"))
133-
134-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib32\\libcurl.dll"))
135-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib32\\libeay32.dll"))
136-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib32\\libidn-11.dll"))
137-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib32\\ssleay32.dll"))
138-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib32\\zlib1.dll"))
139-
140-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib32\\libgcc_s_sjlj-1.dll"))
141-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib32\\libogg-0.dll"))
142-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib32\\libopus-0.dll"))
143-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib32\\libopusfile-0.dll"))
150+
table.insert(client_depends, CopyToDirectory(".", "other/freetype/lib32/freetype.dll"))
151+
table.insert(client_depends, CopyToDirectory(".", "other/sdl/lib32/SDL.dll"))
152+
153+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib32/libcurl.dll"))
154+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib32/libeay32.dll"))
155+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib32/libidn-11.dll"))
156+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib32/ssleay32.dll"))
157+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib32/zlib1.dll"))
158+
159+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib32/libgcc_s_sjlj-1.dll"))
160+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib32/libogg-0.dll"))
161+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib32/libopus-0.dll"))
162+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib32/libopusfile-0.dll"))
144163
else
145-
table.insert(client_depends, CopyToDirectory(".", "other\\freetype\\lib64\\freetype.dll"))
146-
table.insert(client_depends, CopyToDirectory(".", "other\\sdl\\lib64\\SDL.dll"))
147-
148-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib64\\libcurl.dll"))
149-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib64\\libeay32.dll"))
150-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib64\\ssleay32.dll"))
151-
table.insert(client_depends, CopyToDirectory(".", "other\\curl\\windows\\lib64\\zlib1.dll"))
152-
153-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib64\\libwinpthread-1.dll"))
154-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib64\\libgcc_s_seh-1.dll"))
155-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib64\\libogg-0.dll"))
156-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib64\\libopus-0.dll"))
157-
table.insert(client_depends, CopyToDirectory(".", "other\\opus\\windows\\lib64\\libopusfile-0.dll"))
164+
table.insert(client_depends, CopyToDirectory(".", "other/freetype/lib64/freetype.dll"))
165+
table.insert(client_depends, CopyToDirectory(".", "other/sdl/lib64/SDL.dll"))
166+
167+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib64/libcurl.dll"))
168+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib64/libeay32.dll"))
169+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib64/ssleay32.dll"))
170+
table.insert(client_depends, CopyToDirectory(".", "other/curl/windows/lib64/zlib1.dll"))
171+
172+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib64/libwinpthread-1.dll"))
173+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib64/libgcc_s_seh-1.dll"))
174+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib64/libogg-0.dll"))
175+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib64/libopus-0.dll"))
176+
table.insert(client_depends, CopyToDirectory(".", "other/opus/windows/lib64/libopusfile-0.dll"))
158177
end
159-
table.insert(server_sql_depends, CopyToDirectory(".", "other\\mysql\\vc2005libs\\mysqlcppconn.dll"))
160-
table.insert(server_sql_depends, CopyToDirectory(".", "other\\mysql\\vc2005libs\\libmysql.dll"))
178+
table.insert(server_sql_depends, CopyToDirectory(".", "other/mysql/vc2005libs/mysqlcppconn.dll"))
179+
table.insert(server_sql_depends, CopyToDirectory(".", "other/mysql/vc2005libs/libmysql.dll"))
161180

162181
if config.compiler.driver == "cl" then
163182
client_link_other = {ResCompile("other/icons/teeworlds_cl.rc")}
@@ -179,6 +198,16 @@ function build(settings)
179198
--settings.objdir = Path("objs")
180199
settings.cc.Output = Intermediate_Output
181200

201+
cc = os.getenv("CC")
202+
if cc then
203+
settings.cc.exe_c = cc
204+
end
205+
cxx = os.getenv("CXX")
206+
if cxx then
207+
settings.cc.exe_cxx = cxx
208+
settings.link.exe = cxx
209+
settings.dll.exe = cxx
210+
end
182211
cflags = os.getenv("CFLAGS")
183212
if cflags then
184213
settings.cc.flags:Add(cflags)

configure.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ function OptCCompiler(name, default_driver, default_c, default_cxx, desc)
382382
error(option.driver.." is not a known c/c++ compile driver")
383383
end
384384

385-
if option.c_compiler then settings.cc.c_compiler = option.c_compiler end
386-
if option.cxx_compiler then settings.cc.cxx_compiler = option.cxx_compiler end
385+
if option.c_compiler then settings.cc.exe_c = option.c_compiler end
386+
if option.cxx_compiler then settings.cc.exe_cxx = option.cxx_compiler end
387387
end
388388

389389
local save = function(option, output)

other/curl/curl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Curl = {
1212
option.use_pkgconfig = true
1313
end
1414

15-
if ExecuteSilent("pkg-config libcurl") == 0 then
15+
if family ~= "windows" and ExecuteSilent("pkg-config libcurl") == 0 then
1616
option.value = true
1717
if option.use_pkgconfig == nil then
1818
option.use_pkgconfig = true

other/freetype/freetype.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FreeType = {
88
option.use_winlib = 0
99
option.lib_path = nil
1010

11-
if ExecuteSilent("pkg-config freetype2") == 0 then
11+
if family ~= "windows" and ExecuteSilent("pkg-config freetype2") == 0 then
1212
option.value = true
1313
option.use_pkgconfig = true
1414
end

other/opus/ogg.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Ogg = {
1212
option.use_pkgconfig = true
1313
end
1414

15-
if ExecuteSilent("pkg-config ogg") == 0 then
15+
if family ~= "windows" and ExecuteSilent("pkg-config ogg") == 0 then
1616
option.value = true
1717
if option.use_pkgconfig == nil then
1818
option.use_pkgconfig = true

other/opus/opus.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Opus = {
1212
option.use_pkgconfig = true
1313
end
1414

15-
if ExecuteSilent("pkg-config opus") == 0 then
15+
if family ~= "windows" and ExecuteSilent("pkg-config opus") == 0 then
1616
option.value = true
1717
if option.use_pkgconfig == nil then
1818
option.use_pkgconfig = true

other/opus/opusfile.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Opusfile = {
1212
option.use_pkgconfig = true
1313
end
1414

15-
if ExecuteSilent("pkg-config opusfile") == 0 then
15+
if family ~= "windows" and ExecuteSilent("pkg-config opusfile") == 0 then
1616
option.value = true
1717
if option.use_pkgconfig == nil then
1818
option.use_pkgconfig = true

other/sdl/sdl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SDL = {
99
option.use_osxframework = false
1010
option.lib_path = nil
1111

12-
if ExecuteSilent("pkg-config sdl") == 0 then
12+
if family ~= "windows" and ExecuteSilent("pkg-config sdl") == 0 then
1313
option.value = true
1414
option.use_pkgconfig = true
1515
end

0 commit comments

Comments
 (0)