From 50530c00607a87c2f13ada62b1014dfe1af1daf6 Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Tue, 29 Dec 2020 16:15:05 -0500 Subject: [PATCH 1/8] build: simplify linking The Makefile already calls gcc to link together mame, so use $(CC) instead of $(LD) for the final link step. --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bcfdad1..94d428a 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,6 @@ RM = rm -f CC = gcc CPP = g++ AS = as -LD = gcc STRIP = strip EMULATOR = $(TARGET)$(EXE) @@ -61,7 +60,7 @@ include src/$(MAMEOS)/$(MAMEOS).mak CDEFS = $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS) $(EMULATOR): $(COREOBJS) $(OSOBJS) $(DRVOBJS) - $(LD) $(LDFLAGS) $(COREOBJS) $(OSOBJS) $(LIBS) $(DRVOBJS) -o $@ + $(CC) $(LDFLAGS) $(COREOBJS) $(OSOBJS) $(LIBS) $(DRVOBJS) -o $@ $(STRIP) $(EMULATOR) $(OBJ)/%.o: src/%.c From dc8bc9e06b6c49179909f1568cca5d005f8ed7b3 Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Tue, 29 Dec 2020 16:17:56 -0500 Subject: [PATCH 2/8] build: move strip into its own step Within the Makefile, mame is first linked together and then stripped. If the strip step fails, the end result is an unstripped mame binary. Running 'make' again will not try to re-strip it because a file named 'mame' now exists. Modify the final steps of the build process. Place the unstripped binary into $(OBJ), and the stripped binary into $(PWD) as before. --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 94d428a..9267c01 100644 --- a/Makefile +++ b/Makefile @@ -59,9 +59,11 @@ include src/$(MAMEOS)/$(MAMEOS).mak # combine the various definitions to one CDEFS = $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS) -$(EMULATOR): $(COREOBJS) $(OSOBJS) $(DRVOBJS) +$(EMULATOR): $(OBJ)/$(EMULATOR) + $(STRIP) -o $@ $< + +$(OBJ)/$(EMULATOR): $(COREOBJS) $(OSOBJS) $(DRVOBJS) $(CC) $(LDFLAGS) $(COREOBJS) $(OSOBJS) $(LIBS) $(DRVOBJS) -o $@ - $(STRIP) $(EMULATOR) $(OBJ)/%.o: src/%.c @echo Compiling $<... From 6ffa64261b2dc0ebbc6a9631a2853386997a1ab8 Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Mon, 28 Dec 2020 16:39:25 -0500 Subject: [PATCH 3/8] build: Support cross-compilation So as to allow mame4all-pi to be built via cross-compilation, honor the environment variable CROSS_COMPILE as a prefix to build tools. Then to match autotools standards, rename the variable "CPP" to "CXX". All build tools' names can now be overridden by the calling environment. --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9267c01..4134c11 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,10 @@ VPATH=src $(wildcard src/cpu/*) # compiler, linker and utilities MD = @mkdir -p RM = rm -f -CC = gcc -CPP = g++ -AS = as -STRIP = strip +CC ?= $(CROSS_COMPILE)gcc +CXX ?= $(CROSS_COMPILE)g++ +AS ?= $(CROSS_COMPILE)as +STRIP ?= $(CROSS_COMPILE)strip EMULATOR = $(TARGET)$(EXE) @@ -71,15 +71,15 @@ $(OBJ)/%.o: src/%.c $(OBJ)/%.o: src/%.cpp @echo Compiling $<... - $(CPP) $(CDEFS) $(CFLAGS) -fno-rtti -c $< -o $@ + $(CXX) $(CDEFS) $(CFLAGS) -fno-rtti -c $< -o $@ $(OBJ)/%.o: src/%.s @echo Compiling $<... - $(CPP) $(CDEFS) $(CFLAGS) -c $< -o $@ + $(CXX) $(CDEFS) $(CFLAGS) -c $< -o $@ $(OBJ)/%.o: src/%.S @echo Compiling $<... - $(CPP) $(CDEFS) $(CFLAGS) -c $< -o $@ + $(CXX) $(CDEFS) $(CFLAGS) -c $< -o $@ $(sort $(OBJDIRS)): $(MD) $@ From 76f095daef300facbf5de3be5628dedb6e0cc2cc Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Mon, 28 Dec 2020 17:21:10 -0500 Subject: [PATCH 4/8] build: use pkg-config for SDL Attempt to detect if pkg-config is installed. If so, then use SDL's pc file for its CFLAGS and LIBS. Otherwise, default back to the hard-coded values that were previously within the Makefile. --- Makefile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4134c11..45c81f6 100644 --- a/Makefile +++ b/Makefile @@ -22,15 +22,27 @@ CC ?= $(CROSS_COMPILE)gcc CXX ?= $(CROSS_COMPILE)g++ AS ?= $(CROSS_COMPILE)as STRIP ?= $(CROSS_COMPILE)strip +PKGCONF ?= pkg-config EMULATOR = $(TARGET)$(EXE) DEFS = -DGP2X -DLSB_FIRST -DALIGN_INTS -DALIGN_SHORTS -DINLINE="static __inline" -Dasm="__asm__ __volatile__" -DMAME_UNDERCLOCK -DENABLE_AUTOFIRE -DBIGCASE ##sq DEFS = -DGP2X -DLSB_FIRST -DALIGN_INTS -DALIGN_SHORTS -DINLINE="static __inline" -Dasm="__asm__ __volatile__" -DMAME_UNDERCLOCK -DMAME_FASTSOUND -DENABLE_AUTOFIRE -DBIGCASE +HAS_PKGCONF := $(if $(shell which $(PKGCONF)),yes,no) + +ifeq ($(HAS_PKGCONF),yes) + SDL_CFLAGS ?= $(shell $(PKGCONF) --cflags sdl) + SDL_LIBS ?= $(shell $(PKGCONF) --libs sdl) +else + SDL_CFLAGS ?= -I/usr/include/SDL + SDL_LIBS ?= -lSDL +endif + + CFLAGS += -fsigned-char $(DEVLIBS) \ -Isrc -Isrc/$(MAMEOS) -Isrc/zlib \ - -I/usr/include/SDL \ + $(SDL_CFLAGS) \ -I$(SDKSTAGE)/opt/vc/include -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads \ -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux \ -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \ @@ -40,7 +52,7 @@ CFLAGS += -fsigned-char $(DEVLIBS) \ LDFLAGS = $(CFLAGS) -LIBS = -lm -lpthread -lSDL -L$(SDKSTAGE)/opt/vc/lib -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lglib-2.0 -lasound -lrt +LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) -L$(SDKSTAGE)/opt/vc/lib -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lglib-2.0 -lasound OBJ = obj_$(TARGET)_$(MAMEOS) OBJDIRS = $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \ From e60c02261c7f844a1697aad7fb49b16e255cfa78 Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Mon, 28 Dec 2020 17:21:10 -0500 Subject: [PATCH 5/8] build: use pkg-config for VCSM If pkg-config is installed, use VideoCore Shared Memory (VCSM)'s pc file for its CFLAGS and LIBS. Otherwise, default back to the hard-coded values that were previously within the Makefile. --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 45c81f6..536b5df 100644 --- a/Makefile +++ b/Makefile @@ -34,16 +34,21 @@ HAS_PKGCONF := $(if $(shell which $(PKGCONF)),yes,no) ifeq ($(HAS_PKGCONF),yes) SDL_CFLAGS ?= $(shell $(PKGCONF) --cflags sdl) SDL_LIBS ?= $(shell $(PKGCONF) --libs sdl) + VCSM_CFLAGS ?= $(shell $(PKGCONF) --cflags vcsm) + VCSM_LIBS ?= $(shell $(PKGCONF) --libs vcsm) else SDL_CFLAGS ?= -I/usr/include/SDL SDL_LIBS ?= -lSDL + VCSM_CFLAGS ?= -I$(SDKSTAGE)/opt/vc/include + VCSM_LIBS ?= -L$(SDKSTAGE)/opt/vc/lib endif CFLAGS += -fsigned-char $(DEVLIBS) \ -Isrc -Isrc/$(MAMEOS) -Isrc/zlib \ $(SDL_CFLAGS) \ - -I$(SDKSTAGE)/opt/vc/include -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads \ + $(VCSM_CFLAGS) \ + -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads \ -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux \ -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \ -O3 -ffast-math -fno-builtin -fsingle-precision-constant \ @@ -52,7 +57,7 @@ CFLAGS += -fsigned-char $(DEVLIBS) \ LDFLAGS = $(CFLAGS) -LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) -L$(SDKSTAGE)/opt/vc/lib -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lglib-2.0 -lasound +LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lglib-2.0 -lasound OBJ = obj_$(TARGET)_$(MAMEOS) OBJDIRS = $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \ From 07db68db4e14b66b8d7fad4710643cbbb6b2e348 Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Mon, 28 Dec 2020 17:21:10 -0500 Subject: [PATCH 6/8] build: use pkg-config for EGL If pkg-config is installed, use EGL's pc file for its CFLAGS and LIBS. Otherwise, default back to the hard-coded values that were previously within the Makefile. --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 536b5df..6656a83 100644 --- a/Makefile +++ b/Makefile @@ -36,11 +36,15 @@ ifeq ($(HAS_PKGCONF),yes) SDL_LIBS ?= $(shell $(PKGCONF) --libs sdl) VCSM_CFLAGS ?= $(shell $(PKGCONF) --cflags vcsm) VCSM_LIBS ?= $(shell $(PKGCONF) --libs vcsm) + EGL_CFLAGS ?= $(shell $(PKGCONF) --cflags egl) + EGL_LIBS ?= $(shell $(PKGCONF) --libs egl) else SDL_CFLAGS ?= -I/usr/include/SDL SDL_LIBS ?= -lSDL VCSM_CFLAGS ?= -I$(SDKSTAGE)/opt/vc/include VCSM_LIBS ?= -L$(SDKSTAGE)/opt/vc/lib + EGL_CFLAGS ?= -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux + EGL_LIBS ?= -lbcm_host -lbrcmGLESv2 -lbrcmEGL endif @@ -48,8 +52,7 @@ CFLAGS += -fsigned-char $(DEVLIBS) \ -Isrc -Isrc/$(MAMEOS) -Isrc/zlib \ $(SDL_CFLAGS) \ $(VCSM_CFLAGS) \ - -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads \ - -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux \ + $(EGL_CFLAGS) \ -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \ -O3 -ffast-math -fno-builtin -fsingle-precision-constant \ -Wall -Wno-sign-compare -Wunused -Wpointer-arith -Wcast-align -Waggregate-return -Wshadow \ @@ -57,7 +60,7 @@ CFLAGS += -fsigned-char $(DEVLIBS) \ LDFLAGS = $(CFLAGS) -LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lglib-2.0 -lasound +LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) $(EGL_LIBS) -lglib-2.0 -lasound OBJ = obj_$(TARGET)_$(MAMEOS) OBJDIRS = $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \ From 241463ac9921e92ce163e1a2af841684e489368f Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Mon, 28 Dec 2020 17:21:10 -0500 Subject: [PATCH 7/8] build: use pkg-config for GLib-2.0 If pkg-config is installed, use glib-2.0's pc file for its CFLAGS and LIBS. Otherwise, default back to the hard-coded values that were previously within the Makefile. --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6656a83..9a71ebc 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,8 @@ ifeq ($(HAS_PKGCONF),yes) VCSM_LIBS ?= $(shell $(PKGCONF) --libs vcsm) EGL_CFLAGS ?= $(shell $(PKGCONF) --cflags egl) EGL_LIBS ?= $(shell $(PKGCONF) --libs egl) + GLIB_CFLAGS ?= $(shell $(PKGCONF) --cflags glib-2.0) + GLIB_LIBS ?= $(shell $(PKGCONF) --libs glib-2.0) else SDL_CFLAGS ?= -I/usr/include/SDL SDL_LIBS ?= -lSDL @@ -45,6 +47,8 @@ else VCSM_LIBS ?= -L$(SDKSTAGE)/opt/vc/lib EGL_CFLAGS ?= -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux EGL_LIBS ?= -lbcm_host -lbrcmGLESv2 -lbrcmEGL + GLIB_CFLAGS ?= -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include + GLIB_LIBS ?= -lglib-2.0 endif @@ -53,14 +57,14 @@ CFLAGS += -fsigned-char $(DEVLIBS) \ $(SDL_CFLAGS) \ $(VCSM_CFLAGS) \ $(EGL_CFLAGS) \ - -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \ + $(GLIB_CFLAGS) \ -O3 -ffast-math -fno-builtin -fsingle-precision-constant \ -Wall -Wno-sign-compare -Wunused -Wpointer-arith -Wcast-align -Waggregate-return -Wshadow \ -Wno-narrowing LDFLAGS = $(CFLAGS) -LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) $(EGL_LIBS) -lglib-2.0 -lasound +LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) $(EGL_LIBS) $(GLIB_LIBS) -lasound OBJ = obj_$(TARGET)_$(MAMEOS) OBJDIRS = $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \ From 7a8c7b1e7844f180aa1b8495847ab66bdc452943 Mon Sep 17 00:00:00 2001 From: "J. Tang" Date: Mon, 28 Dec 2020 17:21:10 -0500 Subject: [PATCH 8/8] build: use pkg-config for ALSA If pkg-config is installed, use alsa's pc file for its CFLAGS and LIBS. Otherwise, default back to the hard-coded values that were previously within the Makefile. --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9a71ebc..d7cd593 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,8 @@ ifeq ($(HAS_PKGCONF),yes) EGL_LIBS ?= $(shell $(PKGCONF) --libs egl) GLIB_CFLAGS ?= $(shell $(PKGCONF) --cflags glib-2.0) GLIB_LIBS ?= $(shell $(PKGCONF) --libs glib-2.0) + ALSA_CFLAGS ?= $(shell $(PKGCONF) --cflags alsa) + ALSA_LIBS ?= $(shell $(PKGCONF) --libs alsa) else SDL_CFLAGS ?= -I/usr/include/SDL SDL_LIBS ?= -lSDL @@ -49,6 +51,8 @@ else EGL_LIBS ?= -lbcm_host -lbrcmGLESv2 -lbrcmEGL GLIB_CFLAGS ?= -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include GLIB_LIBS ?= -lglib-2.0 + ALSA_CFLAGS ?= + ALSA_LIBS ?= -lasound endif @@ -58,13 +62,14 @@ CFLAGS += -fsigned-char $(DEVLIBS) \ $(VCSM_CFLAGS) \ $(EGL_CFLAGS) \ $(GLIB_CFLAGS) \ + $(ALSA_CFLAGS) \ -O3 -ffast-math -fno-builtin -fsingle-precision-constant \ -Wall -Wno-sign-compare -Wunused -Wpointer-arith -Wcast-align -Waggregate-return -Wshadow \ -Wno-narrowing LDFLAGS = $(CFLAGS) -LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) $(EGL_LIBS) $(GLIB_LIBS) -lasound +LIBS = -lm -ldl -lpthread -lrt $(SDL_LIBS) $(VCSM_LIBS) $(EGL_LIBS) $(GLIB_LIBS) $(ALSA_LIBS) OBJ = obj_$(TARGET)_$(MAMEOS) OBJDIRS = $(OBJ) $(OBJ)/cpu $(OBJ)/sound $(OBJ)/$(MAMEOS) \