CC=gcc
CFLAGS=-Wall -g -I/usr/include/SDL2 -DLINUX
LDFLAGS=-lSDL2_ttf -lSDL2

all: annotator annotator.exe annotator.html

# common

notosans_regular_ttf.c: fonts/NotoSans-Regular.ttf
	(cd fonts && xxd -i NotoSans-Regular.ttf | tr A-Z a-z ) > notosans_regular_ttf.c

notosans_regular_ttf.h: fonts/NotoSans-Regular.ttf
	(cd fonts && xxd -i NotoSans-Regular.ttf | sed "s/^\(.*[^ ]\) *=.*/extern \1\;/g" | grep extern | tr A-Z a-z ) > notosans_regular_ttf.h

# boxui.o: linux

boxui.o: boxui.c boxui.h notosans_regular_ttf.c notosans_regular_ttf.h

# boxui-windows.o: windows

boxui-windows.o: boxui.c boxui.h notosans_regular_ttf.c notosans_regular_ttf.h
	toolchain-zig/compile.sh boxui.c -c -o boxui-windows.o

# boxui-html.o: html5

boxui-html.o: boxui.c boxui.h notosans_regular_ttf.c notosans_regular_ttf.h
	sh -c ". toolchain-emscripten/env.sh ; emcc -g -Wall -s USE_SDL=2 -s USE_SDL_TTF=2 boxui.c -c -o boxui-html.o"

# annotator: linux

annotator.o: annotator.c boxui.h

annotator: boxui.o annotator.o
	gcc annotator.o boxui.o -o annotator -lSDL2_ttf -lSDL2

# annotator: windows

annotator-windows.o: annotator.c boxui.h
	toolchain-zig/compile.sh annotator.c -c -o annotator-windows.o

annotator.exe: annotator-icon_256x256.png boxui-windows.o annotator-windows.o
	toolchain-zig/link.sh -icon annotator-icon_256x256.png annotator.exe boxui-windows.o annotator-windows.o

# annotator: html5

annotator-html.o: annotator.c
	sh -c ". toolchain-emscripten/env.sh ; emcc -g -Wall -s USE_SDL=2 -s USE_SDL_TTF=2 annotator.c -c -o annotator-html.o"

annotator.html: boxui-html.template boxui-html.o annotator-html.o
	sh -c ". toolchain-emscripten/env.sh ; emcc annotator-html.o boxui-html.o -o annotator.html -s USE_SDL=2 -s USE_SDL_TTF=2 && sed s/PROGRAMNAME/annotator/g < boxui-html.template > annotator.html && zip -pr annotator-html.zip annotator.html annotator.js annotator.wasm"

clean:
	rm -f *.o *.js *.html *.wasm *.exe \
 notosans_regular_ttf.c notosans_regular_ttf.h \
 annotator annotator.exe annotator-html.zip