-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
247 lines (212 loc) · 7.39 KB
/
Copy pathMakefile
File metadata and controls
247 lines (212 loc) · 7.39 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
SHELL := /usr/bin/env bash
PONGO_REPOSITORY := https://github.com/checkra1n/PongoOS.git
PONGO_COMMIT := 4c9b7541629234147fcc778f0ce4162482aaccef
PONGO_ROOT ?= $(CURDIR)/.deps/PongoOS
CCTOOLS_REPOSITORY := https://github.com/tpoechtrager/cctools-port.git
CCTOOLS_COMMIT := 904de2a71d4da6a9b30d2efaf912a10ddc7d9ddb
CCTOOLS_ROOT ?= $(CURDIR)/.deps/cctools-port
CCTOOLS_BUILD ?= $(CURDIR)/.deps/cctools-build
CCTOOLS_PREFIX ?= $(CURDIR)/.deps/cctools
DOOM_REPOSITORY := https://github.com/ozkl/doomgeneric.git
DOOM_COMMIT := dcb7a8dbc7a16ce3dda29382ac9aae9d77d21284
DOOM_VENDOR_ROOT ?= $(CURDIR)/vendor/doomgeneric
DOOM_ROOT := $(DOOM_VENDOR_ROOT)/doomgeneric
DOOM_PATCH := $(CURDIR)/patches/doomgeneric-pongo.patch
NEWLIB_ROOT := $(PONGO_ROOT)/newlib
NEWLIB_SYSROOT := $(NEWLIB_ROOT)/aarch64-none-darwin
BUILD_DIR := $(CURDIR)/build
OBJ_DIR := $(BUILD_DIR)/obj
MODULE := $(BUILD_DIR)/DFUoom
PONGO_IMAGE := $(BUILD_DIR)/Pongo.bin
PONGO_STAMP := $(PONGO_ROOT)/.dfuoom-$(PONGO_COMMIT)
CCTOOLS_STAMP := $(CCTOOLS_PREFIX)/.dfuoom-$(CCTOOLS_COMMIT)
DOOM_STAMP := $(DOOM_VENDOR_ROOT)/.dfuoom-$(DOOM_COMMIT)
CROSS_CC ?= clang
HOST_CC ?= cc
HOST_CXX ?= c++
LD64 ?= $(CCTOOLS_PREFIX)/bin/aarch64-apple-darwin-ld
CCTOOLS_STRIP ?= $(CCTOOLS_PREFIX)/bin/aarch64-apple-darwin-strip
LLVM_AR ?= llvm-ar
LLVM_RANLIB ?= llvm-ranlib
LLVM_NM ?= llvm-nm
JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || printf 1)
TARGET_FLAGS := --target=arm64-apple-ios12.0
INCLUDES := \
-I$(NEWLIB_SYSROOT)/include \
-I$(PONGO_ROOT)/apple-include \
-I$(PONGO_ROOT)/example/include \
-I$(DOOM_ROOT) \
-I$(CURDIR)/src
COMMON_CFLAGS := \
$(TARGET_FLAGS) \
-std=gnu11 \
-O2 \
-ffreestanding \
-fno-builtin \
-ffunction-sections \
-fdata-sections \
-fno-stack-protector \
-U__nonnull \
-nostdlibinc \
-DTARGET_OS_OSX=0 \
-DTARGET_OS_MACCATALYST=0 \
-DDFUOOM_PONGO=1 \
-DDOOMGENERIC_RESX=320 \
-DDOOMGENERIC_RESY=200 \
-include $(CURDIR)/src/dfuoom_ctype.h \
$(INCLUDES)
VENDOR_CFLAGS := \
-Wno-deprecated-non-prototype \
-Wno-implicit-function-declaration \
-Wno-incompatible-pointer-types \
-Wno-int-conversion \
-Wno-unused-function \
-Wno-unused-variable
MODULE_LDFLAGS := \
$(TARGET_FLAGS) \
-nostdlib \
-static \
-Wl,-dead_strip \
-Wl,-kext \
-fuse-ld=$(abspath $(LD64))
PONGO_COMPAT_CFLAGS := \
-fno-lto \
-Wno-unused-but-set-variable \
-Wno-deprecated-non-prototype \
-Dva_start=__builtin_va_start \
-Dva_end=__builtin_va_end
DOOM_SOURCES := \
dummy.c am_map.c doomdef.c doomstat.c dstrings.c d_event.c d_items.c \
d_iwad.c d_loop.c d_main.c d_mode.c d_net.c f_finale.c f_wipe.c \
g_game.c hu_lib.c hu_stuff.c info.c i_cdmus.c i_endoom.c i_joystick.c \
i_scale.c i_sound.c i_system.c i_timer.c memio.c m_argv.c m_bbox.c \
m_cheat.c m_config.c m_controls.c m_fixed.c m_menu.c m_misc.c m_random.c \
p_ceilng.c p_doors.c p_enemy.c p_floor.c p_inter.c p_lights.c p_map.c \
p_maputl.c p_mobj.c p_plats.c p_pspr.c p_saveg.c p_setup.c p_sight.c \
p_spec.c p_switch.c p_telept.c p_tick.c p_user.c r_bsp.c r_data.c \
r_draw.c r_main.c r_plane.c r_segs.c r_sky.c r_things.c sha1.c \
sounds.c statdump.c st_lib.c st_stuff.c s_sound.c tables.c v_video.c \
wi_stuff.c w_checksum.c w_main.c w_wad.c z_zone.c i_input.c i_video.c \
doomgeneric.c
PORT_SOURCES := \
src/dfuoom_frame.c \
src/dfuoom_input.c \
src/dfuoom_runtime.c \
src/w_file_memory.c \
src/dfuoom_pongo.c
DOOM_OBJECTS := $(patsubst %.c,$(OBJ_DIR)/doom/%.o,$(DOOM_SOURCES))
PORT_OBJECTS := $(patsubst src/%.c,$(OBJ_DIR)/port/%.o,$(PORT_SOURCES))
OBJECTS := $(DOOM_OBJECTS) $(PORT_OBJECTS)
.PHONY: all bootstrap pongo-source cctools doomgeneric-source newlib pongo module \
test lint verify clean distclean doctor
all: module pongo
bootstrap: pongo-source cctools doomgeneric-source
pongo-source: $(PONGO_STAMP)
$(PONGO_STAMP):
@mkdir -p $(dir $(PONGO_ROOT))
@if [[ ! -d "$(PONGO_ROOT)/.git" ]]; then \
git clone --filter=blob:none $(PONGO_REPOSITORY) $(PONGO_ROOT); \
fi
git -C $(PONGO_ROOT) fetch --depth 1 origin $(PONGO_COMMIT)
git -C $(PONGO_ROOT) checkout --detach $(PONGO_COMMIT)
git -C $(PONGO_ROOT) submodule update --init --depth 1 newlib
@touch $@
doomgeneric-source: $(DOOM_STAMP)
$(DOOM_STAMP): $(DOOM_PATCH)
@mkdir -p $(dir $(DOOM_VENDOR_ROOT))
@if [[ -e "$(DOOM_VENDOR_ROOT)" && ! -d "$(DOOM_VENDOR_ROOT)/.git" ]]; then \
echo "Refusing to replace non-git path: $(DOOM_VENDOR_ROOT)" >&2; \
exit 1; \
fi
@if [[ ! -d "$(DOOM_VENDOR_ROOT)/.git" ]]; then \
git clone --filter=blob:none $(DOOM_REPOSITORY) $(DOOM_VENDOR_ROOT); \
fi
git -C $(DOOM_VENDOR_ROOT) fetch --depth 1 origin $(DOOM_COMMIT)
git -C $(DOOM_VENDOR_ROOT) checkout --detach --force $(DOOM_COMMIT)
git -C $(DOOM_VENDOR_ROOT) apply $(DOOM_PATCH)
@touch $@
$(DOOM_ROOT)/%.c: $(DOOM_STAMP)
@test -f $@
cctools: $(LD64)
$(LD64): $(CCTOOLS_STAMP)
@test -x $@
$(CCTOOLS_STAMP):
@mkdir -p $(dir $(CCTOOLS_ROOT))
@if [[ ! -d "$(CCTOOLS_ROOT)/.git" ]]; then \
git clone --filter=blob:none $(CCTOOLS_REPOSITORY) $(CCTOOLS_ROOT); \
fi
git -C $(CCTOOLS_ROOT) fetch --depth 1 origin $(CCTOOLS_COMMIT)
git -C $(CCTOOLS_ROOT) checkout --detach $(CCTOOLS_COMMIT)
rm -rf $(CCTOOLS_BUILD) $(CCTOOLS_PREFIX)
mkdir -p $(CCTOOLS_BUILD)
cd $(CCTOOLS_BUILD) && \
$(CCTOOLS_ROOT)/cctools/configure \
--prefix=$(CCTOOLS_PREFIX) \
--target=aarch64-apple-darwin \
--disable-lto-support \
--disable-xar-support \
--disable-tapi-support \
CC=$(HOST_CC) \
CXX=$(HOST_CXX)
$(MAKE) -C $(CCTOOLS_BUILD) -j"$(JOBS)"
$(MAKE) -C $(CCTOOLS_BUILD) install
@touch $@
newlib: $(NEWLIB_SYSROOT)/lib/libc.a
$(NEWLIB_SYSROOT)/lib/libc.a: $(PONGO_STAMP) | cctools
$(MAKE) -C $(NEWLIB_ROOT) -j"$(JOBS)" \
EMBEDDED_CC=$(CROSS_CC) \
EMBEDDED_LDFLAGS="-fuse-ld=$(abspath $(LD64))" \
EMBEDDED_AR=$(LLVM_AR) \
EMBEDDED_RANLIB=$(LLVM_RANLIB)
pongo: $(PONGO_IMAGE)
$(PONGO_IMAGE): $(NEWLIB_SYSROOT)/lib/libc.a | cctools
$(MAKE) -C $(PONGO_ROOT) -j"$(JOBS)" build/Pongo.bin \
EMBEDDED_CC=$(CROSS_CC) \
EMBEDDED_LDFLAGS="-fuse-ld=$(abspath $(LD64))" \
EMBEDDED_CFLAGS="$(PONGO_COMPAT_CFLAGS)" \
STRIP=$(abspath $(CCTOOLS_STRIP)) \
CC=$(HOST_CC)
@mkdir -p $(dir $@)
cp $(PONGO_ROOT)/build/Pongo.bin $@
@echo "Built $@"
module: $(MODULE)
$(MODULE): $(OBJECTS) | cctools
@mkdir -p $(dir $@)
$(CROSS_CC) $(MODULE_LDFLAGS) -o $@ $(OBJECTS)
@echo "Built $@"
$(OBJ_DIR)/doom/%.o: $(DOOM_ROOT)/%.c src/dfuoom_ctype.h | newlib
@mkdir -p $(dir $@)
$(CROSS_CC) $(COMMON_CFLAGS) $(VENDOR_CFLAGS) -c $< -o $@
$(OBJ_DIR)/port/%.o: src/%.c src/dfuoom_ctype.h | newlib
@mkdir -p $(dir $@)
$(CROSS_CC) $(COMMON_CFLAGS) -Wall -Wextra -Werror \
-Wno-ignored-qualifiers -c $< -o $@
test:
@mkdir -p $(BUILD_DIR)
$(HOST_CC) -std=c11 -Wall -Wextra -Werror -pedantic \
-Isrc \
tests/test_core.c \
src/dfuoom_frame.c \
src/dfuoom_input.c \
src/dfuoom_runtime.c \
-o $(BUILD_DIR)/test_core
$(BUILD_DIR)/test_core
python3 -m unittest discover -s tests -p 'test_*.py'
lint:
python3 -m py_compile tools/*.py
@for script in scripts/*.sh; do bash -n "$$script"; done
verify: test lint module
file $(MODULE)
llvm-otool -hV $(MODULE)
@$(LLVM_NM) -u $(MODULE) | sort -u > $(BUILD_DIR)/undefined-symbols.txt
python3 tools/check_pongo_imports.py \
--module $(MODULE) \
--pongo-source $(PONGO_ROOT)/src/dynamic/modload.c \
--nm $(LLVM_NM)
@echo "Undefined PongoOS imports: $$(wc -l < $(BUILD_DIR)/undefined-symbols.txt)"
doctor:
python3 tools/dfuoomctl.py doctor
clean:
rm -rf $(BUILD_DIR)
distclean: clean
rm -rf $(CURDIR)/.deps $(DOOM_VENDOR_ROOT)