From f49a4c48cb6eb1974505644f2ae76cf55693e9fe Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 3 Mar 2025 02:02:05 +0200 Subject: [PATCH] try to support macOS for standalone --- Makefile | 29 +++++--- Makefile.libretro | 4 + configure | 99 ++++++++++++++++++------- frontend/menu.c | 18 +++-- frontend/plugin_lib.c | 9 ++- libpcsxcore/new_dynarec/linkage_arm64.S | 1 + libpcsxcore/new_dynarec/new_dynarec.c | 1 + plugins/gpulib/gpulib.mak | 5 +- 8 files changed, 114 insertions(+), 52 deletions(-) diff --git a/Makefile b/Makefile index eb822972..3ea70737 100644 --- a/Makefile +++ b/Makefile @@ -26,16 +26,6 @@ ifeq ($(DEBUG_UBSAN), 1) CFLAGS += -fsanitize=undefined -fno-sanitize=shift-base LDFLAGS += -fsanitize=undefined endif -ifneq ($(NO_FSECTIONS), 1) -CFLAGS += -ffunction-sections -fdata-sections -FSECTIONS_LDFLAGS ?= -Wl,--gc-sections -LDFLAGS += $(FSECTIONS_LDFLAGS) -endif -CFLAGS += -DP_HAVE_MMAP=$(if $(NO_MMAP),0,1) \ - -DP_HAVE_PTHREAD=$(if $(NO_PTHREAD),0,1) \ - -DP_HAVE_POSIX_MEMALIGN=$(if $(NO_POSIX_MEMALIGN),0,1) \ - -DDISABLE_MEM_LUTS=0 -CXXFLAGS += $(CFLAGS) #DRC_DBG = 1 #PCNT = 1 @@ -64,12 +54,25 @@ endif CC_LINK ?= $(CC) CC_AS ?= $(CC) LDFLAGS += $(MAIN_LDFLAGS) -EXTRA_LDFLAGS ?= -Wl,-Map=$@.map +#EXTRA_LDFLAGS ?= -Wl,-Map=$@.map # not on some linkers LDLIBS += $(MAIN_LDLIBS) ifdef PCNT CFLAGS += -DPCNT endif +ifneq ($(NO_FSECTIONS), 1) +CFLAGS += -ffunction-sections -fdata-sections +ifeq ($(GNU_LINKER),1) +FSECTIONS_LDFLAGS ?= -Wl,--gc-sections +LDFLAGS += $(FSECTIONS_LDFLAGS) +endif +endif # NO_FSECTIONS +CFLAGS += -DP_HAVE_MMAP=$(if $(NO_MMAP),0,1) \ + -DP_HAVE_PTHREAD=$(if $(NO_PTHREAD),0,1) \ + -DP_HAVE_POSIX_MEMALIGN=$(if $(NO_POSIX_MEMALIGN),0,1) \ + -DDISABLE_MEM_LUTS=0 +CXXFLAGS += $(CFLAGS) + # core OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cdrom-async.o \ libpcsxcore/cheat.o libpcsxcore/database.o \ @@ -352,8 +355,10 @@ ifeq "$(PLATFORM)" "generic" OBJS += frontend/libpicofe/in_sdl.o OBJS += frontend/libpicofe/plat_sdl.o OBJS += frontend/libpicofe/plat_dummy.o -OBJS += frontend/libpicofe/linux/in_evdev.o OBJS += frontend/plat_sdl.o +ifeq "$(HAVE_EVDEV)" "1" +OBJS += frontend/libpicofe/linux/in_evdev.o +endif ifeq "$(HAVE_GLES)" "1" OBJS += frontend/libpicofe/gl.o frontend/libpicofe/gl_platform.o LDLIBS += $(LDLIBS_GLES) diff --git a/Makefile.libretro b/Makefile.libretro index 40d635bb..2197946c 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -7,6 +7,7 @@ HAVE_PHYSICAL_CDROM ?= 1 USE_ASYNC_CDROM ?= 1 USE_LIBRETRO_VFS ?= 0 NDRC_THREAD ?= 1 +GNU_LINKER ?= 1 # Dynarec options: lightrec, ari64 DYNAREC ?= lightrec @@ -208,6 +209,7 @@ else ifeq ($(platform), osx) LDFLAGS += $(ARCHFLAGS) HAVE_PHYSICAL_CDROM = 0 FSECTIONS_LDFLAGS = -Wl,-dead_strip + GNU_LINKER = 0 # iOS else ifneq (,$(findstring ios,$(platform))) @@ -246,6 +248,7 @@ else endif CFLAGS += $(MINVERSION) FSECTIONS_LDFLAGS = -Wl,-dead_strip + GNU_LINKER = 0 else ifeq ($(platform), tvos-arm64) TARGET := $(TARGET_NAME)_libretro_tvos.dylib @@ -270,6 +273,7 @@ endif MINVERSION = -mappletvos-version-min=11.0 CFLAGS += $(MINVERSION) FSECTIONS_LDFLAGS = -Wl,-dead_strip + GNU_LINKER = 0 # Nintendo Switch (libnx) else ifeq ($(platform), libnx) diff --git a/configure b/configure index 3bc436e5..b4ab4a2a 100755 --- a/configure +++ b/configure @@ -53,8 +53,11 @@ have_armv7="" have_arm_neon="" have_arm_neon_asm="" have_tslib="" +have_evdev="" have_gles="" have_c64x_dsp="" +have_fsections="yes" +gnu_linker="yes" dynarec="" multithreading="yes" need_sdl="no" @@ -68,27 +71,42 @@ optimize_cortexa8="no" optimize_arm926ej="no" # hardcoded stuff -if [ "${OSTYPE}" = "FreeBSD" ]; then - CC="clang" - CXX="clang++" - CFLAGS="-I/usr/local/include -L/usr/local/lib" - MAKE=gmake -else - CC="${CC-${CROSS_COMPILE}gcc}" - CXX="${CXX-${CROSS_COMPILE}g++}" -fi +case "${OSTYPE}" in + *BSD*|*darwin*) + CC="clang" + CXX="clang++" + if test -d /opt/local/include; then + # MacPorts + CFLAGS="$CFLAGS -I/opt/local/include" + LDFLAGS="$LDFLAGS -L/opt/local/lib" + fi + if test -d /opt/local/include; then + CFLAGS="$CFLAGS -I/usr/local/include" + LDFLAGS="$LDFLAGS -L/usr/local/lib" + fi + MAKE=gmake + gnu_linker="no" + ;; + *) + CC="${CC-${CROSS_COMPILE}gcc}" + CXX="${CXX-${CROSS_COMPILE}g++}" + ;; +esac AS="${AS-${CROSS_COMPILE}as}" AR="${AS-${CROSS_COMPILE}ar}" MAIN_LDLIBS="$LDLIBS -ldl -lm -lpthread" config_mak="config.mak" -if [ "${OSTYPE}" = "FreeBSD" ]; then - SYSROOT="$sysroot" - [ "x${SDL_CONFIG}" = "x" ] && SDL_CONFIG="${SYSROOT}/usr/local/bin/sdl-config" -else - SYSROOT="$(${CC} --print-sysroot)" - [ "x${SDL_CONFIG}" = "x" ] && SDL_CONFIG="${SYSROOT}/usr/bin/sdl-config" -fi +case "${OSTYPE}" in + *BSD*|*darwin*) + SYSROOT="$sysroot" + [ "x${SDL_CONFIG}" = "x" ] && SDL_CONFIG="${SYSROOT}/usr/local/bin/sdl-config" + ;; + *) + SYSROOT="$(${CC} --print-sysroot 2> /dev/null || true)" + [ "x${SDL_CONFIG}" = "x" ] && SDL_CONFIG="${SYSROOT}/usr/bin/sdl-config" + ;; +esac fail() { @@ -220,6 +238,16 @@ if [ -z "$ARCH" ]; then fi case "$ARCH" in +aarch64|arm64) + have_arm_neon="yes" + have_arm_neon_asm="no" + if [ "x$dynarec" = "x" ]; then + dynarec="ari64" + fi + if [ "x$builtin_gpu" = "x" ]; then + builtin_gpu="neon" + fi + ;; arm*) # ARM stuff ARCH="arm" @@ -305,16 +333,6 @@ arm*) fi have_arm_neon_asm=$have_arm_neon ;; -aarch64) - have_arm_neon="yes" - have_arm_neon_asm="no" - if [ "x$dynarec" = "x" ]; then - dynarec="ari64" - fi - if [ "x$builtin_gpu" = "x" ]; then - builtin_gpu="neon" - fi - ;; x86_64) if [ "x$dynarec" = "x" ]; then dynarec="lightrec" @@ -399,7 +417,7 @@ check_sdl() { cat > $TMPC < - void main() { SDL_OpenAudio(0, 0); } + int main(int argc, char *argv[]) { SDL_OpenAudio(0, 0); } EOF compile_binary "$@" } @@ -479,6 +497,24 @@ EOF fi fi +# evdev +if [ "x$have_evdev" = "x" ]; then + cat > $TMPC < +EOF + have_evdev="no" + if compile_object; then + have_evdev="yes" + else + cat > $TMPC < +EOF + if compile_object; then + have_evdev="yes" + fi + fi +fi + # check for VideoCore stuff for Raspberry Pi if [ -d /opt/vc/include -a -d /opt/vc/lib -a "$VIDEOCORE" != "no" ]; then CFLAGS_GLES="$CFLAGS_GLES -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux" @@ -604,11 +640,20 @@ fi if [ "$have_tslib" = "yes" ]; then echo "HAVE_TSLIB = 1" >> $config_mak fi +if [ "$have_evdev" = "yes" ]; then + echo "HAVE_EVDEV = 1" >> $config_mak +fi if [ "$have_gles" = "yes" ]; then echo "HAVE_GLES = 1" >> $config_mak echo "CFLAGS_GLES = $CFLAGS_GLES" >> $config_mak echo "LDLIBS_GLES = $LDLIBS_GLES" >> $config_mak fi +if [ "$have_fsections" = "no" ]; then + echo "NO_FSECTIONS = 1" >> $config_mak +fi +if [ "$gnu_linker" = "yes" ]; then + echo "GNU_LINKER = 1" >> $config_mak +fi echo "DYNAREC = $dynarec" >> $config_mak if [ "$drc_cache_base" = "yes" ]; then echo "BASE_ADDR_DYNAMIC = 1" >> $config_mak diff --git a/frontend/menu.c b/frontend/menu.c index ecd69183..0c02118b 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -9,11 +9,6 @@ */ #define _GNU_SOURCE 1 -#ifdef __FreeBSD__ -#define STAT stat -#else -#define STAT stat64 -#endif #include #include #include @@ -45,10 +40,16 @@ #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../plugins/dfsound/spu_config.h" #include "psemu_plugin_defs.h" +#include "compiler_features.h" #include "arm_features.h" #include "revision.h" #define REARMED_BIRTHDAY_TIME 1293306830 /* 25 Dec 2010 */ +#if defined(__linux__) && (!defined(__SIZEOF_POINTER__) || __SIZEOF_POINTER__ == 4) +#define STAT stat64 +#else +#define STAT stat +#endif #define array_size(x) (sizeof(x) / sizeof(x[0])) @@ -111,6 +112,7 @@ int g_opts, g_scaler, g_gamma = 100; int scanlines, scanline_level = 20; int soft_scaling, analog_deadzone; // for Caanoo int soft_filter; +int in_evdev_allow_abs_only attr_weak; // FIXME #ifndef HAVE_PRE_ARMV7 #define DEFAULT_PSX_CLOCK (10000 / CYCLE_MULT_DEFAULT) @@ -1279,7 +1281,7 @@ static const char *men_scaler[] = { "1x1", "integer scaled 2x", "scaled 4:3", "integer scaled 4:3", "fullscreen", "custom", NULL }; static const char *men_soft_filter[] = { "None", -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 "scale2x", "eagle2x", #endif NULL }; @@ -1292,7 +1294,7 @@ static const char h_cscaler[] = "Displays the scaler layer, you can resize it\ "using d-pad or move it using R+d-pad"; static const char h_soft_filter[] = "Works only if game uses low resolution modes"; static const char h_gamma[] = "Gamma/brightness adjustment (default 100)"; -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 static const char *men_scanlines[] = { "OFF", "1", "2", "3", NULL }; static const char h_scanline_l[] = "Scanline brightness, 0-100%"; #endif @@ -1388,7 +1390,7 @@ static menu_entry e_menu_gfx_options[] = mee_onoff ("Software Scaling", MA_OPT_SCALER2, soft_scaling, 1), mee_enum ("Hardware Filter", MA_OPT_HWFILTER, plat_target.hwfilter, men_dummy), mee_enum_h ("Software Filter", MA_OPT_SWFILTER, soft_filter, men_soft_filter, h_soft_filter), -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 mee_enum ("Scanlines", MA_OPT_SCANLINES, scanlines, men_scanlines), mee_range_h ("Scanline brightness", MA_OPT_SCANLINE_LEVEL, scanline_level, 0, 100, h_scanline_l), #endif diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index 9b2fee34..cacaf943 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -36,6 +36,7 @@ #include "../libpcsxcore/gpu.h" #include "../libpcsxcore/r3000a.h" #include "../libpcsxcore/psxcounters.h" +#include "arm_features.h" #define HUD_HEIGHT 10 @@ -265,7 +266,7 @@ static void pl_vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp) assert(vout_h >= 192); pl_vout_scale_w = pl_vout_scale_h = 1; -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 if (soft_filter) { if (resolution_ok(w * 2, h * 2) && bpp == 16) { pl_vout_scale_w = 2; @@ -379,7 +380,7 @@ static void pl_vout_flip(const void *vram, int stride, int bgr24, } } } -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 else if (soft_filter == SOFT_FILTER_SCALE2X && pl_vout_scale_w == 2) { neon_scale2x_16_16(src, (void *)dest, w, @@ -496,7 +497,7 @@ static int dispmode_doubleres(void) } #endif -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 static int dispmode_scale2x(void) { if (!resolution_ok(psx_w * 2, psx_h * 2) || psx_bpp != 16) @@ -525,7 +526,7 @@ static int (*dispmode_switchers[])(void) = { #ifdef BUILTIN_GPU_NEON dispmode_doubleres, #endif -#ifdef __ARM_NEON__ +#ifdef HAVE_NEON32 dispmode_scale2x, dispmode_eagle2x, #endif diff --git a/libpcsxcore/new_dynarec/linkage_arm64.S b/libpcsxcore/new_dynarec/linkage_arm64.S index 730f9cac..e2f795d3 100644 --- a/libpcsxcore/new_dynarec/linkage_arm64.S +++ b/libpcsxcore/new_dynarec/linkage_arm64.S @@ -28,6 +28,7 @@ #define dynarec_local ESYM(dynarec_local) #define ndrc_patch_link ESYM(ndrc_patch_link) #define ndrc_get_addr_ht ESYM(ndrc_get_addr_ht) +#define ndrc_get_addr_ht_param ESYM(ndrc_get_addr_ht_param) #define gen_interupt ESYM(gen_interupt) #define psxException ESYM(psxException) #define execI ESYM(execI) diff --git a/libpcsxcore/new_dynarec/new_dynarec.c b/libpcsxcore/new_dynarec/new_dynarec.c index 0e08aa50..19df23a5 100644 --- a/libpcsxcore/new_dynarec/new_dynarec.c +++ b/libpcsxcore/new_dynarec/new_dynarec.c @@ -3386,6 +3386,7 @@ static void do_store_smc_check(int i, const struct regstat *i_regs, u_int reglis emit_cmpmem_indexedsr12_imm(invalid_code, addr, 1); #error not handled #endif + (void)count; #ifdef INVALIDATE_USE_COND_CALL if (count == 1) { emit_cmpimm(HOST_TEMPREG, 1); diff --git a/plugins/gpulib/gpulib.mak b/plugins/gpulib/gpulib.mak index e861c74f..65b443ea 100644 --- a/plugins/gpulib/gpulib.mak +++ b/plugins/gpulib/gpulib.mak @@ -2,7 +2,10 @@ # always adding gpulib to deps (XXX might be no longer needed) # users must include ../../config.mak -LDFLAGS += -shared -Wl,--no-undefined +LDFLAGS += -shared +ifeq ($(GNU_LINKER),1) +LDFLAGS += -Wl,--no-undefined +endif CFLAGS += $(PLUGIN_CFLAGS) #LDLIBS_GPULIB += `sdl-config --libs` ifdef DEBUG -- 2.39.5