make: try a different way to detect 32bit neon
[pcsx_rearmed.git] / Makefile.libretro
index 60feab4..cf8e080 100644 (file)
@@ -3,6 +3,7 @@
 DEBUG ?= 0
 WANT_ZLIB ?= 1
 HAVE_CHD ?= 1
+USE_LIBRETRO_VFS ?= 0
 
 # Dynarec options: lightrec, ari64
 DYNAREC ?= lightrec
@@ -27,6 +28,7 @@ CC_AS ?= $(CC)
 CFLAGS ?=
 
 TARGET_NAME := pcsx_rearmed
+ARCH_DETECTED := $(shell $(CC) -dumpmachine | awk -F- '{print $$1}')
 GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
 ifneq ($(GIT_VERSION)," unknown")
        CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
@@ -44,20 +46,34 @@ LIBM := -lm
 MMAP_WIN32 = 0
 EXTRA_LDFLAGS =
 
+# select some defaults
+ifneq (,$(findstring $(ARCH_DETECTED),arm aarch64))
+       DYNAREC = ari64
+ifneq ($(findstring __thumb__,$(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h)),)
+       # must disable thumb as ari64 can't handle it
+       CFLAGS += -marm
+endif
+ifneq ($(findstring __ARM_NEON,$(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h)),)
+       BUILTIN_GPU = neon
+endif
+endif
+ifneq (,$(findstring $(ARCH_DETECTED),i686 x86_64 aarch64))
+       BUILTIN_GPU = neon
+endif
+
+# platform specific options
+
 # Unix
 ifeq ($(platform), unix)
        TARGET := $(TARGET_NAME)_libretro.so
        fpic := -fPIC
        THREAD_RENDERING = 1
+ifeq ($(shell uname),Linux)
+       LIGHTREC_CUSTOM_MAP := 1
+endif
 ifneq ($(findstring SunOS,$(shell uname -s)),)
        CC = gcc
 endif
-ifeq ($(ARCH), arm)
-ifneq ($(findstring __thumb__,$(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h)),)
-       # must disable thumb as recompiler can't handle it
-       CFLAGS += -marm
-endif
-endif
 
 # ODROIDN2
 else ifneq (,$(findstring CortexA73_G12B,$(platform)))
@@ -65,6 +81,9 @@ else ifneq (,$(findstring CortexA73_G12B,$(platform)))
        fpic := -fPIC
        SHARED := -shared -Wl,-version-script=link.T
        ARCH = arm64
+       BUILTIN_GPU = neon
+       HAVE_NEON = 1
+       DYNAREC = ari64
        CFLAGS += -fomit-frame-pointer -ffast-math -DARM
        CPUFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8 -mcpu=cortex-a73 -mtune=cortex-a73.cortex-a53
 
@@ -74,7 +93,9 @@ else ifneq (,$(findstring h5,$(platform)))
        fpic := -fPIC
        SHARED := -shared -Wl,-version-script=link.T
        ARCH = arm64
-       DYNAREC ?= lightrec
+       BUILTIN_GPU = neon
+       HAVE_NEON = 1
+       DYNAREC = ari64
        CFLAGS += -fomit-frame-pointer -ffast-math -DARM
        CPUFLAGS += -march=armv8-a+crc -mfpu=neon-fp-armv8 -mcpu=cortex-a53 -mtune=cortex-a53
 
@@ -87,38 +108,40 @@ else ifeq ($(platform), linux-portable)
        LIBDL :=
        LIBM :=
        NO_UNDEF_CHECK = 1
+       LIGHTREC_CUSTOM_MAP := 1
 
 # OS X
 else ifeq ($(platform), osx)
-       DYNAREC ?= lightrec
+       DYNAREC := 0
        TARGET := $(TARGET_NAME)_libretro.dylib
        fpic := -fPIC
-       fpic += -mmacosx-version-min=10.1
-
-# iOS
-else ifeq ($(platform),$(filter $(platform),ios-arm64))
-       ARCH := arm64
        HAVE_NEON = 0
