Skip to content

Commit a3b2da6

Browse files
Merge pull request #2502 from LORgames/ssurtees/gmake_macos_arch
Added macOS arch support to GCC and Clang for gmake and gmakelegacy
2 parents aa52500 + a0e0458 commit a3b2da6

File tree

6 files changed

+130
-10
lines changed

6 files changed

+130
-10
lines changed

modules/gmake/tests/test_gmake_ldflags.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib32 -m32
7474
system (p.MACOSX)
7575
prepare()
7676
test.capture [[
77-
ALL_LDFLAGS += $(LDFLAGS) -m64
77+
ALL_LDFLAGS += $(LDFLAGS) -arch x86_64
7878
]]
7979
end

modules/gmakelegacy/tests/cpp/test_ldflags.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@
7373
system (p.MACOSX)
7474
prepare()
7575
test.capture [[
76-
ALL_LDFLAGS += $(LDFLAGS) -m64
76+
ALL_LDFLAGS += $(LDFLAGS) -arch x86_64
7777
]]
7878
end

src/tools/clang.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,10 @@
233233
--
234234

235235
clang.ldflags = {
236-
architecture = {
237-
x86 = "-m32",
238-
x86_64 = "-m64",
236+
architecture = table.merge(gcc.ldflags.architecture, {
239237
WASM32 = "-m32",
240238
WASM64 = "-m64",
241-
},
239+
}),
242240
linkerfatalwarnings = {
243241
All = "-Wl,--fatal-warnings",
244242
},

src/tools/gcc.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
--
5555
gcc.shared = {
5656
architecture = {
57-
x86 = "-m32",
58-
x86_64 = "-m64",
57+
x86 = function (cfg) return iif(cfg.system == p.MACOSX, "-arch i386", "-m32") end,
58+
x86_64 = function (cfg) return iif(cfg.system == p.MACOSX, "-arch x86_64", "-m64") end,
59+
ARM64 = function (cfg) return iif(cfg.system == p.MACOSX, "-arch arm64", nil) end,
5960
},
6061
fatalwarnings = {
6162
All = "-Werror",
@@ -485,8 +486,9 @@
485486

486487
gcc.ldflags = {
487488
architecture = {
488-
x86 = "-m32",
489-
x86_64 = "-m64",
489+
x86 = function (cfg) return iif(cfg.system == p.MACOSX, "-arch i386", "-m32") end,
490+
x86_64 = function (cfg) return iif(cfg.system == p.MACOSX, "-arch x86_64", "-m64") end,
491+
ARM64 = function (cfg) return iif(cfg.system == p.MACOSX, "-arch arm64", nil) end,
490492
},
491493
linkerfatalwarnings = {
492494
All = "-Wl,--fatal-warnings",

tests/tools/test_clang.lua

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,77 @@ end
237237
test.contains({ "-pg" }, clang.getcxxflags(cfg))
238238
test.contains({ "-pg" }, clang.getldflags(cfg))
239239
end
240+
241+
--
242+
-- Make sure system or architecture flags are added properly.
243+
--
244+
245+
function suite.cflags_onX86()
246+
architecture "x86"
247+
prepare()
248+
test.contains({ "-m32" }, clang.getcflags(cfg))
249+
end
250+
251+
function suite.ldflags_onX86()
252+
architecture "x86"
253+
prepare()
254+
test.contains({ "-m32" }, clang.getldflags(cfg))
255+
end
256+
257+
function suite.cflags_onX86_64()
258+
architecture "x86_64"
259+
prepare()
260+
test.contains({ "-m64" }, clang.getcflags(cfg))
261+
end
262+
263+
function suite.ldflags_onX86_64()
264+
architecture "x86_64"
265+
prepare()
266+
test.contains({ "-m64" }, clang.getldflags(cfg))
267+
end
268+
269+
function suite.cflags_macosx_onX86()
270+
system "macosx"
271+
architecture "x86"
272+
prepare()
273+
test.excludes({ "-m32" }, clang.getcflags(cfg))
274+
test.contains({ "-arch i386" }, clang.getcflags(cfg))
275+
end
276+
277+
function suite.ldflags_macosx_onX86()
278+
system "macosx"
279+
architecture "x86"
280+
prepare()
281+
test.excludes({ "-m32" }, clang.getldflags(cfg))
282+
test.contains({ "-arch i386" }, clang.getldflags(cfg))
283+
end
284+
285+
function suite.cflags_macosx_onX86_64()
286+
system "macosx"
287+
architecture "x86_64"
288+
prepare()
289+
test.excludes({ "-m64" }, clang.getcflags(cfg))
290+
test.contains({ "-arch x86_64" }, clang.getcflags(cfg))
291+
end
292+
293+
function suite.ldflags_macosx_onX86_64()
294+
system "macosx"
295+
architecture "x86_64"
296+
prepare()
297+
test.excludes({ "-m64" }, clang.getldflags(cfg))
298+
test.contains({ "-arch x86_64" }, clang.getldflags(cfg))
299+
end
300+
301+
function suite.cflags_macosx_onarm64()
302+
system "macosx"
303+
architecture "arm64"
304+
prepare()
305+
test.contains({ "-arch arm64" }, clang.getcflags(cfg))
306+
end
307+
308+
function suite.ldflags_macosx_onarm64()
309+
system "macosx"
310+
architecture "arm64"
311+
prepare()
312+
test.contains({ "-arch arm64" }, clang.getldflags(cfg))
313+
end

tests/tools/test_gcc.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,52 @@
606606
test.contains({ "-m64" }, gcc.getldflags(cfg))
607607
end
608608

609+
function suite.cflags_macosx_onX86()
610+
system "macosx"
611+
architecture "x86"
612+
prepare()
613+
test.excludes({ "-m32" }, gcc.getcflags(cfg))
614+
test.contains({ "-arch i386" }, gcc.getcflags(cfg))
615+
end
616+
617+
function suite.ldflags_macosx_onX86()
618+
system "macosx"
619+
architecture "x86"
620+
prepare()
621+
test.excludes({ "-m32" }, gcc.getldflags(cfg))
622+
test.contains({ "-arch i386" }, gcc.getldflags(cfg))
623+
end
624+
625+
function suite.cflags_macosx_onX86_64()
626+
system "macosx"
627+
architecture "x86_64"
628+
prepare()
629+
test.excludes({ "-m64" }, gcc.getcflags(cfg))
630+
test.contains({ "-arch x86_64" }, gcc.getcflags(cfg))
631+
end
632+
633+
function suite.ldflags_macosx_onX86_64()
634+
system "macosx"
635+
architecture "x86_64"
636+
prepare()
637+
test.excludes({ "-m64" }, gcc.getldflags(cfg))
638+
test.contains({ "-arch x86_64" }, gcc.getldflags(cfg))
639+
end
640+
641+
function suite.cflags_macosx_onarm64()
642+
system "macosx"
643+
architecture "arm64"
644+
prepare()
645+
test.contains({ "-arch arm64" }, gcc.getcflags(cfg))
646+
end
647+
648+
function suite.ldflags_macosx_onarm64()
649+
system "macosx"
650+
architecture "arm64"
651+
prepare()
652+
test.contains({ "-arch arm64" }, gcc.getldflags(cfg))
653+
end
654+
609655

610656
--
611657
-- Non-Windows shared libraries should marked as position independent.

0 commit comments

Comments
 (0)