Skip to content

Commit b32f4ca

Browse files
committed
Updates to Makefile and qb configure scripts for Apple
1 parent f3e7e87 commit b32f4ca

4 files changed

Lines changed: 74 additions & 5 deletions

File tree

Makefile

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ ifneq ($(MOC_HEADERS),)
171171
RARCH_OBJ += $(MOC_OBJ)
172172
endif
173173

174-
all: $(TARGET) config.mk
174+
ifeq ($(HAVE_METAL), 1)
175+
METALLIB := default.metallib
176+
endif
177+
178+
all: $(TARGET) $(METALLIB) config.mk
175179

176180
define INFO
177181
ASFLAGS: $(ASFLAGS)
@@ -230,6 +234,23 @@ $(TARGET): $(RARCH_OBJ)
230234
@$(if $(Q), $(shell echo echo LD $@),)
231235
$(Q)$(LINK) -o $@ $(RARCH_OBJ) $(LIBS) $(LDFLAGS) $(LIBRARY_DIRS)
232236

237+
# Compile the Metal shader library used by gfx/drivers/metal.m via
238+
# [device newDefaultLibrary]. Xcode produces this automatically for the
239+
# Metal.xcodeproj build; the commandline build has to do it by hand.
240+
# The .metallib must sit next to the retroarch binary at runtime.
241+
ifeq ($(HAVE_METAL), 1)
242+
METAL_SHADER_SRCS := gfx/common/metal/Shaders.metal gfx/common/metal/menu_pipeline.metal
243+
METAL_AIR_FILES := $(METAL_SHADER_SRCS:.metal=.air)
244+
245+
%.air: %.metal
246+
@$(if $(Q), $(shell echo echo METAL $<),)
247+
$(Q)xcrun -sdk macosx metal $(ARCHFLAGS) -c $< -o $@
248+
249+
default.metallib: $(METAL_AIR_FILES)
250+
@$(if $(Q), $(shell echo echo METALLIB $@),)
251+
$(Q)xcrun -sdk macosx metallib $(METAL_AIR_FILES) -o $@
252+
endif
253+
233254
$(OBJDIR)/%.o: %.c config.h config.mk
234255
@mkdir -p $(dir $@)
235256
@$(if $(Q), $(shell echo echo CC $<),)
@@ -245,6 +266,16 @@ $(OBJDIR)/%.o: %.m
245266
@$(if $(Q), $(shell echo echo OBJC $<),)
246267
$(Q)$(CXX) $(OBJCFLAGS) $(DEFINES) -MMD -c -o $@ $<
247268

