-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
308 lines (250 loc) · 13 KB
/
Makefile
File metadata and controls
308 lines (250 loc) · 13 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
CC = cc
UNAME_S := $(shell uname -s)
# OpenMP: macOS uses libomp via brew; Linux uses libgomp via -fopenmp
ifeq ($(UNAME_S),Darwin)
OMP_PREFIX = $(shell brew --prefix libomp 2>/dev/null)
OMP_CFLAGS = -Xpreprocessor -fopenmp -I$(OMP_PREFIX)/include
OMP_LDFLAGS = -L$(OMP_PREFIX)/lib -lomp
else
OMP_CFLAGS = -fopenmp
OMP_LDFLAGS = -fopenmp
endif
CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 \
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O2 -Ivendor -Isrc \
$(OMP_CFLAGS)
TCFLAGS = $(CFLAGS) -Wno-extra-semi
LDFLAGS = -lm $(OMP_LDFLAGS)
# Linux needs _DEFAULT_SOURCE for clock_gettime/nanosleep with -std=c11
# macOS exposes POSIX symbols by default; adding _POSIX_C_SOURCE restricts them
ifeq ($(UNAME_S),Linux)
CFLAGS += -D_DEFAULT_SOURCE
endif
# Pledge/unveil sandboxing (Linux only — OpenBSD has native support)
# Note: Requires -D_GNU_SOURCE for CLONE_* and F_OFD_* constants
# Disabled on CI due to vendor compatibility issues - can re-enable after fixing pledge-linux.c
PLEDGE_OBJ =
ifeq ($(UNAME_S),Linux)
ifneq ($(CI),true)
PLEDGE_SRC = vendor/pledge/libc/calls/pledge.c \
vendor/pledge/libc/calls/pledge-linux.c \
vendor/pledge/libc/calls/unveil.c \
vendor/pledge/libc/calls/parsepromises.c \
vendor/pledge/libc/calls/landlock_create_ruleset.c \
vendor/pledge/libc/calls/landlock_add_rule.c \
vendor/pledge/libc/calls/landlock_restrict_self.c \
vendor/pledge/libc/intrin/promises.c \
vendor/pledge/libc/calls/islinux.c \
vendor/pledge/libc/intrin/pthread_setcancelstate.c \
vendor/pledge/libc/str/classifypath.c \
vendor/pledge/libc/str/endswith.c \
vendor/pledge/libc/str/isabspath.c \
vendor/pledge/libc/fmt/joinpaths.c
PLEDGE_OBJ = $(PLEDGE_SRC:.c=.o)
CFLAGS += -Ivendor/pledge -D_GNU_SOURCE
endif
endif
# Debug build with sanitizers (no OpenMP — conflicts with ASan)
DEBUG_CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 \
-g -O0 -fsanitize=address,undefined -fno-omit-frame-pointer \
-Ivendor -Isrc
ifeq ($(UNAME_S),Linux)
DEBUG_CFLAGS += -D_DEFAULT_SOURCE
endif
DEBUG_LDFLAGS = -lm -fsanitize=address,undefined
SRC = src/main.c src/image.c src/sampling.c src/grid.c src/font.c \
src/contrast.c src/match.c src/output.c src/temporal.c src/compress.c \
src/glif.c src/blip.c vendor/miniz.c
OBJ = $(SRC:.c=.o)
BIN = glif
# Library objects (everything except main.o)
LIB_OBJ = src/image.o src/sampling.o src/grid.o src/font.o \
src/contrast.o src/match.o src/output.o src/temporal.o src/compress.o \
src/glif.o src/blip.o vendor/miniz.o
# Linux-only: v4l2 output
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
SRC += src/platform/linux/v4l2_output.c
LIB_OBJ += src/platform/linux/v4l2_output.o
ifneq ($(CI),true)
SRC += src/sandbox.c
LIB_OBJ += src/sandbox.o
endif
endif
TESTS = tests/test_vec6 tests/test_sampling tests/test_image \
tests/test_grid tests/test_contrast tests/test_match \
tests/test_font tests/test_output tests/test_temporal \
tests/test_compress tests/test_glif tests/test_blip
all: $(BIN)
$(BIN): $(OBJ) $(PLEDGE_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
src/%.o: src/%.c
$(CC) $(CFLAGS) -c -o $@ $<
vendor/%.o: vendor/%.c
$(CC) $(CFLAGS) -Wno-shadow -Wno-format-nonliteral -c -o $@ $<
vendor/pledge/%.o: vendor/pledge/%.c
$(CC) $(CFLAGS) -Wno-shadow -Wno-pedantic -Wno-format-nonliteral \
-Wno-unused-parameter -Wno-sign-compare -c -o $@ $<
src/platform/linux/%.o: src/platform/linux/%.c
$(CC) $(CFLAGS) -c -o $@ $<
src/platform/wasm/%.o: src/platform/wasm/%.c
$(CC) $(CFLAGS) -c -o $@ $<
# Test targets — each links against the library objects it needs
tests/test_vec6: tests/test_vec6.c src/vec6.h
$(CC) $(TCFLAGS) -o $@ tests/test_vec6.c $(LDFLAGS)
tests/test_sampling: tests/test_sampling.c src/sampling.o
$(CC) $(TCFLAGS) -o $@ tests/test_sampling.c src/sampling.o $(LDFLAGS)
tests/test_image: tests/test_image.c src/image.o
$(CC) $(TCFLAGS) -o $@ tests/test_image.c src/image.o $(LDFLAGS)
tests/test_grid: tests/test_grid.c src/image.o src/sampling.o src/grid.o
$(CC) $(TCFLAGS) -o $@ tests/test_grid.c src/image.o src/sampling.o src/grid.o $(LDFLAGS)
tests/test_contrast: tests/test_contrast.c src/contrast.o src/sampling.o
$(CC) $(TCFLAGS) -o $@ tests/test_contrast.c src/contrast.o src/sampling.o $(LDFLAGS)
tests/test_match: tests/test_match.c src/sampling.o src/match.o src/font.o src/image.o
$(CC) $(TCFLAGS) -o $@ tests/test_match.c src/sampling.o src/match.o src/font.o src/image.o $(LDFLAGS)
tests/test_font: tests/test_font.c src/font.o src/sampling.o src/image.o
$(CC) $(TCFLAGS) -o $@ tests/test_font.c src/font.o src/sampling.o src/image.o $(LDFLAGS)
tests/test_output: tests/test_output.c src/output.o src/compress.o src/glif.o src/blip.o src/font.o src/image.o src/sampling.o src/grid.o src/contrast.o src/match.o vendor/miniz.o
$(CC) $(TCFLAGS) -o $@ tests/test_output.c src/output.o src/compress.o src/glif.o src/blip.o src/font.o src/image.o src/sampling.o src/grid.o src/contrast.o src/match.o vendor/miniz.o $(LDFLAGS)
tests/test_temporal: tests/test_temporal.c src/temporal.o src/image.o src/sampling.o src/grid.o src/contrast.o src/match.o src/font.o
$(CC) $(TCFLAGS) -o $@ tests/test_temporal.c src/temporal.o src/image.o src/sampling.o src/grid.o src/contrast.o src/match.o src/font.o $(LDFLAGS)
tests/test_compress: tests/test_compress.c src/compress.o vendor/miniz.o
$(CC) $(TCFLAGS) -o $@ tests/test_compress.c src/compress.o vendor/miniz.o $(LDFLAGS)
tests/test_glif: tests/test_glif.c src/glif.o src/compress.o src/output.o src/blip.o src/grid.o src/image.o src/sampling.o src/font.o src/contrast.o src/match.o vendor/miniz.o
$(CC) $(TCFLAGS) -o $@ tests/test_glif.c src/glif.o src/compress.o src/output.o src/blip.o src/grid.o src/image.o src/sampling.o src/font.o src/contrast.o src/match.o vendor/miniz.o $(LDFLAGS)
tests/test_blip: tests/test_blip.c src/blip.o src/glif.o src/compress.o src/output.o src/grid.o src/image.o src/sampling.o src/font.o src/contrast.o src/match.o vendor/miniz.o
$(CC) $(TCFLAGS) -o $@ tests/test_blip.c src/blip.o src/glif.o src/compress.o src/output.o src/grid.o src/image.o src/sampling.o src/font.o src/contrast.o src/match.o vendor/miniz.o $(LDFLAGS)
test: $(LIB_OBJ) $(TESTS)
@echo "=== Running tests ==="
@fail=0; \
for t in $(TESTS); do \
echo "--- $$t ---"; \
./$$t || fail=1; \
done; \
if [ $$fail -eq 0 ]; then echo "=== All tests passed ==="; \
else echo "=== Some tests failed ==="; exit 1; fi
tools/bench: tools/bench.c $(LIB_OBJ) $(PLEDGE_OBJ)
$(CC) $(CFLAGS) -o $@ tools/bench.c $(LIB_OBJ) $(PLEDGE_OBJ) $(LDFLAGS)
tools/glif_verify: tools/glif_verify.c $(LIB_OBJ) $(PLEDGE_OBJ)
$(CC) $(CFLAGS) -o $@ tools/glif_verify.c $(LIB_OBJ) $(PLEDGE_OBJ) $(LDFLAGS)
tools/glif_transcode: tools/glif_transcode.c $(LIB_OBJ) $(PLEDGE_OBJ)
$(CC) $(CFLAGS) -o $@ tools/glif_transcode.c $(LIB_OBJ) $(PLEDGE_OBJ) $(LDFLAGS)
tools/glif_codec_stats: tools/glif_codec_stats.c $(LIB_OBJ) $(PLEDGE_OBJ)
$(CC) $(CFLAGS) -o $@ tools/glif_codec_stats.c $(LIB_OBJ) $(PLEDGE_OBJ) $(LDFLAGS)
tools/glif_compare: tools/glif_compare.c $(LIB_OBJ) $(PLEDGE_OBJ)
$(CC) $(CFLAGS) -o $@ tools/glif_compare.c $(LIB_OBJ) $(PLEDGE_OBJ) $(LDFLAGS)
debug: clean
$(CC) $(DEBUG_CFLAGS) -o $(BIN) $(SRC) $(DEBUG_LDFLAGS)
# Core library (shared between native + WASM)
CORE_SRC = src/image.c src/sampling.c src/grid.c src/font.c \
src/contrast.c src/match.c src/temporal.c
# WASM build via Emscripten (Nuklear + Clay UI)
WASM_UI_SRC = $(CORE_SRC) \
src/platform/wasm/ui.c \
src/platform/wasm/nk_webgl.c \
src/platform/wasm/nk_impl.c \
src/platform/wasm/clay_impl.c \
src/platform/wasm/ui_layout.c
WASM_UI_OUT = web/glif.js
WASM_EXPORTS = '_app_init','_app_resize','_app_set_dpr','_app_frame','_app_mouse','_app_key', \
'_app_touch','_app_load_font','_app_load_image','_app_video_frame', \
'_app_switch_camera','_app_get_camera_count', \
'_app_get_grid_rows','_app_get_grid_cols','_app_get_grid_cell_w','_app_get_grid_cell_h', \
'_app_export_grid','_app_get_font_ptr','_app_get_font_len', \
'_app_upload_video_frame','_app_toggle_compare', \
'_app_set_content_mode','_app_set_media_state','_app_toggle_hdr', \
'_app_toggle_help','_app_set_download_state','_app_clear_content','_malloc','_free'
wasm: $(WASM_UI_SRC)
@mkdir -p web
emcc -std=gnu11 -O2 -Wall -Wextra -msimd128 -Ivendor -Isrc \
-Isrc/platform/wasm \
-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s FULL_ES2=1 \
-s MODULARIZE=1 -s EXPORT_NAME='createGlifModule' \
-s "EXPORTED_FUNCTIONS=[$(WASM_EXPORTS)]" \
-s "EXPORTED_RUNTIME_METHODS=['ccall','cwrap','HEAPU8','HEAP8']" \
-s NO_FILESYSTEM=1 -s SINGLE_FILE=1 --no-entry \
-o $(WASM_UI_OUT) $(WASM_UI_SRC) -lm
# WASM build for Chrome extension (no UI framework, just pipeline + WebGL)
WASM_EXT_SRC = $(CORE_SRC) src/platform/wasm/ext.c
WASM_EXT_EXPORTS = '_ext_init','_ext_resize','_ext_frame','_ext_render', \
'_ext_set_params','_ext_set_hdr','_ext_set_hires','_malloc','_free'
# Shared library
ifeq ($(UNAME_S),Darwin)
SHARED_LIB = libglif.dylib
SHARED_FLAGS = -dynamiclib -install_name @rpath/$(SHARED_LIB)
else
SHARED_LIB = libglif.so
SHARED_FLAGS = -shared
endif
LIB_PIC_OBJ = $(LIB_OBJ:.o=.pic.o)
src/%.pic.o: src/%.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
vendor/%.pic.o: vendor/%.c
$(CC) $(CFLAGS) -Wno-shadow -Wno-format-nonliteral -fPIC -c -o $@ $<
src/platform/linux/%.pic.o: src/platform/linux/%.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
$(SHARED_LIB): $(LIB_PIC_OBJ)
$(CC) $(SHARED_FLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: shared
shared: $(SHARED_LIB)
wasm-ext: $(WASM_EXT_SRC)
@mkdir -p extension/wasm
emcc -std=gnu11 -O2 -Wall -Wextra -msimd128 -Ivendor -Isrc \
-Isrc/platform/wasm \
-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s FULL_ES2=1 \
-s MODULARIZE=1 -s EXPORT_NAME='createGlifExt' \
-s "EXPORTED_FUNCTIONS=[$(WASM_EXT_EXPORTS)]" \
-s "EXPORTED_RUNTIME_METHODS=['HEAPU8']" \
-s NO_FILESYSTEM=1 --no-entry \
-o extension/wasm/glif-ext.js $(WASM_EXT_SRC) -lm
# WASM player for .glif playback (minimal deps, no pipeline)
WASM_PLAYER_SRC = src/glif.c src/compress.c src/blip.c vendor/miniz.c src/platform/wasm/player.c
WASM_PLAYER_EXPORTS = '_player_init','_player_load','_player_decode_frame', \
'_player_render','_player_resize','_player_free', \
'_player_set_hdr','_player_set_compare', \
'_player_bind_video_tex','_player_upload_video_frame', \
'_player_get_frames','_player_get_fps', \
'_player_get_cols','_player_get_rows', \
'_player_get_cell_w','_player_get_cell_h', \
'_player_get_flags', \
'_player_has_audio','_player_get_audio_pcm_ptr', \
'_player_get_audio_pcm_len','_player_get_audio_bit_depth', \
'_player_get_audio_sample_rate','_player_has_orig_audio', \
'_player_get_orig_audio_ptr','_player_get_orig_audio_len', \
'_malloc','_free'
wasm-player: $(WASM_PLAYER_SRC)
@mkdir -p web
emcc -std=gnu11 -O2 -Wall -Wextra -Ivendor -Isrc \
-Isrc/platform/wasm \
-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s FULL_ES2=1 \
-s MODULARIZE=1 -s EXPORT_NAME='createGlifPlayer' \
-s "EXPORTED_FUNCTIONS=[$(WASM_PLAYER_EXPORTS)]" \
-s "EXPORTED_RUNTIME_METHODS=['HEAPU8']" \
-s NO_FILESYSTEM=1 --no-entry \
-o web/glif-player-wasm.js $(WASM_PLAYER_SRC) -lm
# WASM encoder for in-browser .glif encoding (full pipeline + writer)
WASM_ENCODE_SRC = $(CORE_SRC) src/output.c src/compress.c src/glif.c src/blip.c \
vendor/miniz.c src/platform/wasm/encode.c
WASM_ENCODE_EXPORTS = '_encoder_init','_encoder_frame','_encoder_audio_samples', \
'_encoder_keep_original_audio','_encoder_finish', \
'_encoder_get_output_ptr','_encoder_get_output_len', \
'_malloc','_free'
wasm-encode: $(WASM_ENCODE_SRC)
@mkdir -p web
emcc -std=gnu11 -O2 -Wall -Wextra -Ivendor -Isrc \
-Isrc/platform/wasm \
-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 -s EXPORT_NAME='createGlifEncoder' \
-s "EXPORTED_FUNCTIONS=[$(WASM_ENCODE_EXPORTS)]" \
-s "EXPORTED_RUNTIME_METHODS=['HEAPU8','HEAP16']" \
-s FORCE_FILESYSTEM=1 \
-o web/glif-encoder-wasm.js $(WASM_ENCODE_SRC) -lm
# Download ffmpeg-wasm to web/vendor/ffmpeg/
fetch-ffmpeg:
@bash scripts/fetch-ffmpeg.sh
clean:
rm -f $(OBJ) $(BIN) $(TESTS)
rm -f src/*.pic.o src/platform/linux/*.o src/platform/linux/*.pic.o src/platform/wasm/*.o
rm -f vendor/*.o vendor/*.pic.o
rm -f $(PLEDGE_OBJ)
rm -f libglif.so libglif.dylib
.PHONY: all clean test debug wasm wasm-ext wasm-player wasm-encode fetch-ffmpeg shared