-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
323 lines (288 loc) · 11.9 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
DESTDIR ?=
PREFIX ?= /usr/local
CTX_VERSION=0.0.0
CCACHE=`command -v ccache`
CLIENTS_CFILES = $(wildcard demos/c/*.c)
CLIENTS_BINS = $(CLIENTS_CFILES:.c=)
BINS_CFILES = $(wildcard bin/*.c)
BINS = $(BINS_CFILES:.c=)
all: build.conf ctx-wasm.pc ctx-wasm-simd.pc ctx.pc libctx.so ctx.h ctx $(BINS)\
tools/ctx-fontgen #
include build.conf
CFLAGS_warnings= -Wall \
-Wextra \
-Wno-unused-but-set-parameter \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-missing-field-initializers
CFLAGS+= $(CFLAGS_warnings) -fpic -fno-builtin-memcpy -fno-semantic-interposition
CFLAGS+= -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=600 \
-I/usr/X11R6/include -I/usr/X11R7/include
CFLAGS += -ffinite-math-only -fno-trapping-math -fno-signed-zeros -fno-math-errno
CFLAGS+= -I. -Ifonts -Ideps
LIBS += -lm -lpthread
SRC_CFILES = $(wildcard src/*.c)
SRC_OBJS = $(SRC_CFILES:.c=.o)
CTX_OBJS = ctx.o
ifeq ($(CTX_SIMD), 1)
ifeq ($(CTX_ARCH), x86_64)
CTX_SIMD_OBJS = ctx-x86-64-v2.o ctx-x86-64-v3.o
else ifeq ($(CTX_ARCH), armv7l)
CTX_SIMD_OBJS = ctx-arm-neon.o
endif
CTX_OBJS += $(CTX_SIMD_OBJS)
endif
CCC=$(CCACHE) $(CC)
build.conf:
@echo "You have not run configure, running ./configure.sh without arguments for you"
@echo "you will have to run make again after this.";echo
./configure.sh
@echo "!!!!!!!!!!!!!!!!!!!!!!!!";
@echo "!! now run make again !!";
@echo "!!!!!!!!!!!!!!!!!!!!!!!!";false
bin/ctx: bin/ctx-*.c bin/ctx.c
bin/%: bin/%.c build.conf Makefile build.conf libctx.so libctx.a
@echo CC $@;if [ x"$(CTX_EXTRA_STATIC)" = x"" ]; then \
$(CCC) -Wl,-rpath `pwd` -g $< -o $@ $(CFLAGS) libctx.so $(LIBS) $(CTX_CFLAGS) $(CTX_LIBS) $(OFLAGS_LIGHT) \
; else $(CCC) -g $< -o $@ $(CFLAGS) libctx.a $(LIBS) $(CTX_CFLAGS) $(CTX_LIBS) $(OFLAGS_LIGHT) -static && strip $@ ; fi
fonts/%.h: tools/ctx-fontgen #
make -C fonts `echo $@|sed s:fonts/::` #
fonts/Roboto-Regular.h: tools/ctx-fontgen Makefile #
make -C fonts ctx-font-ascii.h #
make -C fonts Roboto-Regular.h #
make -C fonts Cousine-Regular.h #
FONT_STAMP=fonts/Roboto-Regular.h #
test: ctx
make -C tests
distclean: clean
rm -f *.conf
clean:
rm -rf nofont #
rm -f ctx.h #
rm -f ctx *.o highlight.css
rm -f libctx.a libctx.so
rm -f ctx.pc ctx-wasm.pc ctx-wasm-simd.pc
rm -f $(CLIENTS_BINS)
rm -f $(BINS)
rm -f $(TERMINAL_OBJS)
rm -f $(MEDIA_HANDLERS_OBJS)
rm -f $(SRC_OBJS) #
rm -f tests/index.html
rm -f fonts/*.h fonts/ctxf/* tools/ctx-fontgen #
ctx.pc: Makefile
@echo "prefix=$(PREFIX)" > $@
@echo 'exec_prefix=$${prefix}' >> $@
@echo 'libdir=$${prefix}/lib' >> $@
@echo 'includedir=$${prefix}/include' >> $@
@echo 'apiversion=0.0' >> $@
@echo '' >> $@
@echo 'Name: ctx' >> $@
@echo 'Description: ctx vector graphics' >> $@
@echo 'Version: 0.0.0' >> $@
@echo 'Libs: -L$${libdir} -lctx' >> $@
@echo 'Cflags: -I$${includedir}' >> $@
ctx-wasm.pc: Makefile
@echo "prefix=$(PREFIX)" > $@
@echo 'exec_prefix=$${prefix}' >> $@
@echo 'libdir=$${prefix}/lib' >> $@
@echo 'includedir=$${prefix}/include' >> $@
@echo 'apiversion=0.0' >> $@
@echo '' >> $@
@echo 'Name: ctx' >> $@
@echo 'Description: ctx vector graphics - wasm target' >> $@
@echo 'Version: 0.0.0' >> $@
@echo 'Libs: -Wl,--lto-O3 ' >> $@
@echo 'Cflags: -I$${includedir} -DCTX_IMPLEMENTATION -flto -O3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=_main,_free,_calloc,_malloc' >> $@
ctx-wasm-simd.pc: Makefile
@echo "prefix=$(PREFIX)" > $@
@echo 'exec_prefix=$${prefix}' >> $@
@echo 'libdir=$${prefix}/lib' >> $@
@echo 'includedir=$${prefix}/include' >> $@
@echo 'apiversion=0.0' >> $@
@echo '' >> $@
@echo 'Name: ctx' >> $@
@echo 'Description: ctx vector graphics - wasm target' >> $@
@echo 'Version: 0.0.0' >> $@
@echo 'Libs: -Wl,--lto-O3 ' >> $@
@echo 'Cflags: -msimd128 -ftree-vectorize -I$${includedir} -DCTX_IMPLEMENTATION -flto -O3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=_main,_free,_calloc,_malloc' >> $@
install: ctx libctx.so ctx.h ctx.pc ctx-wasm.pc ctx-wasm-simd.pc
install -D -m755 -t $(DESTDIR)$(PREFIX)/bin ctx
install -D -m755 -t $(DESTDIR)$(PREFIX)/lib/pkgconfig ctx.pc
install -D -m755 -t $(DESTDIR)$(PREFIX)/lib/pkgconfig ctx-wasm.pc
install -D -m755 -t $(DESTDIR)$(PREFIX)/lib/pkgconfig ctx-wasm-simd.pc
install -D -m644 -t $(DESTDIR)$(PREFIX)/include ctx.h
install -D -m755 -t $(DESTDIR)$(PREFIX)/lib libctx.so
install -D -m644 -t $(DESTDIR)$(PREFIX)/share/appdata meta/graphics.ctx.terminal.appdata.xml
install -D -m644 -t $(DESTDIR)$(PREFIX)/share/applications meta/graphics.ctx.terminal.desktop
install -D -m644 -t $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps meta/graphics.ctx.terminal.svg
ldconfig || true
uninstall:
rm -rf $(DESTDIR)$(PREFIX)/bin/ctx
rm -rf $(DESTDIR)$(PREFIX)/lib/libctx.so
rm -rf $(DESTDIR)$(PREFIX)/lib/pkgconfig/ctx.pc
rm -rf $(DESTDIR)$(PREFIX)/lib/pkgconfig/ctx-wasm.pc
rm -rf $(DESTDIR)$(PREFIX)/lib/pkgconfig/ctx-wasm-simd.pc
rm -rf $(DESTDIR)$(PREFIX)/include/ctx.h
rm -f $(DESTDIR)$(PREFIX)/share/appdata/graphics.ctx.terminal.appdata.xml
rm -f $(DESTDIR)$(PREFIX)/share/applications/graphics.ctx.terminal.desktop
rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/graphics.ctx.terminal.svg
tools/%: tools/%.c #
make nofont/ctx.h #
$(CCC) $< -o $@ -g -lm -Inofont -I. -Ifonts -lpthread -Wall -lm -Ideps $(CFLAGS_warnings) -DCTX_NO_FONTS -DCTX_STB_TT=1 -DCTX_HARFBUZZ=1 `pkg-config harfbuzz --cflags --libs` #
ctx.o: ctx.c ctx.h build.conf Makefile build.conf \
$(FONT_STAMP) #
@echo CC $@; $(CCC) $< -c -o $@ $(CFLAGS) $(CTX_CFLAGS) $(OFLAGS_LIGHT)
ctx-x86-64-v2.o: ctx.c ctx.h build.conf Makefile build.conf \
$(FONT_STAMP) #
rm -f vec.missed
$(CCC) $< -c -o $@ $(CFLAGS) -DCTX_SIMD_X86_64_V2 -momit-leaf-frame-pointer -ftree-vectorize -mfpmath=sse -mmmx -msse -msse2 -msse4.1 -msse4.2 -mpopcnt -mssse3 $(CTX_CFLAGS) $(OFLAGS_LIGHT) \
#-fopt-info-vec-missed=vec.missed
ctx-x86-64-v3.o: ctx.c ctx.h build.conf Makefile build.conf \
$(FONT_STAMP)#
rm -f vec.optimized
$(CCC) $< -c -o $@ $(CFLAGS) -DCTX_SIMD_X86_64_V3 -mmovbe -momit-leaf-frame-pointer -mxsave -mxsaveopt -ftree-vectorize -mmmx -msse -msse2 -msse4.1 -msse4.2 -mpopcnt -mssse3 -mavx -mavx2 -mfma -mmovbe $(CTX_CFLAGS) $(OFLAGS_LIGHT) \
#-fopt-info-vec-optimized=vec.optimized
ctx-arm-neon.o: ctx.c ctx.h build.conf Makefile build.conf \
$(FONT_STAMP) #
$(CCC) $< -c -o $@ $(CFLAGS) -DCTX_SIMD_ARM_NEON -ftree-vectorize -ffast-math -march=armv7 -mfpu=neon-vfpv4 $(CTX_CFLAGS) $(OFLAGS_LIGHT)
libctx.a: $(CTX_OBJS) build.conf Makefile
@echo AR $@;$(AR) rcs $@ $(CTX_OBJS)
libctx.so: $(CTX_OBJS) build.conf Makefile
@echo CCLD $@;$(CCC) -shared $(LIBS) $(CTX_OBJS) $(CTX_LIBS) -o $@
ctx: bin/ctx
cp $< $@
updateweb: all ctx test #
git repack #
(cd docs ; stagit .. ) #
cat tests/index.html | sed 's/.*script.*//' > tmp #
mv tmp tests/index.html #
git update-server-info #
cp -ru tests/* ~/pgo/ctx.graphics/tests #
cp -fru .git/* /home/pippin/pgo/ctx.graphics/.git #
cp -ru docs/* ~/pgo/ctx.graphics/ #
cp ctx.h ~/pgo/ctx.graphics/ #
#
afl/ctx: ctx.h #
make clean #
CC=../afl/afl-2.52b/afl-gcc make ctx -j5 #
cp ctx afl/ctx #
#
flatpak: #
rm -rf build-dir;flatpak-builder --user build-dir meta/graphics.ctx.terminal.yml #
flatpak-builder --collection-id=graphics.ctx --repo=docs/flatpak --force-clean build-dir meta/graphics.ctx.terminal.yml #
#
flatpak-install: #
rm -rf build-dir;flatpak-builder --install --user build-dir meta/graphics.ctx.terminal.yml #
#
ctx.h: src/*.[ch] squoze/squoze.h src/index $(FONT_STAMP) tools/ctx-fontgen src/constants.h #
(cd src; echo "/* ctx-$(CTX_VERSION) */"> ../$@ ; cat `cat index` | grep -v ctx-split.h | sed 's/CTX_STATIC/static/g' >> ../$@) #
#
nofont/ctx.h: src/*.c src/*.h src/index #
rm -rf nofont #
mkdir nofont #
(cd src;cat `cat index|grep -v font` | grep -v ctx-split.h | sed 's/CTX_STATIC/static/g' > ../$@) #
#
squoze/squoze: squoze/*.[ch] #
make -C squoze squoze #
#
src/constants.h: src/*.c Makefile squoze/squoze #
echo '#ifndef __CTX_CONSTANTS' > $@ #
echo '#define __CTX_CONSTANTS' >> $@ #
for a in `cat src/*.[ch] | tr ';' ' ' | tr ',' ' ' | tr ')' ' '|tr ':' ' ' | tr '{' ' ' | tr ' ' '\n' | grep 'SQZ_[a-z][0-9a-zA-Z_]*'| sort | uniq`;do b=`echo $$a|tail -c+5|tr '_' '-'`;echo "#define $$a `./squoze/squoze -33 $$b`u // \"$$b\"";done >> $@ #
echo '#endif' >> $@ #
#
#
#
#
ctx-$(CTX_VERSION).tar.bz2: ctx.h Makefile configure.sh bin/*.[ch] #
rm -rf dist #
rm -rf ctx-$(CTX_VERSION) #
mkdir dist #
cp ctx.h configure.sh dist #
mkdir dist/fonts #
cp fonts/*.h dist/fonts #
mkdir dist/deps #
cp deps/*.[ch] dist/deps #
cp ctx.c dist #
mkdir dist/meta #
cp meta/* dist/meta #
mkdir dist/tests #
mkdir dist/tests/reference #
cp -r tests/reference/* dist/tests/reference #
cp -r tests/*.ctx dist/tests/ #
cp -r tests/*.svg dist/tests/ #
mkdir dist/bin #
cp bin/ctx*.c dist/bin #
cp bin/touch-test.c dist/bin #
cp bin/*.sh dist/bin #
cp bin/terminal-keyboard.h dist/bin #
grep -v '.*#$$' tests/Makefile > dist/tests/Makefile #
grep -v '.*#$$' Makefile > dist/Makefile #
rm dist/fonts/ctx-font-ascii.h #
#
mv dist ctx-$(CTX_VERSION) #
tar cjf ctx-$(CTX_VERSION).tar.bz2 ctx-$(CTX_VERSION) #
rm -rf ctx-$(CTX_VERSION) #
#
dist: ctx-$(CTX_VERSION).tar.bz2 #
distcheck: dist #
tar xvf ctx-$(CTX_VERSION).tar.bz2 #
(cd ctx-$(CTX_VERSION); CFLAGS=-O1 ./configure.sh --static && make ctx -j && make test ) #
(cd ctx-$(CTX_VERSION); make clean ;CFLAGS=-O1 ./configure.sh && make -j ) #
(cd ctx-$(CTX_VERSION); make clean ;CFLAGS=-Oz ./configure.sh --static --disable-all --enable-vt && make -j ) #
cp ctx-$(CTX_VERSION).tar.bz2 docs/tar #
#
#
#
fuzz-css: tools/fuzz-css.c ctx.h #
$(CCACHE) afl-clang-fast -fsanitize=fuzzer $< -o $@ -I. -O2 #
fuzz-css-O0: tools/fuzz-css.c ctx.h #
$(CCACHE) afl-clang-fast -fsanitize=fuzzer,address $< -o $@ -I. -O0 #
afl-css: fuzz-css #
afl-fuzz -G 3048 -a text -o afl-css -i /home/pippin/media/svg/tests/ -- ./fuzz-css #
fuzz-ctx: tools/fuzz-ctx.c ctx.h #
$(CCACHE) afl-clang-fast -fsanitize=fuzzer $< -O2 -o $@ -I. #
fuzz-ctx-O0: tools/fuzz-ctx.c ctx.h #
$(CCACHE) clang -g $< -O0 -o $@ -I. #
fuzz-ctx-asan: tools/fuzz-ctx.c ctx.h #
$(CCACHE) afl-clang-fast -fsanitize=fuzzer,address $< -o $@ -I. #
afl-ctx-asan: fuzz-ctz-asan #
afl-fuzz -G 512 -a text -i afl/in/ -o afl -- ./fuzz-ctx-asan #
afl-ctx: fuzz-ctx #
afl-fuzz -G 512 -a text -i afl/in/ -o afl -- ./fuzz-ctx #
afl-master: fuzz-ctx #
afl-fuzz -M default -G 128 -a text -i afl/in/ -o afl -- ./fuzz-ctx #
afl-worker: fuzz-ctx #
afl-fuzz -S $(AFL_ID) -G 128 -a text -i afl/in/ -o afl -- ./fuzz-ctx #
#
fuzz-vt: tools/fuzz-vt.c ctx.h #
$(CCACHE) afl-clang-fast -fsanitize=fuzzer $< -o $@ -I. -O2 #
fuzz-vt-asan: tools/fuzz-vt.c ctx.h #
$(CCACHE) afl-clang-fast -fsanitize=fuzzer,address $< -o $@ -I. #
afl-vt: fuzz-vt #
afl-fuzz -i afl/in/ -o afl-vt -G 512 -- ./fuzz-vt #
afl-css-min: #
@rm -rf afl-css/min #
@mkdir afl-css/min #
for b in default; do (cd afl-css/$$b/crashes; for a in id*;do afl-tmin -i $$a -o ../../min/$$b-`echo $$a|sed -e 's/,.*//' -e 's/id://'` -- ../../../fuzz-css || true;done) ; done #
#
afl-vt-min: #
@rm -rf afl-vt/min #
@mkdir afl-vt/min #
for b in default; do (cd afl-vt/$$b/crashes; for a in id*;do afl-tmin -i $$a -o ../../min/$$b-`echo $$a|sed -e 's/,.*//' -e 's/id://'` -- ../../../fuzz-vt || true;done) ; done #
#
afl-ctx-min: #
@rm -rf afl/min #
@mkdir afl/min #
for b in default worker0 worker1 worker2 worker3 worker4; do (cd afl/$$b/crashes; for a in id*;do afl-tmin -i $$a -o ../../min/$$b-`echo $$a|sed -e 's/,.*//' -e 's/id://'` -- ../../../fuzz-ctx || true;done) ; done #
(cd afl/min;for a in *;do mv $$a tmp.ctx ; ../../ctx tmp.ctx -o $$a.ctx;rm tmp.ctx;done) #
afl-plot: #
afl-plot afl-vt/default afl-vt/plot || true #
afl-plot afl/default afl/plot || true #
afl-plot afl-css/default afl-css/plot || true #
afl-resume-vt: #
afl-fuzz -i- -o afl-vt -- ./fuzz-vt #
afl-resume-ctx: #
afl-fuzz -i- -o afl -- ./fuzz-ctx #
afl-resume-css: #
afl-fuzz -i- -o afl-css -- ./fuzz-css #