-       BUILTIN_GPU = peops
-       DYNAREC = 0
-       TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
-
-       CC = clang -arch arm64 -isysroot $(IOSSDK) -miphoneos-version-min=8.0
-       CXX = clang++ -arch arm64 -isysroot $(IOSSDK) -miphoneos-version-min=8.0
-       CFLAGS += -marm -DIOS
+   MACSOSVER = `sw_vers -productVersion | cut -d. -f 1`
+   OSXVER = `sw_vers -productVersion | cut -d. -f 2`
+   OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
+   ifeq ($(OSX_LT_MAVERICKS),YES)
+          fpic += -mmacosx-version-min=10.1
+   endif
+
+   ifeq ($(CROSS_COMPILE),1)
+               TARGET_RULE   = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
+               CFLAGS   += $(TARGET_RULE)
+               CPPFLAGS += $(TARGET_RULE)
+               CXXFLAGS += $(TARGET_RULE)
+               LDFLAGS  += $(TARGET_RULE)
+   endif
+
+       CFLAGS  += $(ARCHFLAGS)
+       CXXFLAGS  += $(ARCHFLAGS)
+       LDFLAGS += $(ARCHFLAGS)
 
+# iOS
 else ifneq (,$(findstring ios,$(platform)))
-       ARCH := arm
-#      DYNAREC ?= ari64
-       HAVE_NEON = 1
-       BUILTIN_GPU = neon
        TARGET := $(TARGET_NAME)_libretro_ios.dylib
+       MINVERSION :=
 ifeq ($(DYNAREC),lightrec)
        # Override
        DYNAREC := 0
-endif
-ifeq ($(DYNAREC),0)
-       TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
 endif
        fpic := -fPIC
 
@@ -126,23 +149,53 @@ endif
                IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
        endif
 
-       CC = clang -arch armv7 -isysroot $(IOSSDK)
-       CXX = clang++ -arch armv7 -isysroot $(IOSSDK)
-       CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
-       CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -marm
+       CFLAGS += -DIOS -marm
+ifeq ($(platform),ios-arm64)
+        CC = cc -arch arm64 -isysroot $(IOSSDK)
+       CXX = c++ -arch arm64 -isysroot $(IOSSDK)
+       ARCH := arm64
+       BUILTIN_GPU = neon
+       HAVE_NEON = 1
+       DYNAREC = 0
+else
+       CC = cc -arch armv7 -isysroot $(IOSSDK)
+       CXX = c++ -arch armv7 -isysroot $(IOSSDK)
+       ARCH := arm
+       HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
+       BUILTIN_GPU = neon
+       CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
        ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
-       CFLAGS += -DIOS
-ifeq ($(platform),ios9)
-       CC     += -miphoneos-version-min=8.0
-       CXX    += -miphoneos-version-min=8.0
-       CC_AS  += -miphoneos-version-min=8.0
-       CFLAGS += -miphoneos-version-min=8.0
+endif
+       CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
+ifeq ($(platform),$(filter $(platform),ios9 ios-arm64))
+       MINVERSION = -miphoneos-version-min=8.0
 else
-       CC     += -miphoneos-version-min=5.0
-       CXX    += -miphoneos-version-min=5.0
-       CC_AS  += -miphoneos-version-min=5.0
-       CFLAGS += -miphoneos-version-min=5.0
+       MINVERSION = -miphoneos-version-min=5.0
+endif
+       CFLAGS += $(MINVERSION)
+
+else ifeq ($(platform), tvos-arm64)
+       TARGET := $(TARGET_NAME)_libretro_tvos.dylib
+       MINVERSION :=
+ifeq ($(DYNAREC),lightrec)
+       # Override
+       DYNAREC := 0
 endif
