mirror of https://github.com/LIJI32/SameBoy.git
Allow building libsameboy as a dynamic lib
This commit is contained in:
parent
9ff3bffddd
commit
007d3b2555
52
Makefile
52
Makefile
|
@ -13,6 +13,8 @@ ifneq ($(findstring MSYS,$(PLATFORM)),)
|
|||
PLATFORM := windows32
|
||||
endif
|
||||
|
||||
DL_EXT := so
|
||||
|
||||
ifeq ($(PLATFORM),windows32)
|
||||
_ := $(shell chcp 65001)
|
||||
EXESUFFIX:=.exe
|
||||
|
@ -29,6 +31,7 @@ PB12_COMPRESS := build/pb12$(EXESUFFIX)
|
|||
ifeq ($(PLATFORM),Darwin)
|
||||
DEFAULT := cocoa
|
||||
ENABLE_OPENAL ?= 1
|
||||
DL_EXT := dylib
|
||||
else
|
||||
DEFAULT := sdl
|
||||
endif
|
||||
|
@ -345,9 +348,6 @@ LDFLAGS += -Wl,-exported_symbols_list,$(NULL)
|
|||
STRIP := strip -x
|
||||
CODESIGN := codesign -fs -
|
||||
endif
|
||||
ifeq ($(PLATFORM),windows32)
|
||||
LDFLAGS += -fuse-ld=lld
|
||||
endif
|
||||
LDFLAGS += -flto
|
||||
CFLAGS += -flto
|
||||
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")
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),windows32)
|
||||
LDFLAGS += -fuse-ld=lld
|
||||
endif
|
||||
|
||||
|
||||
# Define our targets
|
||||
|
@ -377,9 +380,9 @@ _ios: $(BIN)/SameBoy-iOS.app $(OBJ)/installer
|
|||
ios-ipa: $(BIN)/SameBoy-iOS.ipa
|
||||
ios-deb: $(BIN)/SameBoy-iOS.deb
|
||||
ifeq ($(PLATFORM),windows32)
|
||||
lib: lib-unsupported
|
||||
lib: $(LIBDIR)/libsameboy.dll
|
||||
else
|
||||
lib: $(LIBDIR)/libsameboy.o $(LIBDIR)/libsameboy.a
|
||||
lib: $(LIBDIR)/libsameboy.o $(LIBDIR)/libsameboy.a $(LIBDIR)/libsameboy.$(DL_EXT)
|
||||
endif
|
||||
all: sdl tester libretro lib
|
||||
ifeq ($(PLATFORM),Darwin)
|
||||
|
@ -554,7 +557,7 @@ endif
|
|||
|
||||
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy: $(BIN)/SameBoy.app/Contents/MacOS/SameBoy.dylib
|
||||
$(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -rpath @executable_path/../../ -Wl,-reexport_library,$^
|
||||
|
||||
|
||||
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy.dylib: $(COCOA_OBJECTS) $(CORE_OBJECTS) $(QUICKLOOK_OBJECTS)
|
||||
-@$(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
|
||||
|
@ -614,7 +617,7 @@ ifeq ($(CONF), release)
|
|||
$(CODESIGN) $@
|
||||
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
|
||||
-@$(MKDIR) -p $(dir $@)
|
||||
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS) $(GL_LDFLAGS) -Wl,/subsystem:windows
|
||||
|
@ -798,14 +801,39 @@ $(LIBDIR)/libsameboy.a: $(LIBDIR)/libsameboy.o
|
|||
-@rm -f $@
|
||||
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
|
||||
-@$(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" > $@
|
||||
|
||||
lib-unsupported:
|
||||
@echo Due to limitations of lld-link, compiling SameBoy as a library on Windows is not supported.
|
||||
@false
|
||||
|
||||
# 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)
|
||||
* SDL frontend: libsdl2
|
||||
* [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:
|
||||
* Visual Studio (For headers, etc.)
|
||||
|
|
|
@ -1 +1 @@
|
|||
VERSION := 0.16.6
|
||||
VERSION := 1.0
|
Loading…
Reference in New Issue