mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-01 17:12:53 +02:00
Allow building libsameboy as a dynamic lib
This commit is contained in:
52
Makefile
52
Makefile
@@ -13,6 +13,8 @@ ifneq ($(findstring MSYS,$(PLATFORM)),)
|
|||||||
PLATFORM := windows32
|
PLATFORM := windows32
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
DL_EXT := so
|
||||||
|
|
||||||
ifeq ($(PLATFORM),windows32)
|
ifeq ($(PLATFORM),windows32)
|
||||||
_ := $(shell chcp 65001)
|
_ := $(shell chcp 65001)
|
||||||
EXESUFFIX:=.exe
|
EXESUFFIX:=.exe
|
||||||
@@ -29,6 +31,7 @@ PB12_COMPRESS := build/pb12$(EXESUFFIX)
|
|||||||
ifeq ($(PLATFORM),Darwin)
|
ifeq ($(PLATFORM),Darwin)
|
||||||
DEFAULT := cocoa
|
DEFAULT := cocoa
|
||||||
ENABLE_OPENAL ?= 1
|
ENABLE_OPENAL ?= 1
|
||||||
|
DL_EXT := dylib
|
||||||
else
|
else
|
||||||
DEFAULT := sdl
|
DEFAULT := sdl
|
||||||
endif
|
endif
|
||||||
@@ -345,9 +348,6 @@ LDFLAGS += -Wl,-exported_symbols_list,$(NULL)
|
|||||||
STRIP := strip -x
|
STRIP := strip -x
|
||||||
CODESIGN := codesign -fs -
|
CODESIGN := codesign -fs -
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),windows32)
|
|
||||||
LDFLAGS += -fuse-ld=lld
|
|
||||||
endif
|
|
||||||
LDFLAGS += -flto
|
LDFLAGS += -flto
|
||||||
CFLAGS += -flto
|
CFLAGS += -flto
|
||||||
LDFLAGS += -Wno-lto-type-mismatch # For GCC's LTO
|
LDFLAGS += -Wno-lto-type-mismatch # For GCC's LTO
|
||||||
@@ -356,6 +356,9 @@ else
|
|||||||
$(error Invalid value for CONF: $(CONF). Use "debug", "release" or "native_release")
|
$(error Invalid value for CONF: $(CONF). Use "debug", "release" or "native_release")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),windows32)
|
||||||
|
LDFLAGS += -fuse-ld=lld
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
# Define our targets
|
# Define our targets
|
||||||
@@ -377,9 +380,9 @@ _ios: $(BIN)/SameBoy-iOS.app $(OBJ)/installer
|
|||||||
ios-ipa: $(BIN)/SameBoy-iOS.ipa
|
ios-ipa: $(BIN)/SameBoy-iOS.ipa
|
||||||
ios-deb: $(BIN)/SameBoy-iOS.deb
|
ios-deb: $(BIN)/SameBoy-iOS.deb
|
||||||
ifeq ($(PLATFORM),windows32)
|
ifeq ($(PLATFORM),windows32)
|
||||||
lib: lib-unsupported
|
lib: $(LIBDIR)/libsameboy.dll
|
||||||
else
|
else
|
||||||
lib: $(LIBDIR)/libsameboy.o $(LIBDIR)/libsameboy.a
|
lib: $(LIBDIR)/libsameboy.o $(LIBDIR)/libsameboy.a $(LIBDIR)/libsameboy.$(DL_EXT)
|
||||||
endif
|
endif
|
||||||
all: sdl tester libretro lib
|
all: sdl tester libretro lib
|
||||||
ifeq ($(PLATFORM),Darwin)
|
ifeq ($(PLATFORM),Darwin)
|
||||||
@@ -554,7 +557,7 @@ endif
|
|||||||
|
|
||||||
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy: $(BIN)/SameBoy.app/Contents/MacOS/SameBoy.dylib
|
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy: $(BIN)/SameBoy.app/Contents/MacOS/SameBoy.dylib
|
||||||
$(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -rpath @executable_path/../../ -Wl,-reexport_library,$^
|
$(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -rpath @executable_path/../../ -Wl,-reexport_library,$^
|
||||||
|
|
||||||
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy.dylib: $(COCOA_OBJECTS) $(CORE_OBJECTS) $(QUICKLOOK_OBJECTS)
|
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy.dylib: $(COCOA_OBJECTS) $(CORE_OBJECTS) $(QUICKLOOK_OBJECTS)
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
$(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -shared -install_name @rpath/Contents/MacOS/SameBoy.dylib -framework OpenGL -framework AudioUnit -framework AVFoundation -framework CoreVideo -framework CoreMedia -framework IOKit -framework PreferencePanes -framework Carbon -framework QuartzCore -framework Security -framework WebKit -weak_framework Metal -weak_framework MetalKit -framework Quicklook -framework AppKit -Wl,-exported_symbols_list,QuickLook/exports.sym -Wl,-exported_symbol,_main
|
$(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -shared -install_name @rpath/Contents/MacOS/SameBoy.dylib -framework OpenGL -framework AudioUnit -framework AVFoundation -framework CoreVideo -framework CoreMedia -framework IOKit -framework PreferencePanes -framework Carbon -framework QuartzCore -framework Security -framework WebKit -weak_framework Metal -weak_framework MetalKit -framework Quicklook -framework AppKit -Wl,-exported_symbols_list,QuickLook/exports.sym -Wl,-exported_symbol,_main
|
||||||
@@ -614,7 +617,7 @@ ifeq ($(CONF), release)
|
|||||||
$(CODESIGN) $@
|
$(CODESIGN) $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Windows version builds two, one with a conole and one without it
|
# Windows version builds two, one with a console and one without it
|
||||||
$(BIN)/SDL/sameboy.exe: $(CORE_OBJECTS) $(SDL_OBJECTS) $(OBJ)/Windows/resources.o
|
$(BIN)/SDL/sameboy.exe: $(CORE_OBJECTS) $(SDL_OBJECTS) $(OBJ)/Windows/resources.o
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS) $(GL_LDFLAGS) -Wl,/subsystem:windows
|
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS) $(GL_LDFLAGS) -Wl,/subsystem:windows
|
||||||
@@ -798,14 +801,39 @@ $(LIBDIR)/libsameboy.a: $(LIBDIR)/libsameboy.o
|
|||||||
-@rm -f $@
|
-@rm -f $@
|
||||||
ar -crs $@ $^
|
ar -crs $@ $^
|
||||||
|
|
||||||
|
$(LIBDIR)/libsameboy.$(DL_EXT): $(CORE_OBJECTS)
|
||||||
|
-@$(MKDIR) -p $(dir $@)
|
||||||
|
$(CC) $(LDFLAGS) -shared $(FAT_FLAGS) $(CFLAGS) $^ -o $@
|
||||||
|
ifeq ($(CONF), release)
|
||||||
|
$(STRIP) $@
|
||||||
|
$(CODESIGN)$@
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# Windows dll
|
||||||
|
|
||||||
|
# To avoid Windows' sort.exe
|
||||||
|
SORT = $(dir $(shell which grep))\sort.exe
|
||||||
|
|
||||||
|
$(OBJ)/names: $(CORE_OBJECTS)
|
||||||
|
llvm-nm -gU $(CORE_OBJECTS) -P | grep -Eo "^GB_[^ ]+" | $(SORT) -u > $@
|
||||||
|
|
||||||
|
$(OBJ)/exports: $(PUBLIC_HEADERS)
|
||||||
|
grep -Eho "\bGB_[a-zA-Z0-9_]+\b" $^ | $(dir $(shell which grep))\sort.exe -u > $@
|
||||||
|
|
||||||
|
$(OBJ)/exports.def: $(OBJ)/exports $(OBJ)/names
|
||||||
|
echo LIBRARY libsameboy > $@
|
||||||
|
echo EXPORTS >> $@
|
||||||
|
comm -12 $^ >> $@
|
||||||
|
|
||||||
|
$(LIBDIR)/libsameboy.dll: $(CORE_OBJECTS) | $(OBJ)/exports.def
|
||||||
|
-@$(MKDIR) -p $(dir $@)
|
||||||
|
$(CC) $(LDFLAGS) -Wl,-lldmingw -Wl,/def:$(OBJ)/exports.def -shared $(CFLAGS) $^ -o $@
|
||||||
|
|
||||||
|
# CPPP doesn't like multibyte characters, so we replace the single quote character before processing so it doesn't complain
|
||||||
$(INC)/%.h: Core/%.h
|
$(INC)/%.h: Core/%.h
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
-@# CPPP doesn't like multibyte characters, so we replace the single quote character before processing so it doesn't complain
|
|
||||||
sed "s/'/@SINGLE_QUOTE@/g" $^ | cppp $(CPPP_FLAGS) | sed "s/@SINGLE_QUOTE@/'/g" > $@
|
sed "s/'/@SINGLE_QUOTE@/g" $^ | cppp $(CPPP_FLAGS) | sed "s/@SINGLE_QUOTE@/'/g" > $@
|
||||||
|
|
||||||
lib-unsupported:
|
|
||||||
@echo Due to limitations of lld-link, compiling SameBoy as a library on Windows is not supported.
|
|
||||||
@false
|
|
||||||
|
|
||||||
# Clean
|
# Clean
|
||||||
clean:
|
clean:
|
||||||
|
@@ -43,7 +43,7 @@ SameBoy requires the following tools and libraries to build:
|
|||||||
* macOS Cocoa frontend: macOS SDK and Xcode (For command line tools and ibtool)
|
* macOS Cocoa frontend: macOS SDK and Xcode (For command line tools and ibtool)
|
||||||
* SDL frontend: libsdl2
|
* SDL frontend: libsdl2
|
||||||
* [rgbds](https://github.com/gbdev/rgbds/releases/), for boot ROM compilation
|
* [rgbds](https://github.com/gbdev/rgbds/releases/), for boot ROM compilation
|
||||||
* [cppp](https://github.com/BR903/cppp), for cleaning up headers when compiling SameBoy as a library
|
* [cppp](https://github.com/LIJI32/cppp), for cleaning up headers when compiling SameBoy as a library
|
||||||
|
|
||||||
On Windows, SameBoy also requires:
|
On Windows, SameBoy also requires:
|
||||||
* Visual Studio (For headers, etc.)
|
* Visual Studio (For headers, etc.)
|
||||||
|
@@ -1 +1 @@
|
|||||||
VERSION := 0.16.6
|
VERSION := 1.0
|
Reference in New Issue
Block a user