git: 84c2e2313e70 - main - emulators/mame: fix build on 14-CURRENT

From: Robert Clausecker <fuz_at_FreeBSD.org>
Date: Thu, 01 Jun 2023 22:30:06 UTC
The branch main has been updated by fuz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=84c2e2313e7098468fc7e99ef95527903a7bc0b5

commit 84c2e2313e7098468fc7e99ef95527903a7bc0b5
Author:     Alastair Hogge <agh@riseup.net>
AuthorDate: 2023-05-31 08:28:33 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-06-01 22:29:21 +0000

    emulators/mame: fix build on 14-CURRENT
    
     - explicitly declare more system libraries
     - port-{clippy,fmt,lint} maintenance
     - separate out Qt machine debugger via OPTIONS
     - separate out tools via OPTIONS
     - remove licenses from ${PORTDOCS} as they are catalogued thru various ${LICENSE}* definitions
     - add conditional logic for when OS ≧ 14 then explicitly build with LLVM
     - a lot of the work in the post-patch target is on static files, so move most of this to files/
     - files/patch-scripts_genie.lua is a fix for GCC
     - sort targets into the order they run in.
    
    PR:             271374
---
 emulators/mame/Makefile                            | 233 +++++++++++----------
 .../mame/files/{target.ini.in => mame.ini.in}      |  57 +++--
 ...h-3rdparty_genie_build_gmake.freebsd_genie.make |  63 ++++++
 .../files/patch-3rdparty_genie_src_host_scripts.c  |  16 ++
 .../files/patch-3rdparty_genie_src_tools_gcc.lua   |  15 ++
 ...patch-3rdparty_genie_tests_test__gmake__cpp.lua |  15 ++
 emulators/mame/files/patch-makefile                |  29 ++-
 emulators/mame/files/patch-scripts_genie.lua       |  14 ++
 emulators/mame/files/patch-scripts_toolchain.lua   |   4 +-
 emulators/mame/files/pkg-message.in                |  15 +-
 emulators/mame/files/plugin.ini.in                 |  20 ++
 emulators/mame/files/ui.ini.in                     |  71 +++++++
 emulators/mame/pkg-plist                           |  59 +++---
 13 files changed, 435 insertions(+), 176 deletions(-)

diff --git a/emulators/mame/Makefile b/emulators/mame/Makefile
index 26b2e16f7030..d026e3a5e0b5 100644
--- a/emulators/mame/Makefile
+++ b/emulators/mame/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	mame
-PORTVERSION=	0.254
-PORTREVISION=	1
+DISTVERSION=	0.254
+PORTREVISION=	2
 CATEGORIES=	emulators games
 
 MAINTAINER=	agh@riseup.net
@@ -21,161 +21,174 @@ LICENSE_FILE=	${WRKSRC}/docs/LICENSE
 ONLY_FOR_ARCHS=	aarch64 amd64 armv7 i386 powerpc powerpc64 powerpc64le
 ONLY_FOR_ARCHS_REASON=	not yet ported to any architecture other than armv7, arm64, x86, and powerpc*
 
-BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}sphinxcontrib-svg2pdfconverter>0:textproc/py-sphinxcontrib-svg2pdfconverter@${PY_FLAVOR}
+BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}sphinxcontrib-svg2pdfconverter>0:textproc/py-sphinxcontrib-svg2pdfconverter@${PY_FLAVOR} \
+		glm>0:math/glm \
+		rapidjson>0:devel/rapidjson
 LIB_DEPENDS=	libexpat.so:textproc/expat2 \
 		libFLAC.so:audio/flac \
 		libfontconfig.so:x11-fonts/fontconfig \
 		libfreetype.so:print/freetype2 \
-		libpugixml.so:textproc/pugixml
+		libportmidi.so:audio/portmidi \
+		libpugixml.so:textproc/pugixml \
+		libutf8proc.so:textproc/utf8proc \
+		libuv.so:devel/libuv
 RUN_DEPENDS=	liberation-fonts-ttf>=0:x11-fonts/liberation-fonts-ttf
 
-USES=		compiler:c++14-lang gl gmake jpeg localbase lua:54 pkgconfig \
-		python:3.9,build qt:5 sdl shebangfix sqlite:3 xorg
+USES=		compiler:c++17-lang gl gmake jpeg localbase lua:54 pkgconfig \
+		python:3.9,build sdl shebangfix sqlite:3 xorg
 
 USE_GITHUB=	yes
 GH_ACCOUNT=	mamedev
