-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
176 lines (139 loc) · 6.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
SDIR=src
ODIR=out
IDIR=$(SDIR)
CFLAGS=-std=gnu11 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-cast-function-type -O3 -I$(IDIR) -DVERSION=$(shell git rev-parse --short HEAD)
LDLIBS=
CC=gcc
BIN=gbmulator
# recursive wildcard that goes into all subdirectories
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# exclude $(SDIR)/platform/{desktop,android}/* if 'make web' or 'make debug_web' is called, else exclude $(SDIR)/platform/{web,android}/*, etc.
ifneq (,$(findstring web,$(MAKECMDGOALS)))
EXCLUDES:=$(call rwildcard,$(SDIR)/platform/desktop,*) $(wildcard $(SDIR)/platform/desktop_sdl/*) $(call rwildcard,$(SDIR)/platform/android,*)
PLATFORM_ODIR=$(ODIR)/web
else ifneq (,$(findstring desktop_sdl,$(MAKECMDGOALS)))
EXCLUDES:=$(wildcard $(SDIR)/platform/desktop/*) $(wildcard $(SDIR)/platform/web/*) $(call rwildcard,$(SDIR)/platform/android,*)
PLATFORM_ODIR=$(ODIR)/desktop_sdl
else
EXCLUDES:=$(wildcard $(SDIR)/platform/web/*) $(call rwildcard,$(SDIR)/platform/android,*) $(call rwildcard,$(SDIR)/platform/desktop_sdl,*)
PLATFORM_ODIR=$(ODIR)/desktop
OBJ=$(PLATFORM_ODIR)/platform/desktop/resources.o
endif
EXCLUDES+=$(wildcard $(SDIR)/bootroms/*)
SRC=$(filter-out $(EXCLUDES),$(call rwildcard,$(SDIR),*.c))
OBJ+=$(SRC:$(SDIR)/%.c=$(PLATFORM_ODIR)/%.o)
HEADERS=$(filter-out $(EXCLUDES),$(call rwildcard,$(IDIR),*.h))
HEADERS:=$(HEADERS:$(IDIR)/%=$(PLATFORM_ODIR)/%)
# PLATFORM_ODIR and its subdirectories' structure to mkdir if they don't exist
PLATFORM_ODIR_STRUCTURE:=$(sort $(foreach d,$(OBJ) $(HEADERS),$(subst /$(lastword $(subst /, ,$d)),,$d)))
ICONDIR=images/icons
ICONS= \
$(ICONDIR)/192x192/$(BIN).png \
$(ICONDIR)/144x144/$(BIN).png \
$(ICONDIR)/128x128/$(BIN).png \
$(ICONDIR)/96x96/$(BIN).png \
$(ICONDIR)/72x72/$(BIN).png \
$(ICONDIR)/64x64/$(BIN).png \
$(ICONDIR)/48x48/$(BIN).png \
$(ICONDIR)/32x32/$(BIN).png \
$(ICONDIR)/16x16/$(BIN).png
UI:=$(wildcard $(SDIR)/platform/desktop/ui/*.ui)
SHADERS:=$(wildcard $(SDIR)/platform/desktop/ui/*.glsl)
all: desktop
debug: CFLAGS+=-g -O0
debug: all
desktop: CFLAGS+=$(shell pkg-config --cflags gtk4 libadwaita-1 zlib manette-0.2 opengl glew openal gstreamer-1.0)
desktop: LDLIBS+=$(shell pkg-config --libs gtk4 libadwaita-1 zlib manette-0.2 opengl glew openal gstreamer-1.0)
desktop: $(PLATFORM_ODIR_STRUCTURE) $(BIN) $(ICONS)
$(SDIR)/platform/desktop/resources.c: $(SDIR)/platform/desktop/ui/gbmulator.gresource.xml $(UI) $(SHADERS)
glib-compile-resources $< --target=$@ --generate-source
desktop_sdl: CFLAGS+=$(shell pkg-config --cflags zlib sdl2)
desktop_sdl: LDLIBS+=$(shell pkg-config --libs zlib sdl2)
desktop_sdl: $(PLATFORM_ODIR_STRUCTURE) $(BIN) $(ICONS)
profile: CFLAGS+=-pg
profile: run
gprof ./$(BIN) gmon.out > prof_output
# TODO this should also make a gbmulator.apk file in this project root dir (next do the gbmulator desktop binary)
android: $(SDIR)/core/boot.c
cd $(SDIR)/platform/android/android-project && ./gradlew build
debug_android: android
cd $(SDIR)/platform/android/android-project && ./gradlew installDebug
adb shell am start -n io.github.mpostaire.gbmulator/.MainMenu
web_build:
mkdir -p web_build
web_build/favicon.png: $(SDIR)/platform/web/favicon.png
cp $^ $@
web_build/style.css: $(SDIR)/platform/web/style.css
cp $^ $@
web: CC:=emcc
web: LDLIBS:=
web: CFLAGS+=-sUSE_SDL=2 -sUSE_ZLIB=1
web: $(PLATFORM_ODIR_STRUCTURE) web_build web_build/favicon.png web_build/style.css web_build/index.html
debug_web: web
emrun web_build/index.html
web_build/index.html: $(SDIR)/platform/web/template.html $(OBJ)
$(CC) -o $@ $(OBJ) $(CFLAGS) -sABORTING_MALLOC=0 -sINITIAL_MEMORY=96MB -sWASM=1 -sEXPORTED_RUNTIME_METHODS=[ccall] -sASYNCIFY --shell-file $<
test:
$(MAKE) -C test
$(BIN): $(OBJ)
$(CC) -o $(BIN) $^ $(CFLAGS) $(LDLIBS)
$(PLATFORM_ODIR)/%.o: $(SDIR)/%.c
$(CC) -o $@ -c $< $(CFLAGS) -MMD $(LDLIBS)
$(PLATFORM_ODIR_STRUCTURE):
mkdir -p $@
# Build boot roms (taken and modified from SameBoy emulator)
$(SDIR)/core/boot.c: $(ODIR)/bootroms/dmg_boot $(ODIR)/bootroms/cgb_boot
cd $(ODIR)/bootroms && xxd -i dmg_boot > ../../$(SDIR)/core/boot.c && xxd -i cgb_boot >> ../../$(SDIR)/core/boot.c
$(ODIR)/bootroms/gbmulator_logo.1bpp: $(SDIR)/bootroms/gbmulator_logo.png
-@mkdir -p $(dir $@)
rgbgfx -d 1 -Z -o $@ $<
$(ODIR)/bootroms/gbmulator_logo.pb8: $(ODIR)/bootroms/gbmulator_logo.1bpp $(ODIR)/bootroms/pb8
$(ODIR)/bootroms/pb8 -l 384 $< $@
# force gcc here to avoid compiling with emcc
$(ODIR)/bootroms/pb8: $(SDIR)/bootroms/pb8.c
gcc $< -o $@
$(ODIR)/bootroms/%: $(SDIR)/bootroms/%.asm $(ODIR)/bootroms/gbmulator_logo.pb8 $(SDIR)/bootroms/hardware.inc
-@mkdir -p $(dir $@)
rgbasm -I $(ODIR)/bootroms/ -I $(SDIR)/bootroms/ -o [email protected] $<
rgblink -o [email protected] [email protected]
dd [email protected] of=$@ count=1 bs=$(if $(findstring dmg,$@),256,2304)
#
$(ICONS): $(ICONDIR)/$(BIN).svg
mkdir -p $(ICONDIR)/$(patsubst $(ICONDIR)/%/$(BIN).png,%,$@)
convert -background none -density 1200 -resize $(patsubst $(ICONDIR)/%/$(BIN).png,%,$@) $^ $(ICONDIR)/$(patsubst $(ICONDIR)/%/$(BIN).png,%,$@)/$(BIN).png
check: $(SDIR)
cppcheck --enable=all --suppress=missingIncludeSystem -i $(SDIR)/platform/android/android-project -i $(SDIR)/platform/desktop/resources.c $(SDIR)
clean:
rm -rf $(ODIR) web_build
$(MAKE) -C test clean
cleaner: clean
rm -rf $(BIN) $(SDIR)/platform/desktop/resources.c $(patsubst %/$(BIN).png,%,$(ICONS))
$(MAKE) -C test cleaner
cd $(SDIR)/platform/android/android-project && ./gradlew clean || true
install:
install -m 0755 $(BIN) /usr/bin
install -m 0644 $(SDIR)/platform/desktop/$(BIN).xml /usr/share/mime/application
install -m 0644 $(SDIR)/platform/desktop/$(BIN).desktop /usr/share/applications
install -m 0644 $(ICONDIR)/$(BIN).svg /usr/share/icons/hicolor/scalable/apps
install -m 0644 $(ICONDIR)/192x192/$(BIN).png /usr/share/icons/hicolor/192x192/apps
install -m 0644 $(ICONDIR)/128x128/$(BIN).png /usr/share/icons/hicolor/128x128/apps
install -m 0644 $(ICONDIR)/96x96/$(BIN).png /usr/share/icons/hicolor/96x96/apps
install -m 0644 $(ICONDIR)/72x72/$(BIN).png /usr/share/icons/hicolor/72x72/apps
install -m 0644 $(ICONDIR)/64x64/$(BIN).png /usr/share/icons/hicolor/64x64/apps
install -m 0644 $(ICONDIR)/48x48/$(BIN).png /usr/share/icons/hicolor/48x48/apps
install -m 0644 $(ICONDIR)/32x32/$(BIN).png /usr/share/icons/hicolor/32x32/apps
install -m 0644 $(ICONDIR)/16x16/$(BIN).png /usr/share/icons/hicolor/16x16/apps
install -m 0644 $(ICONDIR)/128x128/$(BIN).png /usr/share/icons
gtk-update-icon-cache
update-desktop-database
uninstall:
rm -f /usr/bin/$(BIN)
rm -f /usr/share/applications/$(BIN).desktop
rm -f /usr/share/icons/hicolor/scalable/apps/$(BIN).svg
rm -f /usr/share/icons/hicolor/{192x192,128x128,96x96,72x72,64x64,48x48,32x32,16x16}/apps/$(BIN).png
rm -f /usr/share/mime/application/$(BIN).xml
gtk-update-icon-cache
update-desktop-database
-include $(foreach d,$(PLATFORM_ODIR_STRUCTURE),$d/*.d)
.PHONY: all clean run install uninstall debug web debug_web android debug_android test