+       fpic := -fPIC
+
+       ifeq ($(IOSSDK),)
+               IOSSDK := $(shell xcodebuild -version -sdk appletvos Path)
+       endif
+
+       CFLAGS += -DIOS -DTVOS
+        CC = cc -arch arm64 -isysroot $(IOSSDK)
+       CXX = c++ -arch arm64 -isysroot $(IOSSDK)
+       ARCH := arm64
+       BUILTIN_GPU = neon
+       HAVE_NEON = 1
+       DYNAREC = 0
+       CC_AS = perl ./tools/gas-preprocessor.pl $(CC)
 
 # Nintendo Switch (libnx)
 else ifeq ($(platform), libnx)
@@ -150,24 +203,26 @@ else ifeq ($(platform), libnx)
    include $(DEVKITPRO)/libnx/switch_rules
    TARGET := $(TARGET_NAME)_libretro_$(platform).a
    ARCH := arm64
-   BUILTIN_GPU = unai
    HAVE_VFS_FD = 0
-   CFLAGS += -O3 -fomit-frame-pointer -ffast-math -I$(DEVKITPRO)/libnx/include/ -fPIE -Wl,--allow-multiple-definition -include $(LIBNX)/include/switch.h
+   CFLAGS += -O3 -fomit-frame-pointer -ffast-math -I$(DEVKITPRO)/libnx/include/ -fPIE -Wl,--allow-multiple-definition -include $(LIBNX)/include/switch.h
    CFLAGS += -specs=$(DEVKITPRO)/libnx/switch.specs -DNO_OS -DNO_DYLIB -DNO_SOCKET -D__arm64__ -D__ARM_NEON__
-   CFLAGS += -D__SWITCH__
+   CFLAGS += -D__SWITCH__ -DHAVE_LIBNX
    CFLAGS += -DARM -D__aarch64__=1 -march=armv8-a -mtune=cortex-a57 -mtp=soft -DHAVE_INTTYPES -DLSB_FIRST -ffast-math -mcpu=cortex-a57+crc+fp+simd -ffunction-sections
    CFLAGS += -ftree-vectorize
    CFLAGS += -Ifrontend/switch -ftree-vectorize
    LIBPTHREAD :=
    STATIC_LINKING=1
-   # Lightning requires rw/rx patches first
-   DYNAREC := 0
+   BUILTIN_GPU = neon
+   HAVE_NEON = 1
+   DYNAREC = ari64
 
 # Lakka Switch (arm64)
 else ifeq ($(platform), arm64)
    TARGET := $(TARGET_NAME)_libretro.so
    ARCH := arm64
-   BUILTIN_GPU = unai
+   BUILTIN_GPU = neon
+   HAVE_NEON = 1
+   DYNAREC = ari64
    fpic := -fPIC
    CFLAGS := $(filter-out -O2, $(CFLAGS))
    CFLAGS += -O3 -ftree-vectorize
@@ -202,11 +257,10 @@ else ifeq ($(platform), vita)
 
 #      CFLAGS += -U__ARM_NEON__
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        BUILTIN_GPU = neon
 
        DYNAREC = ari64
-       DRC_CACHE_BASE = 0
-
        ARCH = arm
        STATIC_LINKING = 1
 
@@ -222,6 +276,7 @@ else ifeq ($(platform), ctr)
        CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
        CFLAGS += -Ifrontend/3ds -I$(CTRULIB)/include
        CFLAGS += -Werror=implicit-function-declaration
+       CFLAGS += -DHAVE_UNISTD_H
 
        OBJS += frontend/3ds/utils.o
 
@@ -229,7 +284,6 @@ else ifeq ($(platform), ctr)
        BUILTIN_GPU = unai
        THREAD_RENDERING = 1
        DYNAREC = ari64
-       DRC_CACHE_BASE = 0
        ARCH = arm
        HAVE_NEON = 0
        STATIC_LINKING = 1
@@ -262,8 +316,8 @@ else ifeq ($(platform), qnx)
        CC = qcc -Vgcc_ntoarmv7le
        CC_AS = $(CC)
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        DYNAREC = ari64
-       DRC_CACHE_BASE = 0
        BUILTIN_GPU = neon
        ARCH = arm
        CFLAGS += -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
