CC=gcc
CFLAGS=-Wall -g -Isdl3/SDL-preview-3.1.3/include -Isdl3/SDL_ttf/include -DLINUX
LDFLAGS=sdl3/libSDL3.so sdl3/libSDL3_ttf.so

all: boxui_demo_helloworld boxui_demo_helloworld.exe boxui_demo_helloworld.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=3 -s USE_SDL_TTF=3 boxui.c -c -o boxui-html.o"

# boxui_demo_helloworld: linux

boxui_demo_helloworld.o: boxui_demo_helloworld.c boxui.h

boxui_demo_helloworld: boxui.o boxui_demo_helloworld.o
	gcc boxui_demo_helloworld.o boxui.o $(LDFLAGS) -o boxui_demo_helloworld 

# boxui_demo_helloworld: windows

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

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

# boxui_demo_helloworld: html5

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

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

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