-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
164 lines (145 loc) · 4.18 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
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-sdl)
USE_SDL = 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-sdl)
USE_SDL = 1
CC = clang
LIBS = -framework OpenGL -lSDL2 -lSDL2main -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-sdl)
USE_SDL = 1
LIBS = -lGL -lSDL2 -lSDL2main -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 --js-library ${SRCDIR}/emscripten_glue.js \
-s STRICT=1 --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 SUPPORT_ERRNO=0 \
-s ALLOW_MEMORY_GROWTH=1 -s ASSERTIONS=0 \
-s 'MALLOC="emmalloc"' -s FILESYSTEM=0 \
-s INITIAL_MEMORY=4194304 -s STACK_SIZE=262144 \
-DNO_MEMSET -DAVOID_MALLOC --no-entry -DVERSION=\"${VERSION}\"
LDFLAGS = ${CFLAGS}
TARGET = $(BUILDDIR)/zeta_native.js
else
$(error Please specify PLATFORM: macos-sdl, mingw32-sdl, unix-curses, unix-headless, unix-sdl, 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_SDL},1)
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)/sdl/frontend.o \
$(OBJDIR)/sdl/render_software.o \
$(OBJDIR)/sdl/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)