@@ -273,6 +327,17 @@ else ifeq ($(platform), qnx)
        LIBDL :=
        LIBM :=
 
+#Raspberry Pi 1
+else ifeq ($(platform), rpi1)
+       TARGET := $(TARGET_NAME)_libretro.so
+       fpic := -fPIC
+       CFLAGS += -marm -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard
+       ASFLAGS += -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard
+       HAVE_NEON = 0
+       ARCH = arm
+       BUILTIN_GPU = unai
+       DYNAREC = ari64
+
 #Raspberry Pi 2
 else ifeq ($(platform), rpi2)
        TARGET := $(TARGET_NAME)_libretro.so
@@ -280,6 +345,7 @@ else ifeq ($(platform), rpi2)
        CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
        ASFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        ARCH = arm
        BUILTIN_GPU = neon
        DYNAREC = ari64
@@ -291,10 +357,21 @@ else ifeq ($(platform), rpi3)
        CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        ASFLAGS += -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        ARCH = arm
        BUILTIN_GPU = neon
        DYNAREC = ari64
 
+#Raspberry Pi 3 with a 64bit GNU/Linux OS
+else ifeq ($(platform), rpi3_64)
+       TARGET := $(TARGET_NAME)_libretro.so
+       ARCH := arm64
+       BUILTIN_GPU = neon
+       HAVE_NEON = 1
+       DYNAREC = ari64
+       fpic := -fPIC
+       CFLAGS += -march=armv8-a+crc+simd -mtune=cortex-a53 -ftree-vectorize
+
 #Raspberry Pi 4 with a 32bit GNU/Linux OS
 else ifeq ($(platform), rpi4)
        TARGET := $(TARGET_NAME)_libretro.so
@@ -302,6 +379,7 @@ else ifeq ($(platform), rpi4)
        CFLAGS += -marm -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        ASFLAGS += -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        ARCH = arm
        BUILTIN_GPU = neon
        DYNAREC = ari64
@@ -310,8 +388,9 @@ else ifeq ($(platform), rpi4)
 else ifeq ($(platform), rpi4_64)
         TARGET := $(TARGET_NAME)_libretro.so
         ARCH := arm64
-        BUILTIN_GPU = unai
-        DYNAREC = lightrec
+        BUILTIN_GPU = neon
+        HAVE_NEON = 1
+        DYNAREC = ari64
         fpic := -fPIC
         CFLAGS += -march=armv8-a+crc+simd -mtune=cortex-a72 -ftree-vectorize
 
@@ -336,6 +415,7 @@ else ifeq ($(platform), classic_armv7_a7)
        CPPFLAGS += $(CFLAGS)
        ASFLAGS += $(CFLAGS)
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        ARCH = arm
        BUILTIN_GPU = neon
        DYNAREC = ari64
@@ -358,6 +438,7 @@ else ifeq ($(platform), classic_armv8_a35)
        -fmerge-all-constants -fno-math-errno -march=armv8-a \
        -marm -mcpu=cortex-a35 -mtune=cortex-a35 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        HAVE_NEON = 1
+       HAVE_NEON_ASM = 1
        ARCH = arm
        BUILTIN_GPU = neon
        DYNAREC = ari64
@@ -370,7 +451,6 @@ else ifneq (,$(findstring armv,$(platform)))
        TARGET := $(TARGET_NAME)_libretro.so
        fpic := -fPIC
        HAVE_NEON = 0
-       DRC_CACHE_BASE = 0
        BUILTIN_GPU = peops
        ifneq (,$(findstring cortexa8,$(platform)))
                CFLAGS += -marm -mcpu=cortex-a8
@@ -388,6 +468,7 @@ else ifneq (,$(findstring armv,$(platform)))
                CFLAGS += -mfpu=neon
                ASFLAGS += -mfpu=neon
                HAVE_NEON = 1
