Skip to content

Commit

Permalink
libretro: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
retro-wertz committed Jun 4, 2018
1 parent b0982ac commit 1f20ba8
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 89 deletions.
140 changes: 134 additions & 6 deletions src/libretro/Makefile
@@ -1,6 +1,13 @@
TILED_RENDERING=0
STATIC_LINKING=0

SPACE :=
SPACE := $(SPACE) $(SPACE)
BACKSLASH :=
BACKSLASH := \$(BACKSLASH)
filter_out1 = $(filter-out $(firstword $1),$1)
filter_out2 = $(call filter_out1,$(call filter_out1,$1))

ifeq ($(platform),)
platform = unix
ifeq ($(shell uname -a),)
Expand Down Expand Up @@ -109,6 +116,97 @@ else ifeq ($(platform), vita)
USE_THREADED_RENDERER=1
USE_MOTION_SENSOR=1
HAVE_NEON=1

# Windows MSVC 2017 all architectures
else ifneq (,$(findstring windows_msvc2017,$(platform)))

PlatformSuffix = $(subst windows_msvc2017_,,$(platform))
ifneq (,$(findstring desktop,$(PlatformSuffix)))
WinPartition = desktop
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -FS
LDFLAGS += -MANIFEST -LTCG:incremental -NXCOMPAT -DYNAMICBASE -DEBUG -OPT:REF -INCREMENTAL:NO -SUBSYSTEM:WINDOWS -MANIFESTUAC:"level='asInvoker' uiAccess='false'" -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1
LIBS := kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
else ifneq (,$(findstring uwp,$(PlatformSuffix)))
WinPartition = uwp
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -EHsc -FS
LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO
LIBS := WindowsApp.lib
endif

CFLAGS += $(MSVC2017CompileFlags)
CXXFLAGS += $(MSVC2017CompileFlags)

TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))

CC = cl.exe
CXX = cl.exe
LD = link.exe

reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul)))
fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))

ProgramFiles86w := $(shell cmd /c "echo %PROGRAMFILES(x86)%")
ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")

WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir := $(WindowsSdkDir)

WindowsSDKVersion ?= $(firstword $(foreach folder,$(subst $(subst \,/,$(WindowsSdkDir)Include/),,$(wildcard $(call fix_path,$(WindowsSdkDir)Include\*))),$(if $(wildcard $(call fix_path,$(WindowsSdkDir)Include/$(folder)/um/Windows.h)),$(folder),)))$(BACKSLASH)
WindowsSDKVersion := $(WindowsSDKVersion)

VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools
VsInstallEnterprise = $(ProgramFiles86)/Microsoft Visual Studio/2017/Enterprise
VsInstallProfessional = $(ProgramFiles86)/Microsoft Visual Studio/2017/Professional
VsInstallCommunity = $(ProgramFiles86)/Microsoft Visual Studio/2017/Community

VsInstallRoot ?= $(shell if [ -d "$(VsInstallBuildTools)" ]; then echo "$(VsInstallBuildTools)"; fi)
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallEnterprise)" ]; then echo "$(VsInstallEnterprise)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallProfessional)" ]; then echo "$(VsInstallProfessional)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallCommunity)" ]; then echo "$(VsInstallCommunity)"; fi)
endif
VsInstallRoot := $(VsInstallRoot)

VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)

WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")

# For some reason the HostX86 compiler doesn't like compiling for x64
# ("no such file" opening a shared library), and vice-versa.
# Work around it for now by using the strictly x86 compiler for x86, and x64 for x64.
# NOTE: What about ARM?
ifneq (,$(findstring x64,$(TargetArchMoniker)))
VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX64
else
VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX86
endif

PATH := $(shell IFS=$$'\n'; cygpath "$(VCCompilerToolsBinDir)/$(TargetArchMoniker)"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE")
INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)")
ifneq (,$(findstring uwp,$(PlatformSuffix)))
LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store")
endif

export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir)
export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir)
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL

else
TARGET := $(TARGET_NAME)_libretro.dll
LDFLAGS += -Wl,-no-undefined -Wl,--version-script=link.T
Expand All @@ -134,20 +232,50 @@ ifeq ($(DEBUG), 1)
CFLAGS += -g
CXXFLAGS += -g
else
CFLAGS += -O3 -DNDEBUG
CXXFLAGS += -O3 -DNDEBUG
CFLAGS += -O2 -DNDEBUG
CXXFLAGS += -O2 -DNDEBUG
endif

CFLAGS += $(fpic) $(VBA_DEFINES)
CXXFLAGS += $(fpic) $(VBA_DEFINES)

LIBS :=
OBJOUT = -o
LINKOUT = -o

ifneq (,$(findstring msvc,$(platform)))
OBJOUT = -Fo
LINKOUT = -out:
ifeq ($(STATIC_LINKING),1)
LD ?= lib.exe
STATIC_LINKING=0

ifeq ($(DEBUG), 1)
CFLAGS += -MTd
CXXFLAGS += -MTd
else
CFLAGS += -MT
CXXFLAGS += -MT
endif
else
LD = link.exe

ifeq ($(DEBUG), 1)
CFLAGS += -MDd
CXXFLAGS += -MDd
else
CFLAGS += -MD
CXXFLAGS += -MD
endif
endif
else
LD = $(CXX)
endif

%.o: %.cpp
$(CXX) -c -o $@ $< $(CXXFLAGS) $(INCFLAGS)
$(CXX) -c $(OBJOUT)$@ $< $(CXXFLAGS) $(INCFLAGS)

%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS) $(INCFLAGS)
$(CC) -c $(OBJOUT)$@ $< $(CFLAGS) $(INCFLAGS)

ifeq ($(platform), theos_ios)
COMMON_FLAGS := -DIOS $(COMMON_DEFINES) $(INCFLAGS) -I$(THEOS_INCLUDE_PATH) -Wno-error
Expand All @@ -162,7 +290,7 @@ $(TARGET): $(OBJS)
ifeq ($(STATIC_LINKING), 1)
$(AR) rcs $@ $(OBJS)
else
$(CXX) -o $@ $(SHARED) $(OBJS) $(LDFLAGS) $(LIBS)
$(LD) $(LINKOUT)$@ $(SHARED) $(OBJS) $(LDFLAGS) $(LIBS)
endif

clean:
Expand Down
1 change: 1 addition & 0 deletions src/libretro/UtilRetro.cpp
Expand Up @@ -150,6 +150,7 @@ uint8_t *utilLoad(const char *file, bool (*accept)(const char *), uint8_t *data,
char *buf = NULL;

fp = fopen(file,"rb");
if(!fp) return NULL;
fseek(fp, 0, SEEK_END); //go to end
size = ftell(fp); // get position at end (length)
rewind(fp);
Expand Down
71 changes: 12 additions & 59 deletions src/libretro/jni/Android.mk
@@ -1,67 +1,20 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
CORE_DIR := $(LOCAL_PATH)/../..
LIBRETRO_DIR := $(CORE_DIR)/libretro

GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
LOCAL_CXXFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
include $(LIBRETRO_DIR)/Makefile.common

ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS += -DANDROID_ARM
LOCAL_ARM_MODE := arm
endif

ifeq ($(TARGET_ARCH),x86)
LOCAL_CFLAGS += -DANDROID_X86
endif
COREFLAGS := -DHAVE_STDINT_H -DLSB_FIRST -D__LIBRETRO__ -DFINAL_VERSION -DC_CORE -DNO_LINK -DFRONTEND_SUPPORTS_RGB565 -DTILED_RENDERING $(INCFLAGS)

ifeq ($(TARGET_ARCH),mips)
LOCAL_CFLAGS += -DANDROID_MIPS
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
COREFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif

VBADIR = ../../

LOCAL_MODULE := libretro
LOCAL_SRC_FILES = $(VBADIR)/gba/agbprint.cpp \
$(VBADIR)/gba/armdis.cpp \
$(VBADIR)/gba/bios.cpp \
$(VBADIR)/gba/Cheats.cpp \
$(VBADIR)/gba/CheatSearch.cpp \
$(VBADIR)/gba/EEprom.cpp \
$(VBADIR)/gba/elf.cpp \
$(VBADIR)/gba/ereader.cpp \
$(VBADIR)/gba/Flash.cpp \
$(VBADIR)/gba/GBA-arm.cpp \
$(VBADIR)/gba/GBA.cpp \
$(VBADIR)/gba/gbafilter.cpp \
$(VBADIR)/gba/GBAGfx.cpp \
$(VBADIR)/gba/GBALink.cpp \
$(VBADIR)/gba/GBASockClient.cpp \
$(VBADIR)/gba/GBA-thumb.cpp \
$(VBADIR)/gba/Globals.cpp \
$(VBADIR)/gba/Mode0.cpp \
$(VBADIR)/gba/Mode1.cpp \
$(VBADIR)/gba/Mode2.cpp \
$(VBADIR)/gba/Mode3.cpp \
$(VBADIR)/gba/Mode4.cpp \
$(VBADIR)/gba/Mode5.cpp \
$(VBADIR)/gba/remote.cpp \
$(VBADIR)/gba/RTC.cpp \
$(VBADIR)/gba/Sound.cpp \
$(VBADIR)/gba/Sram.cpp \
$(VBADIR)/apu/Blip_Buffer.cpp \
$(VBADIR)/apu/Effects_Buffer.cpp \
$(VBADIR)/apu/Gb_Apu.cpp \
$(VBADIR)/apu/Gb_Apu_State.cpp \
$(VBADIR)/apu/Gb_Oscs.cpp \
$(VBADIR)/apu/Multi_Buffer.cpp \
$(VBADIR)/libretro/libretro.cpp \
$(VBADIR)/libretro/UtilRetro.cpp \
$(VBADIR)/libretro/SoundRetro.cpp \
$(VBADIR)/libretro/scrc32.cpp

LOCAL_CFLAGS = -O3 -DINLINE=inline -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DLSB_FIRST -D__LIBRETRO__ -DFINAL_VERSION -DC_CORE -DUSE_GBA_ONLY -DNO_LINK -DFRONTEND_SUPPORTS_RGB565 -DTILED_RENDERING
LOCAL_C_INCLUDES = $(VBADIR)

include $(CLEAR_VARS)
LOCAL_MODULE := retro
LOCAL_SRC_FILES := $(SOURCES_CXX)
LOCAL_CXXFLAGS := $(COREFLAGS)
LOCAL_LDFLAGS := -Wl,-version-script=$(LIBRETRO_DIR)/link.T
include $(BUILD_SHARED_LIBRARY)
2 changes: 2 additions & 0 deletions src/libretro/jni/Application.mk
@@ -1 +1,3 @@
APP_ABI := all
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.9

0 comments on commit 1f20ba8

Please sign in to comment.