269+
# ARC (Automatic Reference Counting) overrides. These three Objective-C
270+
# files use ARC-only constructs (__weak, etc.) and must be built with
271+
# -fobjc-arc. The rest of the RetroArch Objective-C code is MRC-written
272+
# (explicit retain/release, NSAutoreleasePool, etc.) and would fail to
273+
# compile under ARC — so we cannot set -fobjc-arc globally. Xcode does
274+
# the equivalent via per-file CLANG_ENABLE_OBJC_ARC=YES build settings.
275+
$(OBJDIR)/gfx/drivers/metal.o: OBJCFLAGS += -fobjc-arc
276+
$(OBJDIR)/gfx/common/metal/metal_renderer.o: OBJCFLAGS += -fobjc-arc
277+
$(OBJDIR)/input/drivers_joypad/mfi_joypad.o: OBJCFLAGS += -fobjc-arc
278+
248279
$(OBJDIR)/%.o: %.S config.h config.mk $(HEADERS)
249280
@mkdir -p $(dir $@)
250281
@$(if $(Q), $(shell echo echo AS $<),)
@@ -264,6 +295,9 @@ install: $(TARGET)
264295
mkdir -p $(DESTDIR)$(MAN_DIR)/man6 2>/dev/null || /bin/true
265296
mkdir -p $(DESTDIR)$(DATA_DIR)/pixmaps 2>/dev/null || /bin/true
266297
cp $(TARGET) $(DESTDIR)$(BIN_DIR)
298+
@if test "$(HAVE_METAL)" = "1" && test -f default.metallib; then \
299+
cp default.metallib $(DESTDIR)$(BIN_DIR)/; \
300+
fi
267301
cp tools/cg2glsl.py $(DESTDIR)$(BIN_DIR)/retroarch-cg2glsl
268302
cp retroarch.cfg $(DESTDIR)$(GLOBAL_CONFIG_DIR)
269303
cp com.libretro.RetroArch.metainfo.xml $(DESTDIR)$(DATA_DIR)/metainfo
@@ -316,6 +350,7 @@ clean:
316350
$(Q)rm -rf $(OBJDIR_BASE)
317351
$(Q)rm -f $(TARGET)
318352
$(Q)rm -f *.d
353+
$(Q)rm -f default.metallib gfx/common/metal/*.air
319354

320355
.PHONY: all install uninstall clean
321356

Makefile.common

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,14 +1643,23 @@ endif
16431643

16441644
ifeq ($(HAVE_METAL), 1)
16451645
DEFINES += -DHAVE_METAL
1646-
LIBS += -framework Metal -framework MetalKit
1647-
# Metal code relies on ARC (Automatic Reference Counting), enable it
1648-
DEF_FLAGS += -fobjc-arc
1646+
LIBS += -framework Metal -framework MetalKit -framework QuartzCore
1647+
# Metal code (metal.m, metal_renderer.m) relies on ARC. Enabled per-file
1648+
# via an override in the top-level Makefile, since applying -fobjc-arc
1649+
# globally would break the MRC-written Cocoa code (ui_cocoa.m et al.).
16491650
OBJ += \
16501651
gfx/common/metal/metal_renderer.o \
16511652
gfx/drivers/metal.o
16521653
endif
16531654

1655+
ifeq ($(HAVE_MFI), 1)
1656+
DEFINES += -DHAVE_MFI
1657+
LIBS += -framework GameController -framework CoreHaptics
1658+
# mfi_joypad.m uses __weak references, which require ARC. Enabled
1659+
# per-file in the top-level Makefile (see comment above).
1660+
OBJ += input/drivers_joypad/mfi_joypad.o
1661+
endif
1662+
16541663
ifeq ($(HAVE_EGL), 1)
16551664
DEFINES += -DHAVE_EGL
16561665
DEF_FLAGS += $(EGL_CFLAGS)
@@ -2575,6 +2584,7 @@ ifeq ($(HAVE_COCOA), 1)
25752584
endif
25762585
ifeq ($(HAVE_COCOA_METAL), 1)
25772586
HAVE_COCOA_COMMON = 1
2587+
DEFINES += -DHAVE_COCOA_METAL
25782588
endif
25792589

25802590
ifeq ($(HAVE_COCOA_COMMON),1)

qb/config.libs.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ check_platform Linux RPILED 'The RPI led driver is' true
244244
check_platform Darwin METAL 'Metal is' true
245245

246246
if [ "$OS" = 'Darwin' ]; then
247+
# macOS: the Metal and Vulkan (MoltenVK) defaults differ from what the
248+
# generic qb logic produces.
249+
# * HAVE_METAL defaults to 'no' in config.params.sh so check_platform
250+
# early-outs. Force it on here so the Metal video driver is built,
251+
# unless the user explicitly passed --disable-metal.
252+
# * HAVE_VULKAN must be set to 'yes' before the COCOA_METAL check
253+
# below, which decides which AppKit glue to compile based on
254+
# whether Metal/Vulkan is in play. Link-time libvulkan is not
255+
# required on Darwin; MoltenVK is loaded dynamically at runtime
256+
# by gfx/common/vulkan_common.c.
257+
[ "${USER_METAL:-}" != 'no' ] && HAVE_METAL=yes
258+
[ "${USER_VULKAN:-}" != 'no' ] && HAVE_VULKAN=yes
259+
247260
check_platform Darwin COCOA 'Cocoa is' true
248261
check_lib '' COREAUDIO "-framework AudioUnit" AudioUnitInitialize
249262
check_lib '' CORETEXT "-framework CoreText" CTFontCreateWithName
@@ -259,6 +272,10 @@ if [ "$OS" = 'Darwin' ]; then
259272
check_lib '' CORELOCATION "-framework CoreLocation"
260273
check_lib '' IOHIDMANAGER "-framework IOKit" IOHIDManagerCreate
261274
check_lib '' AL "-framework OpenAL" alcOpenDevice
275+
# MFi (Made For iPhone) / GameController.framework joypad support.
276+
# Used for any modern gamepad on macOS (Xbox, DualShock, DualSense, MFi).
277+
# Matches the -DHAVE_MFI default in pkg/apple/BaseConfig.xcconfig.
278+
check_lib '' MFI "-framework GameController"
262279
HAVE_X11=no # X11 breaks on recent OSXes even if present.
263280
HAVE_SDL=no
264281
HAVE_SW2=no
@@ -585,6 +602,12 @@ check_enabled THREADS VULKAN vulkan 'Threads are' false
585602

586603
if [ "$HAVE_VULKAN" != "no" ] && [ "$OS" = 'Win32' ]; then
587604
HAVE_VULKAN=yes
605+
elif [ "$HAVE_VULKAN" != "no" ] && [ "$OS" = 'Darwin' ]; then
606+
# macOS: Vulkan is provided by MoltenVK and is loaded dynamically at
607+
# runtime via gfx/common/vulkan_common.c (see vksym.h). Link-time
608+
# presence of libvulkan is not required, mirroring the Win32 path above
609+
# and matching what pkg/apple/Metal.xcconfig does for the Xcode build.
610+
HAVE_VULKAN=yes
588611
else
589612
check_lib '' VULKAN -lvulkan vkCreateInstance
590613
fi

qb/config.params.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,5 @@ HAVE_TEST_DRIVERS=yes # Test input driver
214214
HAVE_GAME_AI=no
215215
HAVE_SMBCLIENT=auto # SMB client support
216216
HAVE_BUILTINSMBCLIENT=no # Use builtin libsmb2
217-
HAVE_COCOA=auto # Cocoa support (Darwin/Apple)
217+
HAVE_COCOA=auto # Cocoa support (Darwin/Apple)
218+
HAVE_MFI=auto # GameController.framework joypad support (Apple)

0 commit comments

Comments
 (0)