-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
205 lines (186 loc) · 5.21 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
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
ifneq (${USE_CLANG},)
ifneq (${ARCH},)
BUILDDIR = build/${ARCH}-${PLATFORM}-clang
CC = ${ARCH}clang
else
BUILDDIR = build/${PLATFORM}-clang
CC = clang
endif
else
ifneq (${ARCH},)
BUILDDIR = build/${ARCH}-${PLATFORM}
CC = ${ARCH}gcc
else
BUILDDIR = build/${PLATFORM}
CC = gcc
endif
endif
VERSION ?= 1.0.9a
RESDIR = res
SRCDIR = src
TOOLSDIR = tools
FONTSDIR = fonts
OBJDIR = ${BUILDDIR}/obj
CFLAGS = -g -O3 -flto -std=gnu18 -Wall -DVERSION=\"${VERSION}\"
LDFLAGS = -g -O3 -flto -std=gnu18 -Wall
ifeq (${PLATFORM},mingw32-sdl3)
USE_SDL3 = 1
WINDRES = windres
ifneq (${ARCH},)
WINDRES = ${ARCH}-w64-mingw32-windres
ifneq (${USE_CLANG},)
CC = ${ARCH}-w64-mingw32-clang
else
CC = ${ARCH}-w64-mingw32-gcc
endif
endif
CFLAGS += -mwindows
LDFLAGS += -mwindows
LIBS = -Wl,-Bstatic -lmingw32 -lwinpthread -lm -lgcc -lpng -lz -lssp -Wl,-Bdynamic -lSDL3 -lopengl32
TARGET = $(BUILDDIR)/zeta86.exe
else ifeq (${PLATFORM},mingw32-sdl2)
USE_SDL2 = 1
WINDRES = windres
ifneq (${ARCH},)
WINDRES = ${ARCH}-w64-mingw32-windres
ifneq (${USE_CLANG},)
CC = ${ARCH}-w64-mingw32-clang
else
CC = ${ARCH}-w64-mingw32-gcc
endif
endif
CFLAGS += -mwindows
LDFLAGS += -mwindows
LIBS = -Wl,-Bstatic -lmingw32 -lwinpthread -lm -lgcc -lSDL2main -lpng -lz -lssp -Wl,-Bdynamic -lSDL2 -lopengl32
TARGET = $(BUILDDIR)/zeta86.exe
else ifeq (${PLATFORM},macos-sdl3)
USE_SDL3 = 1
CC = clang
LIBS = -framework OpenGL -lSDL3 -lpng -lm
else ifeq (${PLATFORM},macos-sdl2)
USE_SDL2 = 1
CC = clang
LIBS = -framework OpenGL -lSDL2main -lSDL2 -lpng -lm
TARGET = $(BUILDDIR)/zeta86
ifeq (${ARCH},x86_64)
CFLAGS += -target x86_64-apple-macos10.12
LDFLAGS += -target x86_64-apple-macos10.12
else ifeq (${ARCH},aarch64)
CFLAGS += -target arm64-apple-macos11
LDFLAGS += -target arm64-apple-macos11
endif
else ifeq (${PLATFORM},unix-sdl2)
USE_SDL2 = 1
LIBS = -lGL -lSDL2 -lSDL2main -lpng -lm
TARGET = $(BUILDDIR)/zeta86
else ifeq (${PLATFORM},unix-sdl3)
USE_SDL3 = 1
LIBS = -lGL -lSDL3 -lpng -lm
TARGET = $(BUILDDIR)/zeta86
else ifeq (${PLATFORM},unix-curses)
USE_CURSES = 1
LIBS = -lncursesw -lm
TARGET = $(BUILDDIR)/zeta86
else ifeq (${PLATFORM},unix-headless)
USE_HEADLESS = 1
LIBS = -lm
TARGET = $(BUILDDIR)/zeta86
else ifeq (${PLATFORM},wasm)
CC = EMCC_CLOSURE_ARGS="--js $(realpath ${SRCDIR})/emscripten_externs.js" emcc
CFLAGS = -O3 -s STRICT=1 \
-DNO_MEMSET -DAVOID_MALLOC --no-entry -DVERSION=\"${VERSION}\"
LDFLAGS = ${CFLAGS} \
--closure 1 \
-s ENVIRONMENT=web \
-s 'EXPORTED_FUNCTIONS=["_malloc","_free","_audio_generate_init"]' \
-s 'EXPORTED_RUNTIME_METHODS=["AsciiToString", "HEAPU8", "HEAPU32"]' \
-s MODULARIZE=1 -s 'EXPORT_NAME="ZetaNative"' \
-s ALLOW_MEMORY_GROWTH=1 \
-s 'MALLOC="emmalloc"' -s FILESYSTEM=0 \
-s INITIAL_MEMORY=4194304 -s STACK_SIZE=262144 \
-L $(realpath ${SRCDIR}) -lemscripten_glue.js
TARGET = $(BUILDDIR)/zeta_native.js
ifeq (${DEBUG},)
LDFLAGS += -s ASSERTIONS=0
else
LDFLAGS += -s ASSERTIONS=1
endif
else
$(error Please specify PLATFORM: macos-sdl3, mingw32-sdl3, unix-curses, unix-headless, unix-sdl2, unix-sdl3, wasm)
endif
OBJS = $(OBJDIR)/8x8.o \
$(OBJDIR)/8x14.o \
\
$(OBJDIR)/cpu.o \
$(OBJDIR)/zzt.o \
$(OBJDIR)/zzt_ems.o \
$(OBJDIR)/ui.o \
$(OBJDIR)/audio_stream.o \
$(OBJDIR)/audio_shared.o
ifeq (${USE_SDL2},1)
CFLAGS += -DUSE_SDL -DUSE_SDL2
OBJS += $(OBJDIR)/asset_loader.o \
$(OBJDIR)/posix_vfs.o \
$(OBJDIR)/util.o \
$(OBJDIR)/render_software.o \
$(OBJDIR)/audio_writer.o \
$(OBJDIR)/gif_writer.o \
$(OBJDIR)/screenshot_writer.o \
$(OBJDIR)/sdl2/frontend.o \
$(OBJDIR)/sdl2/render_software.o \
$(OBJDIR)/sdl2/render_opengl.o
else ifeq (${USE_SDL3},1)
CFLAGS += -DUSE_SDL -DUSE_SDL3
OBJS += $(OBJDIR)/asset_loader.o \
$(OBJDIR)/posix_vfs.o \
$(OBJDIR)/util.o \
$(OBJDIR)/render_software.o \
$(OBJDIR)/audio_writer.o \
$(OBJDIR)/gif_writer.o \
$(OBJDIR)/screenshot_writer.o \
$(OBJDIR)/sdl3/frontend.o \
$(OBJDIR)/sdl3/render_software.o \
$(OBJDIR)/sdl3/render_opengl.o
else ifeq (${USE_CURSES},1)
OBJS += $(OBJDIR)/frontend_curses.o \
$(OBJDIR)/asset_loader.o \
$(OBJDIR)/posix_vfs.o
else ifeq (${USE_HEADLESS},1)
OBJS += $(OBJDIR)/frontend_headless.o \
$(OBJDIR)/asset_loader.o \
$(OBJDIR)/posix_vfs.o
endif
ifeq (${PLATFORM},mingw32-sdl)
OBJS += $(OBJDIR)/win32-resources.o
endif
all: $(TARGET)
$(TARGET): $(OBJS)
@mkdir -p $(@D)
$(CC) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR)/8x14.o: $(OBJDIR)/8x14.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -g -c -o $@ $<
$(OBJDIR)/8x14.c: $(OBJDIR)/8x14.bin $(TOOLSDIR)/bin2c.py
@mkdir -p $(@D)
python3 $(TOOLSDIR)/bin2c.py --field_name res_8x14_bin $(OBJDIR)/8x14.c $(OBJDIR)/8x14.h $(OBJDIR)/8x14.bin
$(OBJDIR)/8x14.bin: $(FONTSDIR)/pc_ega.png $(TOOLSDIR)/font2raw.py
@mkdir -p $(@D)
python3 $(TOOLSDIR)/font2raw.py $< 8 14 a $@
$(OBJDIR)/8x8.o: $(OBJDIR)/8x8.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -g -c -o $@ $<
$(OBJDIR)/8x8.c: $(OBJDIR)/8x8.bin $(TOOLSDIR)/bin2c.py
@mkdir -p $(@D)
python3 $(TOOLSDIR)/bin2c.py --field_name res_8x8_bin $(OBJDIR)/8x8.c $(OBJDIR)/8x8.h $(OBJDIR)/8x8.bin
$(OBJDIR)/8x8.bin: $(FONTSDIR)/pc_cga.png $(TOOLSDIR)/font2raw.py
@mkdir -p $(@D)
python3 $(TOOLSDIR)/font2raw.py $< 8 8 a $@
$(OBJDIR)/win32-resources.o: mingw/resources.rc
@mkdir -p $(@D)
$(WINDRES) -i $< -o $@
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET)