2016-08-26 22:30:11 +00:00
|
|
|
# Make hacks
|
|
|
|
.INTERMEDIATE:
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# Set target, configuration, version and destination folders
|
|
|
|
|
|
|
|
PLATFORM := $(shell uname -s)
|
|
|
|
|
|
|
|
ifeq ($(PLATFORM),Darwin)
|
2016-08-06 12:57:32 +00:00
|
|
|
DEFAULT := cocoa
|
2016-03-30 20:07:55 +00:00
|
|
|
else
|
2016-08-06 12:57:32 +00:00
|
|
|
DEFAULT := sdl
|
2016-03-30 20:07:55 +00:00
|
|
|
endif
|
|
|
|
|
2016-08-06 12:57:32 +00:00
|
|
|
default: $(DEFAULT)
|
|
|
|
|
|
|
|
ifeq ($(MAKECMDGOALS),)
|
|
|
|
MAKECMDGOALS := $(DEFAULT)
|
|
|
|
endif
|
|
|
|
|
2016-09-10 17:59:02 +00:00
|
|
|
VERSION := 0.7
|
2016-08-20 14:51:17 +00:00
|
|
|
CONF ?= debug
|
2016-04-01 20:36:43 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
BIN := build/bin
|
|
|
|
OBJ := build/obj
|
2016-08-26 22:30:11 +00:00
|
|
|
BOOTROMS_DIR ?= $(BIN)/BootROMs
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# Set tools
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
CC := clang
|
2016-08-20 14:51:17 +00:00
|
|
|
ifeq ($(PLATFORM),windows32)
|
|
|
|
# To force use of the Unix version instead of the Windows version
|
|
|
|
MKDIR := $(shell which mkdir)
|
|
|
|
else
|
|
|
|
MKDIR := mkdir
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Set compilation and linkage flags based on target, platform and configuration
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
CFLAGS += -Werror -Wall -std=gnu11 -ICore -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES
|
2016-03-30 20:07:55 +00:00
|
|
|
SDL_LDFLAGS := -lSDL
|
2016-08-20 14:51:17 +00:00
|
|
|
ifeq ($(PLATFORM),windows32)
|
|
|
|
CFLAGS += -IWindows
|
2016-08-20 19:59:03 +00:00
|
|
|
LDFLAGS += -lmsvcrt -lSDLmain -Wl,/MANIFESTFILE:NUL
|
2016-08-20 14:51:17 +00:00
|
|
|
else
|
2016-03-30 20:07:55 +00:00
|
|
|
LDFLAGS += -lc -lm
|
2016-08-20 14:51:17 +00:00
|
|
|
endif
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
ifeq ($(PLATFORM),Darwin)
|
2017-01-22 19:53:52 +00:00
|
|
|
SYSROOT := $(shell xcodebuild -sdk macosx -version Path 2> /dev/null)
|
2016-07-17 19:43:23 +00:00
|
|
|
CFLAGS += -F/Library/Frameworks
|
2017-01-22 19:53:52 +00:00
|
|
|
OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT) -mmacosx-version-min=10.9
|
2016-10-26 21:14:02 +00:00
|
|
|
LDFLAGS += -framework AppKit -framework Carbon -framework QuartzCore
|
2016-03-30 20:07:55 +00:00
|
|
|
SDL_LDFLAGS := -framework SDL
|
|
|
|
endif
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
ifeq ($(PLATFORM),windows32)
|
|
|
|
CFLAGS += -Wno-deprecated-declarations # Seems like Microsoft deprecated every single LIBC function
|
|
|
|
LDFLAGS += -Wl,/NODEFAULTLIB:libcmt
|
|
|
|
endif
|
|
|
|
|
2016-04-01 19:53:29 +00:00
|
|
|
ifeq ($(CONF),debug)
|
|
|
|
CFLAGS += -g
|
2016-08-20 14:51:17 +00:00
|
|
|
ifeq ($(PLATFORM),windows32)
|
|
|
|
LDFLAGS += -Wl,/debug
|
|
|
|
endif
|
2016-04-01 19:53:29 +00:00
|
|
|
else ifeq ($(CONF), release)
|
2016-08-20 14:51:17 +00:00
|
|
|
CFLAGS += -O3 -DNDEBUG
|
|
|
|
ifneq ($(PLATFORM),windows32)
|
2016-08-06 13:18:23 +00:00
|
|
|
LDFLAGS += -flto
|
2016-08-20 14:51:17 +00:00
|
|
|
CFLAGS += -flto
|
|
|
|
endif
|
2016-04-01 19:53:29 +00:00
|
|
|
else
|
|
|
|
$(error Invalid value for CONF: $(CONF). Use "debug" or "release")
|
|
|
|
endif
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# Define our targets
|
|
|
|
|
|
|
|
ifeq ($(PLATFORM),windows32)
|
|
|
|
SDL_TARGET := $(BIN)/sdl/sameboy.exe $(BIN)/sdl/sameboy_debugger.exe $(BIN)/sdl/SDL.dll
|
2016-09-03 00:39:32 +00:00
|
|
|
TESTER_TARGET := $(BIN)/tester/sameboy_tester.exe
|
2016-08-20 14:51:17 +00:00
|
|
|
else
|
|
|
|
SDL_TARGET := $(BIN)/sdl/sameboy
|
2016-09-03 00:39:32 +00:00
|
|
|
TESTER_TARGET := $(BIN)/tester/sameboy_tester
|
2016-08-20 14:51:17 +00:00
|
|
|
endif
|
|
|
|
|
2017-01-20 16:35:20 +00:00
|
|
|
cocoa: $(BIN)/SameBoy.app
|
|
|
|
quicklook: $(BIN)/SameBoy.qlgenerator
|
2016-08-20 14:51:17 +00:00
|
|
|
sdl: $(SDL_TARGET) $(BIN)/sdl/dmg_boot.bin $(BIN)/sdl/cgb_boot.bin $(BIN)/sdl/LICENSE
|
2016-03-30 20:07:55 +00:00
|
|
|
bootroms: $(BIN)/BootROMs/cgb_boot.bin $(BIN)/BootROMs/dmg_boot.bin
|
2016-09-03 00:39:32 +00:00
|
|
|
tester: $(TESTER_TARGET) $(BIN)/tester/dmg_boot.bin $(BIN)/tester/cgb_boot.bin
|
2017-01-20 16:35:20 +00:00
|
|
|
all: cocoa sdl tester
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# Get a list of our source files and their respective object file targets
|
|
|
|
|
|
|
|
CORE_SOURCES := $(shell ls Core/*.c)
|
|
|
|
SDL_SOURCES := $(shell ls SDL/*.c)
|
2016-09-03 00:39:32 +00:00
|
|
|
TESTER_SOURCES := $(shell ls Tester/*.c)
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
ifeq ($(PLATFORM),Darwin)
|
|
|
|
COCOA_SOURCES := $(shell ls Cocoa/*.m) $(shell ls HexFiend/*.m)
|
2017-01-20 16:35:20 +00:00
|
|
|
QUICKLOOK_SOURCES := $(shell ls QuickLook/*.m) $(shell ls QuickLook/*.c)
|
2016-08-20 14:51:17 +00:00
|
|
|
SDL_SOURCES += $(shell ls SDL/*.m)
|
2016-03-30 20:07:55 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
CORE_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(CORE_SOURCES))
|
|
|
|
COCOA_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(COCOA_SOURCES))
|
2017-01-20 16:35:20 +00:00
|
|
|
QUICKLOOK_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(QUICKLOOK_SOURCES))
|
2016-03-30 20:07:55 +00:00
|
|
|
SDL_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(SDL_SOURCES))
|
2016-09-03 00:39:32 +00:00
|
|
|
TESTER_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(TESTER_SOURCES))
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
# Automatic dependency generation
|
2016-08-20 14:51:17 +00:00
|
|
|
|
2016-08-06 12:57:32 +00:00
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
-include $(CORE_OBJECTS:.o=.dep)
|
|
|
|
ifneq ($(filter $(MAKECMDGOALS),sdl),)
|
|
|
|
-include $(SDL_OBJECTS:.o=.dep)
|
|
|
|
endif
|
2016-09-03 00:39:32 +00:00
|
|
|
ifneq ($(filter $(MAKECMDGOALS),tester),)
|
|
|
|
-include $(TESTER_OBJECTS:.o=.dep)
|
|
|
|
endif
|
2016-08-06 12:57:32 +00:00
|
|
|
ifneq ($(filter $(MAKECMDGOALS),cocoa),)
|
|
|
|
-include $(COCOA_OBJECTS:.o=.dep)
|
|
|
|
endif
|
|
|
|
endif
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
$(OBJ)/%.dep: %
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-03-30 20:07:55 +00:00
|
|
|
$(CC) $(CFLAGS) -MT $(OBJ)/$^.o -M $^ -c -o $@
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# Compilation rules
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
$(OBJ)/%.c.o: %.c
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-03-30 20:07:55 +00:00
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
2016-08-12 19:49:17 +00:00
|
|
|
# HexFiend requires more flags
|
|
|
|
$(OBJ)/HexFiend/%.m.o: HexFiend/%.m
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-08-12 19:49:17 +00:00
|
|
|
$(CC) $(CFLAGS) $(OCFLAGS) -c $< -o $@ -fno-objc-arc -include HexFiend/HexFiend_2_Framework_Prefix.pch
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
$(OBJ)/%.m.o: %.m
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-03-30 20:07:55 +00:00
|
|
|
$(CC) $(CFLAGS) $(OCFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
# Cocoa Port
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
Shaders:$(shell ls Shaders/*.fsh)
|
2016-04-28 20:07:05 +00:00
|
|
|
|
2017-01-20 16:35:20 +00:00
|
|
|
$(BIN)/SameBoy.app: $(BIN)/SameBoy.app/Contents/MacOS/SameBoy \
|
|
|
|
$(shell ls Cocoa/*.icns) \
|
|
|
|
Cocoa/License.html \
|
|
|
|
Cocoa/Info.plist \
|
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/dmg_boot.bin \
|
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/cgb_boot.bin \
|
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/Base.lproj/Document.nib \
|
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/Base.lproj/MainMenu.nib \
|
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/Base.lproj/Preferences.nib \
|
|
|
|
$(BIN)/SameBoy.qlgenerator \
|
|
|
|
Shaders
|
|
|
|
$(MKDIR) -p $(BIN)/SameBoy.app/Contents/Resources
|
|
|
|
cp Cocoa/*.icns $(BIN)/SameBoy.app/Contents/Resources/
|
|
|
|
sed s/@VERSION/$(VERSION)/ < Cocoa/Info.plist > $(BIN)/SameBoy.app/Contents/Info.plist
|
|
|
|
cp Cocoa/License.html $(BIN)/SameBoy.app/Contents/Resources/Credits.html
|
|
|
|
$(MKDIR) -p $(BIN)/SameBoy.app/Contents/Resources/Shaders
|
|
|
|
cp Shaders/*.fsh $(BIN)/SameBoy.app/Contents/Resources/Shaders
|
|
|
|
$(MKDIR) -p $(BIN)/SameBoy.app/Contents/Library/QuickLook/
|
|
|
|
cp -rf $(BIN)/SameBoy.qlgenerator $(BIN)/SameBoy.app/Contents/Library/QuickLook/
|
|
|
|
|
|
|
|
$(BIN)/SameBoy.app/Contents/MacOS/SameBoy: $(CORE_OBJECTS) $(COCOA_OBJECTS)
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-10-02 21:26:12 +00:00
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) -framework OpenGL -framework AudioUnit -framework AVFoundation -framework CoreVideo -framework CoreMedia
|
2016-08-06 13:19:04 +00:00
|
|
|
ifeq ($(CONF), release)
|
|
|
|
strip $@
|
|
|
|
endif
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2017-01-20 16:35:20 +00:00
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/Base.lproj/%.nib: Cocoa/%.xib
|
2016-03-30 20:07:55 +00:00
|
|
|
ibtool --compile $@ $^
|
|
|
|
|
2017-01-20 16:35:20 +00:00
|
|
|
# Quick Look generator
|
|
|
|
|
|
|
|
$(BIN)/SameBoy.qlgenerator: $(BIN)/SameBoy.qlgenerator/Contents/MacOS/SameBoyQL \
|
|
|
|
$(shell ls QuickLook/*.png) \
|
|
|
|
QuickLook/Info.plist \
|
|
|
|
$(BIN)/SameBoy.qlgenerator/Contents/Resources/cgb_boot_fast.bin
|
|
|
|
$(MKDIR) -p $(BIN)/SameBoy.qlgenerator/Contents/Resources
|
|
|
|
cp QuickLook/*.png $(BIN)/SameBoy.qlgenerator/Contents/Resources/
|
|
|
|
sed s/@VERSION/$(VERSION)/ < QuickLook/Info.plist > $(BIN)/SameBoy.qlgenerator/Contents/Info.plist
|
|
|
|
|
|
|
|
# Currently, SameBoy.app includes two "copies" of each Core .o file once in the app itself and
|
|
|
|
# once in the QL Generator. It should probably become a dylib instead.
|
|
|
|
$(BIN)/SameBoy.qlgenerator/Contents/MacOS/SameBoyQL: $(CORE_OBJECTS) $(QUICKLOOK_OBJECTS)
|
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) -bundle -framework Cocoa -framework Quicklook
|
|
|
|
ifeq ($(CONF), release)
|
|
|
|
strip -u -r -s QuickLook/exports.sym $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
# cgb_boot_fast.bin is not a standard boot ROM, we don't expect it to exist in the user-provided
|
|
|
|
# boot ROM directory.
|
|
|
|
$(BIN)/SameBoy.qlgenerator/Contents/Resources/cgb_boot_fast.bin: $(BIN)/BootROMs/cgb_boot_fast.bin
|
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
cp -f $^ $@
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# SDL Port
|
|
|
|
|
|
|
|
# Unix versions build only one binary
|
2016-03-30 20:07:55 +00:00
|
|
|
$(BIN)/sdl/sameboy: $(CORE_OBJECTS) $(SDL_OBJECTS)
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-03-30 20:07:55 +00:00
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS)
|
2016-08-06 13:19:04 +00:00
|
|
|
ifeq ($(CONF), release)
|
|
|
|
strip $@
|
|
|
|
endif
|
2016-08-20 14:51:17 +00:00
|
|
|
|
|
|
|
# Windows version builds two, one with a conole and one without it
|
2016-08-20 19:59:03 +00:00
|
|
|
$(BIN)/sdl/sameboy.exe: $(CORE_OBJECTS) $(SDL_OBJECTS) $(OBJ)/Windows/resources.o
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS) -Wl,/subsystem:windows
|
|
|
|
|
2016-08-20 19:59:03 +00:00
|
|
|
$(BIN)/sdl/sameboy_debugger.exe: $(CORE_OBJECTS) $(SDL_OBJECTS) $(OBJ)/Windows/resources.o
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS) -Wl,/subsystem:console
|
|
|
|
|
2016-08-20 19:59:03 +00:00
|
|
|
$(OBJ)/%.res: %.rc
|
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
rc /fo $@ /dVERSION=\"$(VERSION)\" $^
|
|
|
|
|
|
|
|
%.o: %.res
|
|
|
|
cvtres /OUT:"$@" $^
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# We must provide SDL.dll with the Windows port. This is an AWFUL HACK to find it.
|
|
|
|
SPACE :=
|
|
|
|
SPACE +=
|
|
|
|
$(BIN)/sdl/SDL.dll:
|
|
|
|
@$(eval POTENTIAL_MATCHES := $(subst @@@," ",$(patsubst %,%/SDL.dll,$(subst ;,$(SPACE),$(subst $(SPACE),@@@,$(lib))))))
|
|
|
|
@$(eval MATCH := $(shell ls $(POTENTIAL_MATCHES) 2> NUL | head -n 1))
|
|
|
|
cp "$(MATCH)" $@
|
|
|
|
|
2016-09-03 00:39:32 +00:00
|
|
|
# Tester
|
|
|
|
|
|
|
|
$(BIN)/tester/sameboy_tester: $(CORE_OBJECTS) $(TESTER_OBJECTS)
|
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS)
|
|
|
|
ifeq ($(CONF), release)
|
|
|
|
strip $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(BIN)/tester/sameboy_tester.exe: $(CORE_OBJECTS) $(SDL_OBJECTS)
|
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) -Wl,/subsystem:console
|
|
|
|
|
|
|
|
$(BIN)/sdl/%.bin $(BIN)/tester/%.bin: $(BOOTROMS_DIR)/%.bin
|
2016-08-26 22:30:11 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
cp -f $^ $@
|
|
|
|
|
2017-01-20 16:35:20 +00:00
|
|
|
$(BIN)/SameBoy.app/Contents/Resources/%.bin: $(BOOTROMS_DIR)/%.bin
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
|
|
|
cp -f $^ $@
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
$(BIN)/sdl/LICENSE: LICENSE
|
|
|
|
cp -f $^ $@
|
|
|
|
|
|
|
|
# Boot ROMs
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
$(BIN)/BootROMs/%.bin: BootROMs/%.asm
|
2016-08-20 14:51:17 +00:00
|
|
|
-@$(MKDIR) -p $(dir $@)
|
2016-03-30 20:07:55 +00:00
|
|
|
cd BootROMs && rgbasm -o ../$@.tmp ../$<
|
|
|
|
rgblink -o $@.tmp2 $@.tmp
|
2016-08-06 21:39:32 +00:00
|
|
|
head -c $(if $(findstring dmg,$@), 256, 2304) $@.tmp2 > $@
|
2016-03-30 20:07:55 +00:00
|
|
|
@rm $@.tmp $@.tmp2
|
|
|
|
|
2016-08-20 14:51:17 +00:00
|
|
|
# Clean
|
2016-04-01 20:29:03 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
clean:
|
2016-08-20 14:51:17 +00:00
|
|
|
rm -rf build
|