2016-03-30 20:07:55 +00:00
|
|
|
ifeq ($(shell uname -s),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-08-06 13:55:01 +00:00
|
|
|
VERSION := 0.6
|
2016-04-01 20:36:43 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
BIN := build/bin
|
|
|
|
OBJ := build/obj
|
|
|
|
|
|
|
|
CC := clang
|
|
|
|
|
2016-07-17 19:43:23 +00:00
|
|
|
CFLAGS += -Werror -Wall -std=gnu11 -ICore -D_GNU_SOURCE -DVERSION="$(VERSION)"
|
2016-03-30 20:07:55 +00:00
|
|
|
SDL_LDFLAGS := -lSDL
|
|
|
|
LDFLAGS += -lc -lm
|
2016-04-01 19:53:29 +00:00
|
|
|
CONF ?= debug
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
ifeq ($(shell uname -s),Darwin)
|
2016-07-17 19:43:23 +00:00
|
|
|
CFLAGS += -F/Library/Frameworks
|
2016-03-30 20:07:55 +00:00
|
|
|
OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(shell xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.9
|
2016-06-09 15:22:47 +00:00
|
|
|
LDFLAGS += -framework AppKit -framework Carbon
|
2016-03-30 20:07:55 +00:00
|
|
|
SDL_LDFLAGS := -framework SDL
|
|
|
|
endif
|
|
|
|
|
2016-04-01 19:53:29 +00:00
|
|
|
ifeq ($(CONF),debug)
|
|
|
|
CFLAGS += -g
|
|
|
|
else ifeq ($(CONF), release)
|
2016-08-06 13:18:23 +00:00
|
|
|
CFLAGS += -O3 -flto
|
|
|
|
LDFLAGS += -flto
|
2016-04-01 19:53:29 +00:00
|
|
|
else
|
|
|
|
$(error Invalid value for CONF: $(CONF). Use "debug" or "release")
|
|
|
|
endif
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
cocoa: $(BIN)/Sameboy.app
|
2016-04-01 20:29:03 +00:00
|
|
|
sdl: $(BIN)/sdl/sameboy $(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
|
|
|
|
|
|
|
|
CORE_SOURCES := $(shell echo Core/*.c)
|
|
|
|
SDL_SOURCES := $(shell echo SDL/*.c)
|
|
|
|
|
|
|
|
ifeq ($(shell uname -s),Darwin)
|
|
|
|
COCOA_SOURCES := $(shell echo Cocoa/*.m)
|
|
|
|
SDL_SOURCES += $(shell echo SDL/*.m)
|
|
|
|
endif
|
|
|
|
|
|
|
|
CORE_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(CORE_SOURCES))
|
|
|
|
COCOA_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(COCOA_SOURCES))
|
|
|
|
SDL_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(SDL_SOURCES))
|
|
|
|
|
|
|
|
ALL_OBJECTS := $(CORE_OBJECTS) $(COCOA_OBJECTS) $(SDL_OBJECTS)
|
|
|
|
|
|
|
|
# Automatic dependency generation
|
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
|
|
|
|
ifneq ($(filter $(MAKECMDGOALS),cocoa),)
|
|
|
|
-include $(COCOA_OBJECTS:.o=.dep)
|
|
|
|
endif
|
|
|
|
endif
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
$(OBJ)/%.dep: %
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
$(CC) $(CFLAGS) -MT $(OBJ)/$^.o -M $^ -c -o $@
|
|
|
|
|
|
|
|
$(OBJ)/%.c.o: %.c
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
$(OBJ)/%.m.o: %.m
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
$(CC) $(CFLAGS) $(OCFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
# Cocoa Port
|
|
|
|
|
2016-04-28 20:07:05 +00:00
|
|
|
Shaders:$(shell echo Shaders/*.fsh)
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
$(BIN)/Sameboy.app: $(BIN)/Sameboy.app/Contents/MacOS/Sameboy \
|
|
|
|
$(shell echo Cocoa/*.icns) \
|
2016-04-01 20:36:43 +00:00
|
|
|
Cocoa/License.html \
|
|
|
|
Cocoa/info.plist \
|
2016-03-30 20:07:55 +00:00
|
|
|
$(BIN)/BootROMs/dmg_boot.bin \
|
|
|
|
$(BIN)/BootROMs/cgb_boot.bin \
|
|
|
|
$(BIN)/Sameboy.app/Contents/Resources/Base.lproj/Document.nib \
|
2016-04-13 19:43:16 +00:00
|
|
|
$(BIN)/Sameboy.app/Contents/Resources/Base.lproj/MainMenu.nib \
|
2016-04-28 20:07:05 +00:00
|
|
|
$(BIN)/Sameboy.app/Contents/Resources/Base.lproj/Preferences.nib \
|
|
|
|
Shaders
|
2016-03-30 20:07:55 +00:00
|
|
|
mkdir -p $(BIN)/Sameboy.app/Contents/Resources
|
|
|
|
cp Cocoa/*.icns $(BIN)/BootROMs/dmg_boot.bin $(BIN)/BootROMs/cgb_boot.bin $(BIN)/Sameboy.app/Contents/Resources/
|
2016-04-01 20:36:43 +00:00
|
|
|
sed s/@VERSION/$(VERSION)/ < Cocoa/info.plist > $(BIN)/Sameboy.app/Contents/info.plist
|
2016-04-01 19:13:05 +00:00
|
|
|
cp Cocoa/License.html $(BIN)/Sameboy.app/Contents/Resources/Credits.html
|
2016-04-28 20:07:05 +00:00
|
|
|
mkdir -p $(BIN)/Sameboy.app/Contents/Resources/Shaders
|
|
|
|
cp Shaders/*.fsh $(BIN)/Sameboy.app/Contents/Resources/Shaders
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
$(BIN)/Sameboy.app/Contents/MacOS/Sameboy: $(CORE_OBJECTS) $(COCOA_OBJECTS)
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) -framework OpenGL -framework AudioUnit
|
2016-08-06 13:19:04 +00:00
|
|
|
ifeq ($(CONF), release)
|
|
|
|
strip $@
|
|
|
|
endif
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
$(BIN)/Sameboy.app/Contents/Resources/Base.lproj/%.nib: Cocoa/%.xib
|
|
|
|
ibtool --compile $@ $^
|
|
|
|
|
|
|
|
$(BIN)/sdl/sameboy: $(CORE_OBJECTS) $(SDL_OBJECTS)
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
$(CC) $^ -o $@ $(LDFLAGS) $(SDL_LDFLAGS)
|
2016-08-06 13:19:04 +00:00
|
|
|
ifeq ($(CONF), release)
|
|
|
|
strip $@
|
|
|
|
endif
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
$(BIN)/BootROMs/%.bin: BootROMs/%.asm
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
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
|
|
|
|
|
|
|
|
$(BIN)/sdl/%.bin: $(BIN)/BootROMs/%.bin
|
|
|
|
-@mkdir -p $(dir $@)
|
|
|
|
cp -f $^ $@
|
|
|
|
|
2016-04-01 20:29:03 +00:00
|
|
|
$(BIN)/sdl/LICENSE: LICENSE
|
|
|
|
cp -f $^ $@
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
clean:
|
|
|
|
rm -rf build
|
|
|
|
|