-GH_PROJECT=	mame # explicit (master port)
-GH_TAGNAME=	mame${PORTVERSION:S/.//}
+GH_TAGNAME=	mame${DISTVERSION:S/.//}
 USE_GL=		gl
-USE_QT=		buildtools core gui qmake widgets
 USE_SDL=	sdl2 ttf2
 USE_XORG=	x11 xext xi xinerama xrender
 
 MAKEFILE=	makefile
 MAKE_ARGS=	TARGETOS=freebsd \
-		TOOLS=1 \
-		USE_SYSTEM_LIB_PUGIXML=1 \
-		USE_SYSTEM_LIB_SQLITE3=1 \
-		VERBOSE=1
-MAKE_ENV=	FULLNAME="mame" \
-		GCC_LDFLAGS="${LDFLAGS}" \
-		LD="${CXX}" \
+		VERBOSE="1"
+MAKE_ENV=	LDOPTS="${LDFLAGS}" \
+		NO_USE_PORTAUDIO=1 \
+		NO_USE_PULSEAUDIO=1 \
 		NOWERROR=1 \
 		OPT_FLAGS="${CXXFLAGS}" \
-		PYTHON="${PYTHON_CMD}" \
-		SDL_NETWORK="pcap" \
-		SUBTARGET="${MSUBTARGET}" \
-		TARGET="${MTARGET}" \
-		USE_NETWORK=1
-
-BINARY_ALIAS=	python3=${PYTHON_CMD} python=${PYTHON_CMD}
-SUB_FILES=	pkg-message target.ini
-SUB_LIST=	MSUBTARGET=${MSUBTARGET} \
-		MTARGET=${MTARGET}
-
-PORTDOCS=	LICENSE html/* legal/*
-PORTEXAMPLES=	${MSUBTARGET}.ini
-
-OPTIONS_DEFINE=	DEBUG DOCS EXAMPLES
-DEBUG_DESC=	Build with debug profiling and symbols
-DOCS_DESC=	Install additional MAME documentation
-EXAMPLES_DESC=	Install example ${EMULATOR}.ini configuration
-
-DEBUG_MAKE_ENV=	DEBUG=1
-
-GENIE=		${WRKSRC}/3rdparty/genie
-MSUBTARGET=	mame
-MTARGET=	mame
+		PRECOMPILE=0 \
+		PYTHON_EXECUTABLE="${PYTHON_CMD}" \
+		USE_PCAP=1 \
+		USE_SYSTEM_LIB_EXPAT=1 \
+		USE_SYSTEM_LIB_FLAC=1 \
+		USE_SYSTEM_LIB_GLM=1 \
+		USE_SYSTEM_LIB_JPEG=1 \
+		USE_SYSTEM_LIB_PORTMIDI=1 \
+		USE_SYSTEM_LIB_PUGIXML=1 \
+		USE_SYSTEM_LIB_RAPIDJSON=1 \
+		USE_SYSTEM_LIB_SQLITE3=1 \
+		USE_SYSTEM_LIB_UTF8PROC=1 \
+		USE_SYSTEM_LIB_UV=1 \
+		USE_SYSTEM_LIB_ZLIB=1 \
+		USE_TAPTUN=1
+
+SUB_FILES=	pkg-message mame.ini plugin.ini ui.ini
+
+PORTDOCS=	html/*
+
+OPTIONS_DEFINE=	DEBUG DOCS QTDEBUGGER TOOLS
+OPTIONS_SUB=	yes
+
+DEBUG_DESC=		Build with debug profiling and symbols
+DOCS_DESC=		Install extensive online MAME documentation
+QTDEBUGGER_DESC=	Install Qt interactive low-level machine debugger
+TOOLS_DESC=		Install tools for machine archiving and development
+
+DEBUG_MAKE_ENV=			DEBUG=1 \
+				OPTIMIZE=0 \
+				PROFILER=1 \
+				SYMBOLS=1
+DEBUG_MAKE_ENV_OFF=		OPTIMIZE=2 \
+				STRIP_SYMBOLS=1
+# Attempt to avoid address space exhaustion during linking, specifically
+# on armv7, and possibly other architectures:
+DEBUG_LDFLAGS_OFF=		-s
+QTDEBUGGER_USES=		qt:5
+QTDEBUGGER_USE=			QT=core,gui,widgets,buildtools:build,qmake:build
+QTDEBUGGER_MAKE_ENV=		USE_QTDEBUG=1
+QTDEBUGGER_MAKE_ENV_OFF=	USE_QTDEBUG=0
+TOOLS_MAKE_ENV=			TOOLS=1
+TOOLS_MAKE_ENV_OFF=		TOOLS=0
+
+_GENIE=		${WRKSRC}/3rdparty/genie
 
 .include <bsd.port.options.mk>
 
 .if ${PORT_OPTIONS:MDEBUG}
-WITH_DEBUG=	"YES"
-MAKE_ENV+=	DEBUG="1" \
-		OPTIMIZE="0" \
-		PROFILER="1" \
-		SYMBOLS="1"
+WITH_DEBUG=	yes
+.endif
+
+.if ${OPSYS} == FreeBSD && ${OSVERSION} > 1400000
+USES+=		llvm:15,build
+MAKE_ENV+=	OVERRIDE_AR="llvm-ar${LLVM_VERSION}" \
+		OVERRIDE_CC="clang${LLVM_VERSION}" \
+		OVERRIDE_CXX="clang++${LLVM_VERSION}" \
+		OVERRIDE_LD="lld${LLVM_VERSION}"
 .else
-# avoid address space exhaustion in linker on armv7
-LDFLAGS+=	-s
+MAKE_ENV+=	OVERRIDE_AR="${AR}" \
+		OVERRIDE_CC="${CC}" \
+		OVERRIDE_CXX="${CXX}" \
+		OVERRIDE_LD="${LD}"
 .endif
 
-.if ${ARCH} == aarch64 || ${ARCH} == amd64 || ${ARCH:Mpowerpc64*}
+.if ${ARCH:Maarch64} || ${ARCH:Mamd64} || ${ARCH:Mpowerpc64*}
 MAKE_ARGS+=	PTR64=1
 .endif
 
-EMULATOR=	${MSUBTARGET}
-PLIST_SUB+=	EMULATOR=${EMULATOR}
+post-extract:
+	@${MV} ${WRKSRC}/src/lib/util/png.h \
+		${WRKSRC}/src/lib/util/localpng.h
+
+post-patch:
+# Prefer some system headers over bundled.
+	@${RM} ${WRKSRC}/3rdparty/bx/include/compat/freebsd/dirent.h
+	@${RM} ${WRKSRC}/3rdparty/bx/include/compat/freebsd/signal.h
+# Accommodate GENie conception of BSD.
+	@${MV} ${_GENIE}/build/gmake.freebsd \
+		${_GENIE}/build/gmake.bsd
+# Patch build to use bundled PNG.
+	@${GREP} -rl '"png.h"' ${WRKSRC}/src | \
+		${XARGS} ${REINPLACE_CMD} -e 's|"png.h"|"localpng.h"|'
+	@${REINPLACE_CMD} -e 's|"util/png.h"|"util/localpng.h"|' \
+		${WRKSRC}/src/frontend/mame/ui/icorender.cpp
 
 do-build-DOCS-on:
-	(cd ${WRKSRC}/docs && ${SETENV} ${MAKE_ENV} \
-		${MAKE_CMD} ${MAKE_ARGS} html \
-		SPHINXBUILD=sphinx-build-${PYTHON_VER})
+	(cd ${WRKSRC}/docs && \
+		${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} html SPHINXBUILD=sphinx-build-${PYTHON_VER})
 	@${RM} ${WRKSRC}/docs/build/html/.buildinfo
 
-do-install:
-.for PROGRAM in castool chdman floptool imgtool jedutil ldresample ldverify \
-	nltool nlwav pngcmp regrep romcmp split srcclean testkeys unidasm
-	${INSTALL_PROGRAM} ${WRKSRC}/${PROGRAM} \
-		${STAGEDIR}${PREFIX}/bin
-.endfor
+post-build:
+	(cd ${WRKSRC}/docs && \
+		${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} man SPHINXBUILD=sphinx-build-${PYTHON_VER})
 
-.for data in artwork bgfx ctrlr ini hash language plugins samples
+do-install:
+.for DATA in artwork bgfx ctrlr ini hash language plugins samples
 	(cd ${WRKSRC} && \
-		${COPYTREE_SHARE} ${data} ${STAGEDIR}${DATADIR})
+		${COPYTREE_SHARE} ${DATA} ${STAGEDIR}${DATADIR})
 .endfor
 
 	${MKDIR} ${STAGEDIR}${DOCSDIR}
-	${INSTALL_MAN} ${WRKSRC}/docs/man/*.1 \
+	${INSTALL_MAN} ${WRKSRC}/docs/build/man/MAME.1 \
 		${STAGEDIR}${MANPREFIX}/man/man1
-	${INSTALL_MAN} ${WRKSRC}/docs/build/man/*.1 \
-		${STAGEDIR}${MANPREFIX}/man/man1
-	${INSTALL_MAN} ${WRKSRC}/docs/man/${EMULATOR}.6 \
+	${INSTALL_MAN} ${WRKSRC}/docs/man/mame.6 \
 		${STAGEDIR}${MANPREFIX}/man/man6
-	${INSTALL_MAN} ${WRKSRC}/docs/LICENSE \
-		${STAGEDIR}${DOCSDIR}
-	(cd ${WRKSRC}/docs && \
-		${COPYTREE_SHARE} legal ${STAGEDIR}${DOCSDIR})
 
-do-install-DEBUG-off:
-	${INSTALL_PROGRAM} ${WRKSRC}/${MSUBTARGET} \
-		${STAGEDIR}${PREFIX}/bin/${EMULATOR}
+	${MKDIR} ${STAGEDIR}${ETCDIR}
+.for INI in mame plugin ui
+	${INSTALL_DATA} ${WRKDIR}/${INI}.ini \
+		${STAGEDIR}${ETCDIR}/${INI}.ini.sample
+.endfor
 
 do-install-DEBUG-on:
-	${INSTALL_PROGRAM} ${WRKSRC}/${MSUBTARGET}d \
-		${STAGEDIR}${PREFIX}/bin/${EMULATOR}
+	${INSTALL_PROGRAM} ${WRKSRC}/mamed \
+		${STAGEDIR}${PREFIX}/bin/mame
 
-post-build:
-	cd ${WRKSRC}/docs && ${SETENV} ${MAKE_ENV} \
-		${MAKE_CMD} ${MAKE_ARGS} man \
-		SPHINXBUILD=sphinx-build-${PYTHON_VER}
+do-install-DEBUG-off:
+	${INSTALL_PROGRAM} ${WRKSRC}/mame \
+		${STAGEDIR}${PREFIX}/bin/
 
-post-install-DOCS-on:
+do-install-DOCS-on:
 	${MKDIR} ${STAGEDIR}${DOCSDIR}
 	(cd ${WRKSRC}/docs/build && \
 		${COPYTREE_SHARE} html ${STAGEDIR}${DOCSDIR})
 
-post-install-EXAMPLES-on:
-	${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
-	${INSTALL_DATA} ${WRKDIR}/target.ini \
-		${STAGEDIR}${EXAMPLESDIR}/${EMULATOR}.ini
+do-install-TOOLS-on:
+.for PROGRAM in castool chdman floptool imgtool jedutil ldresample ldverify \
+	nltool nlwav pngcmp regrep romcmp split srcclean testkeys unidasm
+	${INSTALL_PROGRAM} ${WRKSRC}/${PROGRAM} \
+		${STAGEDIR}${PREFIX}/bin
+.endfor
 
-post-patch:
-	@${RM} ${WRKSRC}/3rdparty/bx/include/compat/freebsd/dirent.h
-	@${RM} ${WRKSRC}/3rdparty/bx/include/compat/freebsd/signal.h
-	@${MV} ${GENIE}/build/gmake.freebsd \
-		${GENIE}/build/gmake.bsd
-	@${REINPLACE_CMD} -e \
-		's|^\(AR \)|#\1| ; \
-		 s|^\(CC \)|#\1| ; \
-		 s|^\(CXX \)|#\1| ; \
-		 s|^\(CXX:\)|#\1| ; \
-		 s|^\(LD \)|#\1| ; \
-		 s| .(ARCH)||g' \
-		 ${WRKSRC}/makefile \
-		 ${GENIE}/build/gmake.bsd/genie.make
-	@${REINPLACE_CMD} -e 's|gcc|${CC}|; s|g++|${CXX}|' \
-		${GENIE}/src/tools/gcc.lua \
-		${GENIE}/src/tools/snc.lua \
-		${GENIE}/tests/test_gmake_cpp.lua
-	@${REINPLACE_CMD} -e 's|= \"gcc|= \"${CC}|; s|= \"g++|= \"${CXX}|' \
-		-e "s|'CXX =|'#CXX =|; s|'CC  =|'#CC  =|; s| .(ARCH)| |g" \
-		${GENIE}/src/host/scripts.c
-	@${GREP} -rl '"png.h"' ${WRKSRC}/src | \
-		${XARGS} ${REINPLACE_CMD} -e 's|"png.h"|"localpng.h"|'
-	@${REINPLACE_CMD} -e 's|"util/png.h"|"util/localpng.h"|' \
-		${WRKSRC}/src/frontend/mame/ui/icorender.cpp
-	@${MV} ${WRKSRC}/src/lib/util/png.h \
-		${WRKSRC}/src/lib/util/localpng.h
+.for MANUAL in castool chdman floptool imgtool jedutil ldplayer ldresample \
+	ldverify romcmp
+	${INSTALL_MAN} ${WRKSRC}/docs/man/${MANUAL}.1 \
+		${STAGEDIR}${MANPREFIX}/man/man1
+.endfor
 
 .include <bsd.port.mk>
diff --git a/emulators/mame/files/target.ini.in b/emulators/mame/files/mame.ini.in
similarity index 85%
rename from emulators/mame/files/target.ini.in
rename to emulators/mame/files/mame.ini.in
index 45f332852e02..af7225c732b5 100644
--- a/emulators/mame/files/target.ini.in
+++ b/emulators/mame/files/mame.ini.in
@@ -7,31 +7,31 @@ writeconfig               0
 #
 # CORE SEARCH PATH OPTIONS
 #
-homepath                  ~/.%%MTARGET%%
-rompath                   ~/.%%MTARGET%%/roms;%%DATADIR%%/roms/
-hashpath                  ~/.%%MTARGET%%/hash;%%DATADIR%%/hash/
-samplepath                ~/.%%MTARGET%%/samples;%%DATADIR%%/samples/
-artpath                   ~/.%%MTARGET%%/artwork;%%DATADIR%%/artwork/
-ctrlrpath                 ~/.%%MTARGET%%/ctrlr;%%DATADIR%%/ctrlr/
-inipath                   ~/.%%MTARGET%%/;.;~/.%%MTARGET%%/ini;%%DATADIR%%/ini/
-fontpath                  ~/.%%MTARGET%%/font;%%DATADIR%%/font/
-cheatpath                 ~/.%%MTARGET%%/cheat;%%DATADIR%%/cheat/
-crosshairpath             ~/.%%MTARGET%%/crosshair;%%DATADIR%%/crosshair/
-pluginspath               ~/.%%MTARGET%%/plugins;%%DATADIR%%/plugins/
-languagepath              ~/.%%MTARGET%%/language;%%DATADIR%%/language/
-swpath                    ~/.%%MTARGET%%/software;%%DATADIR%%/software/
+homepath                  ~/.mame
+rompath                   ~/.mame/roms;%%DATADIR%%/roms/
+hashpath                  ~/.mame/hash;%%DATADIR%%/hash/
+samplepath                ~/.mame/samples;%%DATADIR%%/samples/
+artpath                   ~/.mame/artwork;%%DATADIR%%/artwork/
+ctrlrpath                 ~/.mame/ctrlr;%%DATADIR%%/ctrlr/
+inipath                   ~/.mame/ini;%%DATADIR%%/ini/;.
+fontpath                  ~/.mame/font;%%DATADIR%%/font/
+cheatpath                 ~/.mame/cheat;%%DATADIR%%/cheat/
+crosshairpath             ~/.mame/crosshair;%%DATADIR%%/crosshair/
+pluginspath               ~/.mame/plugins;%%DATADIR%%/plugins/
+languagepath              ~/.mame/language;%%DATADIR%%/language/
+swpath                    ~/.mame/software;%%DATADIR%%/software/
 
 #
 # CORE OUTPUT DIRECTORY OPTIONS
 #
-cfg_directory             ~/.%%MTARGET%%/cfg
-nvram_directory           ~/.%%MTARGET%%/nvram
-input_directory           ~/.%%MTARGET%%/inp
-state_directory           ~/.%%MTARGET%%/state
-snapshot_directory        ~/.%%MTARGET%%/snapshot
-diff_directory            ~/.%%MTARGET%%/diff
-comment_directory         ~/.%%MTARGET%%/comments
-share_directory           ~/.%%MTARGET%%/share
+cfg_directory             ~/.mame/cfg
+nvram_directory           ~/.mame/nvram
+input_directory           ~/.mame/inp
+state_directory           ~/.mame/state
+snapshot_directory        ~/.mame/snapshot
+diff_directory            ~/.mame/diff
+comment_directory         ~/.mame/comments
+share_directory           ~/.mame/share
 
 #
 # CORE STATE/PLAYBACK OPTIONS
@@ -138,6 +138,7 @@ offscreen_reload          0
 joystick_map              auto
 joystick_deadzone         0.3
 joystick_saturation       0.85
+joystick_threshold        0.3
 natural                   0
 joystick_contradictory    0
 coin_impulse              0
@@ -211,9 +212,11 @@ http_port                 8080
 http_root                 web
 
 #
-# OSD KEYBOARD MAPPING OPTIONS
+# OSD INPUT MAPPING OPTIONS
 #
 uimodekey                 auto
+controller_map            none
+background_input          0
 
 #
 # OSD FONT OPTIONS
@@ -330,6 +333,16 @@ glsl_shader_screen9       none
 sound                     auto
 audio_latency             2
 
+#
+# OSD MIDI OPTIONS
+#
+midiprovider              auto
+
+#
+# OSD EMULATED NETWORKING OPTIONS
+#
+networkprovider           auto
+
 #
 # BGFX POST-PROCESSING OPTIONS
 #
diff --git a/emulators/mame/files/patch-3rdparty_genie_build_gmake.freebsd_genie.make b/emulators/mame/files/patch-3rdparty_genie_build_gmake.freebsd_genie.make
new file mode 100644
index 000000000000..d528ea1d3b91
--- /dev/null
+++ b/emulators/mame/files/patch-3rdparty_genie_build_gmake.freebsd_genie.make
@@ -0,0 +1,63 @@
+--- 3rdparty/genie/build/gmake.freebsd/genie.make.orig	2023-05-26 04:14:50 UTC
++++ 3rdparty/genie/build/gmake.freebsd/genie.make
+@@ -28,9 +28,9 @@ endif
+   RM    = $(SILENT) del /F "$(subst /,\\,$(1))" 2> nul || exit 0
+ endif
+ 
+-CC  = gcc
+-CXX = g++
+-AR  = ar
++CC  ?= gcc
++CXX ?= g++
++AR  ?= ar
+ 
+ ifndef RESCOMP
+   ifdef WINDRES
+@@ -49,17 +49,17 @@ ifeq ($(config),release)
+   DEFINES            += -DNDEBUG -DLUA_COMPAT_MODULE -DLUA_USE_POSIX -DLUA_USE_DLOPEN
+   INCLUDES           += -I"../../src/host/lua-5.3.0/src"
+   ALL_CPPFLAGS       += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES)
+-  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os $(MPARAM)
+-  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os $(MPARAM)
+-  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os $(MPARAM)
+-  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os $(MPARAM)
+-  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -Os $(MPARAM)
++  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -Os $(MPARAM)
++  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -Os $(MPARAM)
++  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -Os $(MPARAM)
++  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -Os $(MPARAM)
++  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -Os $(MPARAM)
+   ALL_RESFLAGS       += $(RESFLAGS) $(DEFINES) $(INCLUDES)
+   ALL_LDFLAGS        += $(LDFLAGS) -L. -s -rdynamic
+   LDDEPS             +=
+   LIBS               += $(LDDEPS) -lm
+   EXTERNAL_LIBS      +=
+-  LINKCMD             = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
++  LINKCMD             = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES)  $(ALL_LDFLAGS) $(LIBS)
+   OBJECTS := \
+ 	$(OBJDIR)/src/host/lua-5.3.0/src/lapi.o \
+ 	$(OBJDIR)/src/host/lua-5.3.0/src/lauxlib.o \
+@@ -132,17 +132,17 @@ ifeq ($(config),debug)
+   DEFINES            += -D_DEBUG -DLUA_COMPAT_MODULE -DLUA_USE_POSIX -DLUA_USE_DLOPEN
+   INCLUDES           += -I"../../src/host/lua-5.3.0/src"
+   ALL_CPPFLAGS       += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES)
+-  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+-  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+-  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+-  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
+-  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Wall -Wextra -g
++  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -g
++  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -g
++  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -g
++  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -g
++  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS)  -Wall -Wextra -g
+   ALL_RESFLAGS       += $(RESFLAGS) $(DEFINES) $(INCLUDES)
+   ALL_LDFLAGS        += $(LDFLAGS) -L. -rdynamic
+   LDDEPS             +=
+   LIBS               += $(LDDEPS) -lm
+   EXTERNAL_LIBS      +=
+-  LINKCMD             = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
++  LINKCMD             = $(CC) -o $(TARGET) $(OBJECTS) $(RESOURCES)  $(ALL_LDFLAGS) $(LIBS)
+   OBJECTS := \
+ 	$(OBJDIR)/src/host/lua-5.3.0/src/lapi.o \
+ 	$(OBJDIR)/src/host/lua-5.3.0/src/lauxlib.o \
diff --git a/emulators/mame/files/patch-3rdparty_genie_src_host_scripts.c b/emulators/mame/files/patch-3rdparty_genie_src_host_scripts.c
new file mode 100644
index 000000000000..044cf87ada38
--- /dev/null
+++ b/emulators/mame/files/patch-3rdparty_genie_src_host_scripts.c
@@ -0,0 +1,16 @@
+--- 3rdparty/genie/src/host/scripts.c.orig	2023-05-22 09:40:13 UTC
++++ 3rdparty/genie/src/host/scripts.c
+@@ -237,10 +237,10 @@ const char* builtin_scripts[] = {
+ 	"exit 0')\n_p('  COPY  = $(SILENT) copy /Y \"$(subst /,\\\\\\\\,$(1))\" \"$(subst /,\\\\\\\\,$(2))\"')\n_p('  RM    = $(SILENT) del /F \"$(subst /,\\\\\\\\,$(1))\" 2> nul || exit 0')\n_p('endif')\n_p('')\n_p('CC  = %s', cc.cc)\n_p('CXX = %s', cc.cxx)\n_p('AR  = %s', cc.ar)\n_p('')\n_p('ifndef RESCOMP')\n_p('  ifdef WINDRES')\n_p('    RESCOMP = $(WINDRES)')\n_p('  else')\n_p('    RESCOMP = %s', cc.rc or 'windres')\n_p('  endif')\n_p('endif')\n_p('')\nif (not premake.make.makefile_ignore) then\n_p('MAKEFILE = %s', _MAKE.getmakefilename(prj, true))\n_p('')\nend\nend\nlocal function is_excluded(prj, cfg, file)\nif table.icontains(prj.excludes, file) then\nreturn true\nend\nif table.icontains(cfg.excludes, file) then\nreturn true\nend\nreturn false\nend\nfunction premake.gmake_cpp_configs(prj, cc, platforms)\nfor _, platform in ipairs(platforms) do\nfor cfg in premake.eachconfig(prj, platform) do\npremake.gmake_cpp_config(prj, cfg, cc)\nend\nend\nend\nfunction premake.gmake_cpp_config(
 prj, cfg, cc)\n_p('ifeq ($(conf"
+ 	"ig),%s)', _MAKE.esc(cfg.shortname))\ncpp.platformtools(cfg, cc)\nlocal targetDir = _MAKE.esc(cfg.buildtarget.directory)\n_p('  ' .. (table.contains(premake.make.override,\"OBJDIR\") and \"override \" or \"\") ..    'OBJDIR              = %s', _MAKE.esc(cfg.objectsdir))\n_p('  ' .. (table.contains(premake.make.override,\"TARGETDIR\") and \"override \" or \"\") .. 'TARGETDIR           = %s', iif(targetDir == \"\", \".\", targetDir))\n_p('  ' .. (table.contains(premake.make.override,\"TARGET\") and \"override \" or \"\") ..    'TARGET              = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name))\n_p('  DEFINES            +=%s', make.list(_MAKE.escquote(cc.getdefines(cfg.defines))))\nlocal id  = make.list(cc.getincludedirs(cfg.includedirs));\nlocal uid = make.list(cc.getquoteincludedirs(cfg.userincludedirs))\nlocal sid = make.list(cc.getsystemincludedirs(cfg.systemincludedirs))\nif id ~= \"\" then\n_p('  INCLUDES           +=%s', id)\nend\nif uid ~= \"\" then\n_p('  INCLUDES     
       +=%s', uid)\nend\nif sid "
+ 	"~= \"\" then\n_p('  INCLUDES           +=%s', sid)\nend\ncpp.pchconfig(cfg)\ncpp.flags(cfg, cc)\ncpp.linker(prj, cfg, cc)\ntable.sort(cfg.files)\nif cfg.flags.UseObjectResponseFile then\n_p('  OBJRESP             = $(OBJDIR)/%s_objects', prj.name)\nelse\n_p('  OBJRESP             =')\nend\n_p('  OBJECTS := \\\\')\nfor _, file in ipairs(cfg.files) do\nif path.issourcefile(file) then\nif not is_excluded(prj, cfg, file) then\n_p('\\t$(OBJDIR)/%s.o \\\\'\n, _MAKE.esc(path.trimdots(path.removeext(file)))\n)\nend\nend\nend\n_p('')\n_p('  define PREBUILDCMDS')\nif #cfg.prebuildcommands > 0 then\n_p('\\t@echo Running pre-build commands')\n_p('\\t%s', table.implode(cfg.prebuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p('  endef')\n_p('  define PRELINKCMDS')\nif #cfg.prelinkcommands > 0 then\n_p('\\t@echo Running pre-link commands')\n_p('\\t%s', table.implode(cfg.prelinkcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p('  endef')\n_p('  define POSTBUILDCMDS')\nif #cfg.postbuildcommands > 0 then
 \n_p('\\t@echo Running post-bui"
+-	"ld commands')\n_p('\\t%s', table.implode(cfg.postbuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p('  endef')\nmake.settings(cfg, cc)\n_p('endif')\n_p('')\nend\nfunction cpp.platformtools(cfg, cc)\nlocal platform = cc.platforms[cfg.platform]\nif platform.cc then\n_p('  CC         = %s', platform.cc)\nend\nif platform.cxx then\n_p('  CXX        = %s', platform.cxx)\nend\nif platform.ar then\n_p('  AR         = %s', platform.ar)\nend\nend\nfunction cpp.flags(cfg, cc)\nif cfg.pchheader and not cfg.flags.NoPCH then\n_p('  FORCE_INCLUDE      += -include $(OBJDIR)/$(notdir $(PCH))')\n_p('  FORCE_INCLUDE_OBJC += -include $(OBJDIR)/$(notdir $(PCH))_objc')\nend\nif #cfg.forcedincludes > 0 then\n_p('  FORCE_INCLUDE      += -include %s'\n,_MAKE.esc(table.concat(cfg.forcedincludes, \";\")))\nend\n_p('  ALL_CPPFLAGS       += $(CPPFLAGS) %s $(DEFINES) $(INCLUDES)', table.concat(cc.getcppflags(cfg), \" \"))\n_p('  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(
 table.join(cc.getcflags(cfg), c"
+-	"fg.buildoptions, cfg.buildoptions_asm)))\n_p('  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(cc.getcflags(cfg), cfg.buildoptions, cfg.buildoptions_c)))\n_p('  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(cc.getcflags(cfg), cc.getcxxflags(cfg), cfg.buildoptions, cfg.buildoptions_cpp)))\n_p('  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(cc.getcflags(cfg), cc.getobjcflags(cfg), cfg.buildoptions, cfg.buildoptions_objc)))\n_p('  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH)%s', make.list(table.join(cc.getcflags(cfg), cc.getcxxflags(cfg), cc.getobjcflags(cfg), cfg.buildoptions, cfg.buildoptions_objcpp)))\n_p('  ALL_RESFLAGS       += $(RESFLAGS) $(DEFINES) $(INCLUDES)%s',\n        make.list(table.join(cc.getdefines(cfg.resdefines),\n                                cc.getincludedirs(cfg.resincludedirs), cfg.resoptions)))\nend\nfunction cpp.linker(
 prj, cfg, cc)\nlocal libdeps\nl"
++	"ld commands')\n_p('\\t%s', table.implode(cfg.postbuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p('  endef')\nmake.settings(cfg, cc)\n_p('endif')\n_p('')\nend\nfunction cpp.platformtools(cfg, cc)\nlocal platform = cc.platforms[cfg.platform]\nif platform.cc then\n_p('  CC         = %s', platform.cc)\nend\nif platform.cxx then\n_p('  CXX        = %s', platform.cxx)\nend\nif platform.ar then\n_p('  AR         = %s', platform.ar)\nend\nend\nfunction cpp.flags(cfg, cc)\nif cfg.pchheader and not cfg.flags.NoPCH then\n_p('  FORCE_INCLUDE      += -include $(OBJDIR)/$(notdir $(PCH))')\n_p('  FORCE_INCLUDE_OBJC += -include $(OBJDIR)/$(notdir $(PCH))_objc')\nend\nif #cfg.forcedincludes > 0 then\n_p('  FORCE_INCLUDE      += -include %s'\n,_MAKE.esc(table.concat(cfg.forcedincludes, \";\")))\nend\n_p('  ALL_CPPFLAGS       += $(CPPFLAGS) %s $(DEFINES) $(INCLUDES)', table.concat(cc.getcppflags(cfg), \" \"))\n_p('  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) %s', make.list(table.j
 oin(cc.getcflags(cfg), c"
++	"fg.buildoptions, cfg.buildoptions_asm)))\n_p('  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) %s', make.list(table.join(cc.getcflags(cfg), cfg.buildoptions, cfg.buildoptions_c)))\n_p('  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) %s', make.list(table.join(cc.getcflags(cfg), cc.getcxxflags(cfg), cfg.buildoptions, cfg.buildoptions_cpp)))\n_p('  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) %s', make.list(table.join(cc.getcflags(cfg), cc.getobjcflags(cfg), cfg.buildoptions, cfg.buildoptions_objc)))\n_p('  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) %s', make.list(table.join(cc.getcflags(cfg), cc.getcxxflags(cfg), cc.getobjcflags(cfg), cfg.buildoptions, cfg.buildoptions_objcpp)))\n_p('  ALL_RESFLAGS       += $(RESFLAGS) $(DEFINES) $(INCLUDES)%s',\n        make.list(table.join(cc.getdefines(cfg.resdefines),\n                                cc.getincludedirs(cfg.resincludedirs), cfg.resoptions)))\nend\nfunction cpp.linker(prj, cfg, cc)\nlocal libdeps
 \nl"
+ 	"ocal lddeps\nif #cfg.wholearchive > 0 then\nlibdeps = {}\nlddeps  = {}\nfor _, linkcfg in ipairs(premake.getlinks(cfg, \"siblings\", \"object\")) do\nlocal linkpath = path.rebase(linkcfg.linktarget.fullpath, linkcfg.location, cfg.location)\nif table.icontains(cfg.wholearchive, linkcfg.project.name) then\nlddeps = table.join(lddeps, cc.wholearchive(linkpath))\nelse\ntable.insert(lddeps, linkpath)\nend\ntable.insert(libdeps, linkpath)\nend\nlibdeps = make.list(_MAKE.esc(libdeps))\nlddeps  = make.list(_MAKE.esc(lddeps))\nelse\nlibdeps = make.list(_MAKE.esc(premake.getlinks(cfg, \"siblings\", \"fullpath\")))\nlddeps  = libdeps\nend\n_p('  ALL_LDFLAGS        += $(LDFLAGS)%s', make.list(table.join(cc.getlibdirflags(cfg), cc.getldflags(cfg), cfg.linkoptions)))\n_p('  LIBDEPS            +=%s', libdeps)\n_p('  LDDEPS             +=%s', lddeps)\nif cfg.flags.UseLDResponseFile then\n_p('  LDRESP              = $(OBJDIR)/%s_libs', prj.name)\n_p('  LIBS               += @$(LDRESP)%s', make.li
 st(cc.getlinkflags(cfg)))\nelse"
+-	"\n_p('  LDRESP              =')\n_p('  LIBS               += $(LDDEPS)%s', make.list(cc.getlinkflags(cfg)))\nend\n_p('  EXTERNAL_LIBS      +=%s', make.list(cc.getlibfiles(cfg)))\n_p('  LINKOBJS            = %s', (cfg.flags.UseObjectResponseFile and \"@$(OBJRESP)\" or \"$(OBJECTS)\"))\nif cfg.kind == \"StaticLib\" then\nif (not prj.options.ArchiveSplit) then\n_p('  LINKCMD             = $(AR) %s $(TARGET)', make.list(cc.getarchiveflags(prj, cfg, false)))\nelse\n_p('  LINKCMD             = $(AR) %s $(TARGET)', make.list(cc.getarchiveflags(prj, cfg, false)))\n_p('  LINKCMD_NDX         = $(AR) %s $(TARGET)', make.list(cc.getarchiveflags(prj, cfg, true)))\nend\nelse\nlocal tool = iif(cfg.language == \"C\", \"CC\", \"CXX\")\nlocal startgroup = ''\nlocal endgroup = ''\nif (cfg.flags.LinkSupportCircularDependencies) then\nstartgroup = '-Wl,--start-group '\nendgroup   = ' -Wl,--end-group'\nend\n_p('  LINKCMD             = $(%s) -o $(TARGET) $(LINKOBJS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) 
 %s$(LIBS)%s', tool, startgroup,"
++	"\n_p('  LDRESP              =')\n_p('  LIBS               += $(LDDEPS)%s', make.list(cc.getlinkflags(cfg)))\nend\n_p('  EXTERNAL_LIBS      +=%s', make.list(cc.getlibfiles(cfg)))\n_p('  LINKOBJS            = %s', (cfg.flags.UseObjectResponseFile and \"@$(OBJRESP)\" or \"$(OBJECTS)\"))\nif cfg.kind == \"StaticLib\" then\nif (not prj.options.ArchiveSplit) then\n_p('  LINKCMD             = $(AR) %s $(TARGET)', make.list(cc.getarchiveflags(prj, cfg, false)))\nelse\n_p('  LINKCMD             = $(AR) %s $(TARGET)', make.list(cc.getarchiveflags(prj, cfg, false)))\n_p('  LINKCMD_NDX         = $(AR) %s $(TARGET)', make.list(cc.getarchiveflags(prj, cfg, true)))\nend\nelse\nlocal tool = iif(cfg.language == \"C\", \"CC\", \"CXX\")\nlocal startgroup = ''\nlocal endgroup = ''\nif (cfg.flags.LinkSupportCircularDependencies) then\nstartgroup = '-Wl,--start-group '\nendgroup   = ' -Wl,--end-group'\nend\n_p('  LINKCMD             = $(%s) -o $(TARGET) $(LINKOBJS) $(RESOURCES)  $(ALL_LDFLAGS) %s$(LIB
 S)%s', tool, startgroup,"
+ 	" endgroup)\nend\nend\nfunction cpp.pchconfig(cfg)\nif not cfg.pchheader or cfg.flags.NoPCH then\nreturn\nend\nlocal pch = cfg.pchheader\nfor _, incdir in ipairs(cfg.includedirs) do\nlocal abspath = path.getabsolute(path.join(cfg.project.location, incdir))\nlocal testname = path.join(abspath, pch)\nif os.isfile(testname) then\npch = path.getrelative(cfg.location, testname)\nbreak\nend\nend\n_p('  PCH                 = %s', _MAKE.esc(pch))\n_p('  GCH                 = $(OBJDIR)/$(notdir $(PCH)).gch')\n_p('  GCH_OBJC            = $(OBJDIR)/$(notdir $(PCH))_objc.gch')\nend\nfunction cpp.pchrules(prj)\n_p('ifneq (,$(PCH))')\n_p('$(GCH): $(PCH) $(MAKEFILE) | $(OBJDIR)')\nif prj.msgprecompile then\n_p('\\t@echo ' .. prj.msgprecompile)\nelse\n_p('\\t@echo $(notdir $<)')\nend\nlocal cmd = iif(prj.language == \"C\", \"$(CC) $(ALL_CFLAGS) -x c-header\", \"$(CXX) $(ALL_CXXFLAGS) -x c++-header\")\n_p('\\t$(SILENT) %s $(DEFINES) $(INCLUDES) -o \"$@\" -c \"$<\"', cmd)\n_p('')\n_p('$(GCH_OBJC): 
 $(PCH) $(MAKEFILE) | $(OBJDIR)'"
+ 	")\nif prj.msgprecompile then\n_p('\\t@echo ' .. prj.msgprecompile)\nelse\n_p('\\t@echo $(notdir $<)')\nend\nlocal cmd = iif(prj.language == \"C\", \"$(CC) $(ALL_OBJCFLAGS) -x objective-c-header\", \"$(CXX) $(ALL_OBJCPPFLAGS) -x objective-c++-header\")\n_p('\\t$(SILENT) %s $(DEFINES) $(INCLUDES) -o \"$@\" -c \"$<\"', cmd)\n_p('endif')\n_p('')\nend\nfunction cpp.fileRules(prj, cc)\nlocal platforms = premake.filterplatforms(prj.solution, cc.platforms, \"Native\")\n_p('ifneq (,$(OBJRESP))')\n_p('$(OBJRESP): $(OBJECTS) | $(TARGETDIR) $(OBJDIRS)')\n_p('\\t$(SILENT) echo $^')\n_p('\\t$(SILENT) echo $^ > $@')\n_p('endif')\n_p('')\n_p('ifneq (,$(LDRESP))')\n_p('$(LDRESP): $(LDDEPS) | $(TARGETDIR) $(OBJDIRS)')\n_p('\\t$(SILENT) echo $^')\n_p('\\t$(SILENT) echo $^ > $@')\n_p('endif')\n_p('')\ntable.sort(prj.allfiles)\nfor _, file in ipairs(prj.allfiles or {}) do\nif path.issourcefile(file) then\nif (path.isobjcfile(file)) then\n_p('$(OBJDIR)/%s.o: %s $(GCH_OBJC) $(MAKEFILE) | $(OBJDIR)/%s'\
 n, _MAKE.esc(path.trimdots(path"
+ 	".removeext(file)))\n, _MAKE.esc(file)\n, _MAKE.esc(path.getdirectory(path.trimdots(file)))\n)\nelse\n_p('$(OBJDIR)/%s.o: %s $(GCH) $(MAKEFILE) | $(OBJDIR)/%s'\n, _MAKE.esc(path.trimdots(path.removeext(file)))\n, _MAKE.esc(file)\n, _MAKE.esc(path.getdirectory(path.trimdots(file)))\n)\nend\nif (path.isobjcfile(file) and prj.msgcompile_objc) then\n_p('\\t@echo ' .. prj.msgcompile_objc)\nelseif prj.msgcompile then\n_p('\\t@echo ' .. prj.msgcompile)\nelse\n_p('\\t@echo $(notdir $<)')\nend\nif (path.isobjcfile(file)) then\nif (path.iscfile(file)) then\n_p('\\t$(SILENT) $(CXX) $(ALL_OBJCFLAGS) $(FORCE_INCLUDE_OBJC) -o \"$@\" -c \"$<\"')\nelse\n_p('\\t$(SILENT) $(CXX) $(ALL_OBJCPPFLAGS) $(FORCE_INCLUDE_OBJC) -o \"$@\" -c \"$<\"')\nend\nelseif (path.isasmfile(file)) then\n_p('\\t$(SILENT) $(CC) $(ALL_ASMFLAGS) -o \"$@\" -c \"$<\"')\nelse\ncpp.buildcommand(path.iscfile(file) and not prj.options.ForceCPP, \"o\")\nend\nfor _, task in ipairs(prj.postcompiletasks or {}) do\n_p('\\t$(SILENT) %s
 ', task)\n_p('')\nend\n_p('')\n"
diff --git a/emulators/mame/files/patch-3rdparty_genie_src_tools_gcc.lua b/emulators/mame/files/patch-3rdparty_genie_src_tools_gcc.lua
new file mode 100644
index 000000000000..9ffe65ae8854
--- /dev/null
+++ b/emulators/mame/files/patch-3rdparty_genie_src_tools_gcc.lua
@@ -0,0 +1,15 @@
+--- 3rdparty/genie/src/tools/gcc.lua.orig	2023-05-25 09:19:09 UTC
++++ 3rdparty/genie/src/tools/gcc.lua
+@@ -12,9 +12,9 @@ --
+ -- Set default tools
+ --
+ 
+-	premake.gcc.cc     = "gcc"
+-	premake.gcc.cxx    = "g++"
+-	premake.gcc.ar     = "ar"
++	premake.gcc.cc     = _OPTIONS["CC"]
++	premake.gcc.cxx    = _OPTIONS["CXX"]
++	premake.gcc.ar     = _OPTIONS["AR"]
+ 	premake.gcc.rc     = "windres"
+ 	premake.gcc.llvm   = false
+ 
diff --git a/emulators/mame/files/patch-3rdparty_genie_tests_test__gmake__cpp.lua b/emulators/mame/files/patch-3rdparty_genie_tests_test__gmake__cpp.lua
new file mode 100644
index 000000000000..481cbce2ab24
--- /dev/null
+++ b/emulators/mame/files/patch-3rdparty_genie_tests_test__gmake__cpp.lua
@@ -0,0 +1,15 @@
+--- 3rdparty/genie/tests/test_gmake_cpp.lua.orig	2023-04-25 15:19:25 UTC
++++ 3rdparty/genie/tests/test_gmake_cpp.lua
+@@ -47,9 +47,9 @@ endif
+   SILENT = @
+ endif
+ 
+-CC = gcc
+-CXX = g++
+-AR = ar
++CC ?= gcc
++CXX ?= g++
++AR ?= ar
+ 
+ ifndef RESCOMP
+   ifdef WINDRES
diff --git a/emulators/mame/files/patch-makefile b/emulators/mame/files/patch-makefile
index 82288e63f2ca..eda56ef1f250 100644
--- a/emulators/mame/files/patch-makefile
+++ b/emulators/mame/files/patch-makefile
@@ -1,14 +1,27 @@
---- makefile.orig	2023-05-17 11:43:34 UTC
+--- makefile.orig	2023-04-25 15:19:25 UTC
 +++ makefile
-@@ -1425,6 +1425,11 @@ $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang/Makefile: make
+@@ -447,9 +447,9 @@ ifneq ($(TARGETOS),asmjs)
+ endif
  
- .PHONY: freebsd_x64_clang
- freebsd_x64_clang: generate $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang/Makefile
-+	$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang config=$(CONFIG)64 precompile
-+	$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang config=$(CONFIG)64
+ ifneq ($(TARGETOS),asmjs)
+-CC := $(SILENT)gcc
+-LD := $(SILENT)g++
+-CXX:= $(SILENT)g++
++CC ?= $(SILENT)gcc
++LD ?= $(SILENT)g++
++CXX ?= $(SILENT)g++
+ endif
+ 
+ #-------------------------------------------------
+@@ -1409,6 +1409,11 @@ $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang/Makefile: make
+ 
+ $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang/Makefile: makefile $(SCRIPTS) $(GENIE)
+ 	$(SILENT) $(GENIE) $(PARAMS) $(TARGET_PARAMS) --gcc=freebsd-clang --gcc_version=$(CLANG_VERSION) $(MAKETYPE)
 +
 +.PHONY: freebsd_arm64_clang
 +freebsd_arm64_clang: generate $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang/Makefile
- 	$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang config=$(CONFIG)64 precompile
- 	$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang config=$(CONFIG)64
++	$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang config=$(CONFIG)64 precompile
++	$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang config=$(CONFIG)64
  
+ .PHONY: freebsd_x64_clang
+ freebsd_x64_clang: generate $(PROJECTDIR)/$(MAKETYPE)-freebsd-clang/Makefile
diff --git a/emulators/mame/files/patch-scripts_genie.lua b/emulators/mame/files/patch-scripts_genie.lua
new file mode 100644
index 000000000000..fbe17676dd90
--- /dev/null
+++ b/emulators/mame/files/patch-scripts_genie.lua
@@ -0,0 +1,14 @@
+--- scripts/genie.lua.orig	2023-05-24 01:14:32 UTC
++++ scripts/genie.lua
+@@ -1238,6 +1238,11 @@ configuration { "netbsd" }
+ 			"LinkSupportCircularDependencies",
+ 		}
+ 
++configuration { "freebsd" }
++		flags {
++			"LinkSupportCircularDependencies",
++		}
++
+ configuration { "osx*" }
+ 		links {
+ 			"pthread",
diff --git a/emulators/mame/files/patch-scripts_toolchain.lua b/emulators/mame/files/patch-scripts_toolchain.lua
index 014ee01b1f28..fe4f9966ff46 100644
--- a/emulators/mame/files/patch-scripts_toolchain.lua
+++ b/emulators/mame/files/patch-scripts_toolchain.lua
@@ -1,4 +1,4 @@
---- scripts/toolchain.lua.orig	2023-05-06 02:56:32 UTC
+--- scripts/toolchain.lua.orig	2023-05-27 02:18:45 UTC
 +++ scripts/toolchain.lua
 @@ -60,7 +60,8 @@ function androidToolchainRoot()
  		local hostTags = {
@@ -6,7 +6,7 @@
  			linux   = "linux-x86_64",
 -			macosx  = "darwin-x86_64"
 +			macosx  = "darwin-x86_64",
-+			bsd = "freebsd-x86_64"
++			bsd     = "freebsd-x86_64"
  		}
  		android.toolchainRoot = (os.getenv("ANDROID_NDK_HOME") or "") .. "/toolchains/llvm/prebuilt/" .. hostTags[os.get()]
  	end
diff --git a/emulators/mame/files/pkg-message.in b/emulators/mame/files/pkg-message.in
index 0d2518668aee..2133bf702035 100644
--- a/emulators/mame/files/pkg-message.in
+++ b/emulators/mame/files/pkg-message.in
@@ -1,12 +1,15 @@
 [
 { type: install
   message: <<EOM
-An example configuration file has been installed in
-"%%EXAMPLESDIR%%/%%MSUBTARGET%%.ini" This configuration can be copied to your
-"~/.%%MSUBTARGET%%" directory; alternatively, run "%%MSUBTARGET%% -createconfig" to
-create a clean copy of "%%MSUBTARGET%%.ini", which can be copied to
-"~/.%%MSUBTARGET%%", or elsewhere.
-To run %%MSUBTARGET%% with a custom path, run "%%MSUBTARGET%% -inipath path-to-%%MSUBTARGET%%.ini"
+Sample configuration files have been installed in "%%ETCDIR%%/"
+The configuration data can be copied to your "~/.mame" directory; alternatively,
+to create clean copies of MAME's configuration, run "mame -createconfig",
+the output from this can be stored in ~/.mame or elsewhere.
+
+To run mame with a custom path, run "mame -inipath path-to-mame.ini"
+
+By default, MAME will search and write to the current working directory, unless
+it finds configuration data.
 EOM
 }
 ]
diff --git a/emulators/mame/files/plugin.ini.in b/emulators/mame/files/plugin.ini.in
new file mode 100644
index 000000000000..293c79bea26d
--- /dev/null
+++ b/emulators/mame/files/plugin.ini.in
@@ -0,0 +1,20 @@
+#
+# PLUGINS OPTIONS
+#
+autofire                  0
+cheat                     0
+cheatfind                 0
+commonui                  0
+console                   0
+data                      1
+discord                   0
+dummy                     0
+gdbstub                   0
+hiscore                   0
+inputmacro                0
+json                      0
+layout                    0
+portname                  0
+timecode                  0
+timer                     0
+SLAXML                    0
diff --git a/emulators/mame/files/ui.ini.in b/emulators/mame/files/ui.ini.in
new file mode 100644
index 000000000000..f55e36cec83b
--- /dev/null
+++ b/emulators/mame/files/ui.ini.in
@@ -0,0 +1,71 @@
+#
+# UI SEARCH PATH OPTIONS
+#
+historypath               ~/.mame/histroy;~/.mame/dats;%%DATADIR%%/history/;%%DATADIR%%/dats/;.
+categorypath              folders
+cabinets_directory        ~/.mame/cabinets;~/.mame/cabdevs;%%DATADIR%%/cabinets/;%%DATADIR%%/cabdevs/
+cpanels_directory         ~/.mame/cpanel;%%DATADIR%%/cpanel
+pcbs_directory            ~/.mame/pcb;%%DATADIR%%/pcb
+flyers_directory          ~/.mame/flyers;%%DATADIR%%/flyers
+titles_directory          ~/.mame/titles;%%DATADIR%%/titles
+ends_directory            ~/.mame/ends;%%DATADIR%%/ends
+marquees_directory        ~/.mame/marguees;%%DATADIR%%/marquees
+artwork_preview_directory ~/.mame/artpreview;%%DATADIR%%/artpreview
+bosses_directory          ~/.mame/bosses;%%DATADIR%%/bosses
+logos_directory           ~/.mame/logo;%%DATADIR%%/logo
+scores_directory          ~/.mame/scores;%%DATADIR%%/scores
+versus_directory          ~/.mame/versus;%%DATADIR%%/versus
+gameover_directory        ~/.mame/gameover;%%DATADIR%%/gameover
+howto_directory           ~/.mame/howto;%%DATADIR%%/howto
+select_directory          ~/.mame/select;%%DATADIR%%/select
+icons_directory           ~/.mame/icons;%%DATADIR%%/icons
+covers_directory          ~/.mame/covers;%%DATADIR%%/covers
+ui_path                   ui
+
+#
+# UI MISC OPTIONS
+#
+system_names              
+skip_warnings             0
+unthrottle_mute           0
+versus
+#
+# UI OPTIONS
+#
+infos_text_size           0.75
+font_rows                 30
+ui_border_color           ffffffff
+ui_bg_color               ef101030
+ui_clone_color            ff808080
+ui_dipsw_color            ffffff00
+ui_gfxviewer_color        ef101030
+ui_mousedown_bg_color     b0606000
+ui_mousedown_color        ffffff80
+ui_mouseover_bg_color     70404000
+ui_mouseover_color        ffffff80
+ui_selected_bg_color      ef808000
+ui_selected_color         ffffff00
+ui_slider_color           ffffffff
+ui_subitem_color          ffffffff
+ui_text_bg_color          ef000000
+ui_text_color             ffffffff
+ui_unavail_color          ff404040
+
+#
+# SYSTEM/SOFTWARE SELECTION MENU OPTIONS
+#
+hide_main_panel           0
+use_background            1
+skip_biosmenu             0
+skip_partsmenu            0
+remember_last             1
+last_used_machine         
+last_used_filter          
+system_right_panel        image
+software_right_panel      image
+system_right_image        snap
+software_right_image      snap
+enlarge_snaps             1
+forced4x3                 1
+info_audit_enabled        0
+hide_romless              1
diff --git a/emulators/mame/pkg-plist b/emulators/mame/pkg-plist
index 36f07ac1497c..4074b130d61b 100644
--- a/emulators/mame/pkg-plist
+++ b/emulators/mame/pkg-plist
@@ -1,31 +1,31 @@
-bin/castool
-bin/chdman
-bin/floptool
-bin/imgtool
-bin/jedutil
-bin/ldresample
-bin/ldverify
-bin/%%EMULATOR%%
-bin/nltool
-bin/nlwav
-bin/pngcmp
-bin/regrep
-bin/romcmp
-bin/split
-bin/srcclean
-bin/testkeys
-bin/unidasm
+%%TOOLS%%bin/castool
+%%TOOLS%%bin/chdman
+%%TOOLS%%bin/floptool
+%%TOOLS%%bin/imgtool
+%%TOOLS%%bin/jedutil
+%%TOOLS%%bin/ldresample
+%%TOOLS%%bin/ldverify
+bin/mame
+%%TOOLS%%bin/nltool
+%%TOOLS%%bin/nlwav
+%%TOOLS%%bin/pngcmp
+%%TOOLS%%bin/regrep
+%%TOOLS%%bin/romcmp
+%%TOOLS%%bin/split
+%%TOOLS%%bin/srcclean
+%%TOOLS%%bin/testkeys
+%%TOOLS%%bin/unidasm
 man/man1/MAME.1.gz
-man/man1/castool.1.gz
-man/man1/chdman.1.gz
-man/man1/floptool.1.gz
-man/man1/imgtool.1.gz
-man/man1/jedutil.1.gz
-man/man1/ldplayer.1.gz
-man/man1/ldresample.1.gz
-man/man1/ldverify.1.gz
-man/man1/romcmp.1.gz
-man/man6/%%EMULATOR%%.6.gz
+%%TOOLS%%man/man1/castool.1.gz
+%%TOOLS%%man/man1/chdman.1.gz
+%%TOOLS%%man/man1/floptool.1.gz
+%%TOOLS%%man/man1/imgtool.1.gz
+%%TOOLS%%man/man1/jedutil.1.gz
+%%TOOLS%%man/man1/ldplayer.1.gz
+%%TOOLS%%man/man1/ldresample.1.gz
+%%TOOLS%%man/man1/ldverify.1.gz
+%%TOOLS%%man/man1/romcmp.1.gz
+man/man6/mame.6.gz
 %%DATADIR%%/artwork/LICENSE
 %%DATADIR%%/artwork/README.md
 %%DATADIR%%/artwork/aperture-grille.png
@@ -2204,7 +2204,7 @@ man/man6/%%EMULATOR%%.6.gz
 %%DATADIR%%/plugins/data/data_gameinit.lua
 %%DATADIR%%/plugins/data/data_hiscore.lua
 %%DATADIR%%/plugins/data/data_history.lua
-%%DATADIR%%/plugins/data/data_%%EMULATOR%%info.lua
+%%DATADIR%%/plugins/data/data_mameinfo.lua
 %%DATADIR%%/plugins/data/data_marp.lua
 %%DATADIR%%/plugins/data/data_messinfo.lua
 %%DATADIR%%/plugins/data/data_story.lua
@@ -2269,3 +2269,6 @@ man/man6/%%EMULATOR%%.6.gz
 %%DATADIR%%/samples/floppy/525_spin_start_empty.wav
 %%DATADIR%%/samples/floppy/525_spin_start_loaded.wav
 %%DATADIR%%/samples/floppy/525_step_1_1.wav
+@sample %%ETCDIR%%/mame.ini.sample
+@sample %%ETCDIR%%/plugin.ini.sample
+@sample %%ETCDIR%%/ui.ini.sample