CC=gcc
CFLAGS=-g -Wall -Wformat-truncation=0 -Ideps -I/usr/include/SDL2
LDFLAGS=-lSDL2 -lSDL2_image -lSDL2_ttf

all: re tests tests_utf8

recenteditor.o: recenteditor.c re_data.h ext/socklib.h

re_data.o: re_data.c re_data.h

re_plugin_unsaved.o: re_plugin_unsaved.c re_plugin_unsaved.h re_data.h

re_plugin_highlighter.o: re_plugin_highlighter.c re_plugin_highlighter.h re_data.h

re_plugin_prototypes.o: re_plugin_prototypes.c re_plugin_prototypes.h prototypes_c89_posix.h

re_ui.o: re_ui.c re_ui.h hack_regular.h iosevka_fixed_regular.h

re_tests.o: re_tests.c re_data.h

re_tests_utf8.o: re_tests_utf8.c re_ui.h

sha3.o: sha3/sha3.c sha3/sha3.h
	$(CC) $(CFLAGS) -Isha3 -c -o sha3.o sha3/sha3.c

hack_regular.c: ttf/Hack-Regular.ttf
	./ttf2h.sh ttf/Hack-Regular.ttf

hack_regular.h: ttf/Hack-Regular.ttf
	./ttf2h.sh ttf/Hack-Regular.ttf

hack_regular.o: hack_regular.c
	$(CC) $(CFLAGS) -c -o hack_regular.o hack_regular.c

iosevka_fixed_regular.c: ttf/iosevka-fixed-regular.ttf
	./ttf2h.sh ttf/iosevka-fixed-regular.ttf

iosevka_fixed_regular.h: ttf/iosevka-fixed-regular.ttf
	./ttf2h.sh ttf/iosevka-fixed-regular.ttf

iosevka_fixed_regular.o: iosevka_fixed_regular.c
	$(CC) $(CFLAGS) -c -o iosevka_fixed_regular.o iosevka_fixed_regular.c

prototypes_c89_posix.c: prototypes_c89_posix.txt
	./prototypes2h.sh prototypes_c89_posix.txt

prototypes_c89_posix.h: prototypes_c89_posix.txt
	./prototypes2h.sh prototypes_c89_posix.txt

prototypes_c89_posix.o: prototypes_c89_posix.c
	$(CC) $(CFLAGS) -c -o prototypes_c89_posix.o prototypes_c89_posix.c

prototypes_tcl.c: prototypes_tcl.txt
	./prototypes2h.sh prototypes_tcl.txt

prototypes_tcl.h: prototypes_tcl.txt
	./prototypes2h.sh prototypes_tcl.txt

prototypes_tcl.o: prototypes_tcl.c
	$(CC) $(CFLAGS) -c -o prototypes_tcl.o prototypes_tcl.c

socklib.o: ext/socklib.c ext/socklib.h
	$(CC) $(CFLAGS) -Iext -c -o socklib.o ext/socklib.c

re: recenteditor.o re_data.o re_plugin_unsaved.o re_plugin_highlighter.o re_plugin_prototypes.o prototypes_c89_posix.o prototypes_tcl.o sha3.o re_ui.o hack_regular.o iosevka_fixed_regular.o socklib.o
	$(CC) -o re recenteditor.o re_data.o re_plugin_unsaved.o re_plugin_highlighter.o re_plugin_prototypes.o prototypes_c89_posix.o prototypes_tcl.o sha3.o re_ui.o hack_regular.o iosevka_fixed_regular.o socklib.o $(LDFLAGS)

tests: re_tests.o re_data.o sha3.o
	$(CC) $(LDFLAGS) -o tests re_tests.o re_data.o sha3.o

tests_utf8: re_tests_utf8.o re_data.o sha3.o
	$(CC) $(LDFLAGS) -o tests_utf8 re_tests_utf8.o re_data.o sha3.o

re32: recenteditor.c re_data.c re_plugin_unsaved.c re_plugin_highlighter.c re_plugin_prototypes.c prototypes_c89_posix.c prototypes_tcl.c sha3/sha3.c re_ui.c hack_regular.c iosevka_fixed_regular.c ../webkernel/src/socklib.c
	sh -c ". /shared/Devel/toolchains/zig/env.sh ; zig cc -target x86-linux-musl -I/shared/Devel/toolchains/alpine/alpine-i386/usr/include/ -I/shared/Devel/toolchains/alpine/alpine-i386/usr/include/SDL2/ -L/shared/Devel/toolchains/alpine/alpine-i386/usr/lib recenteditor.c re_data.c re_plugin_unsaved.c re_plugin_highlighter.c re_plugin_prototypes.c prototypes_c89_posix.c prototypes_tcl.c -Isha3 sha3/sha3.c re_ui.c hack_regular.c iosevka_fixed_regular.c -I../webkernel/src/ ../webkernel/src/socklib.c -lSDL2 -lSDL2_ttf -o re32"

re64: recenteditor.c re_data.c re_plugin_unsaved.c re_plugin_highlighter.c re_plugin_prototypes.c prototypes_c89_posix.c prototypes_tcl.c sha3/sha3.c re_ui.c hack_regular.c iosevka_fixed_regular.c ../webkernel/src/socklib.c
	sh -c ". /shared/Devel/toolchains/zig/env.sh ; zig cc -target x86_64-linux-gnu -I/usr/include/ -I/usr/include/SDL2/ -L/usr/lib/x86_64-linux-gnu/ recenteditor.c re_data.c re_plugin_unsaved.c re_plugin_highlighter.c re_plugin_prototypes.c prototypes_c89_posix.c prototypes_tcl.c -Isha3 sha3/sha3.c re_ui.c hack_regular.c iosevka_fixed_regular.c -I../webkernel/src/ ../webkernel/src/socklib.c -lSDL2 -lSDL2_ttf -lfreetype -lpng -lz -lsndio -lasound -lpulse -lwayland-client -lxkbcommon -lwayland-cursor -lwayland-egl -lXrandr -lXxf86vm -lXss -lXi -lXinerama -lXext -lX11 -lX11-xcb -lxcb -lXcursor -lXau -lXdmcp -lXrender -lXfixes -o re64"

clean:
	rm -f recenteditor.o re_data.o re_tests.o re_plugin_unsaved.o re_plugin_highlighter.o sha3.o re_ui.o hack_regular.c hack_regular.h hack_regular.o iosevka_fixed_regular.c iosevka_fixed_regular.h iosevka_fixed_regular.o prototypes_c89_posix.o prototypes_tcl.o re tests