+               HAVE_NEON_ASM = 1
                BUILTIN_GPU = neon
        endif
        ifneq (,$(findstring softfloat,$(platform)))
@@ -400,6 +481,18 @@ else ifneq (,$(findstring armv,$(platform)))
        ARCH = arm
        DYNAREC = ari64
 
+else ifeq ($(platform), miyoo)
+       TARGET := $(TARGET_NAME)_libretro.so
+       CC = /opt/miyoo/usr/bin/arm-linux-gcc
+       CXX = /opt/miyoo/usr/bin/arm-linux-g++
+       fpic := -fPIC
+       CFLAGS += -mcpu=arm926ej-s -fsingle-precision-constant
+       CFLAGS += -DGPULIB_USE_MMAP -DGPU_UNAI_USE_INT_DIV_MULTINV -D_MIYOO
+       ARCH = arm
+       BUILTIN_GPU = unai
+       DYNAREC = ari64
+       HAVE_NEON = 0
+
 # Emscripten
 else ifeq ($(platform), emscripten)
    TARGET  := $(TARGET_NAME)_libretro_$(platform).bc
@@ -411,7 +504,6 @@ else ifeq ($(platform), emscripten)
 # Windows
 else
        TARGET := $(TARGET_NAME)_libretro.dll
-       BUILTIN_GPU = peops
        PLATFORM = libretro
        MAIN_LDFLAGS += -static-libgcc -static-libstdc++ -s
        CFLAGS += -D__WIN32__ -DNO_DYLIB
@@ -420,6 +512,7 @@ else
        LIBPTHREAD :=
        LIBDL :=
        LIBM :=
+       USE_LIBRETRO_VFS = 1
 endif
 
 CFLAGS += $(fpic)
@@ -433,14 +526,27 @@ endif
 
 # try to autodetect stuff for the lazy
 ifndef ARCH
-ARCH = $(shell $(CC) -dumpmachine | awk -F- '{print $$1}')
+ARCH = $(ARCH_DETECTED)
 endif
-ifndef HAVE_NEON
-HAVE_NEON = $(shell $(CC) -E -dD - < /dev/null 2> /dev/null | grep -q __ARM_NEON__ && echo 1 || echo 0)
+ifndef HAVE_NEON_ASM
+# asm for 32bit only
+HAVE_NEON_ASM = $(shell $(CC) -E -dD $(CFLAGS) include/arm_features.h | grep -q HAVE_NEON32 && echo 1 || echo 0)
 endif
 ifeq ($(NO_UNDEF_CHECK)$(shell ld -v 2> /dev/null | awk '{print $$1}'),GNU)
 MAIN_LDFLAGS += -Wl,--no-undefined
 endif
+ifdef ALLOW_LIGHTREC_ON_ARM
+CFLAGS += -DALLOW_LIGHTREC_ON_ARM
+endif
+ifeq ($(BUILTIN_GPU),neon)
+ifneq (,$(findstring $(ARCH),x86 i686))
+       CFLAGS_GPU_NEON ?= -msse2 # required
+endif
+ifeq ($(ARCH),x86_64)
+       CFLAGS_GPU_NEON ?= -mssse3 # optional, for more perf
+endif
+CFLAGS += $(CFLAGS_GPU_NEON)
+endif
 
 TARGET ?= libretro.so
 PLATFORM = libretro
@@ -458,6 +564,16 @@ NO_CONFIG_MAK = yes
 #endif
 #endif
 
+$(info TARGET:      $(TARGET))
+$(info platform:    $(platform))
+$(info ARCH:        $(ARCH))
+$(info DYNAREC:     $(DYNAREC))
+$(info BUILTIN_GPU: $(BUILTIN_GPU))
+$(info CC:          $(CC))
+$(info CFLAGS:      $(CFLAGS))
+$(info MAIN_LDLIBS: $(MAIN_LDLIBS))
+$(info )
+
 include Makefile
 
 # no special AS needed for gpu_neon