include nix.tup
CPPFLAGS_ = -Wall -Werror -std=c++17 -fcolor-diagnostics -g -O1 -I./3rd-party/stb
CPPFLAGS_ASAN = $(CPPFLAGS_) -fsanitize=address -fno-omit-frame-pointer
CPPFLAGS_THREAD = $(CPPFLAGS_) -fsanitize=thread
CPPFLAGS_MEM = $(CPPFLAGS_) -fsanitize=memory -fno-omit-frame-pointer
CPPFLAGS_UB = $(CPPFLAGS_) -fsanitize=undefined
CPPFLAGS = $(CPPFLAGS_)

LINK_FLAGS = -L. -lpacking

GUI_FLAGS = -I3rd-party/raylib-4.0.0/src
GUI_LINK_FLAGS = $(LINK_FLAGS) -L3rd-party/raylib-4.0.0 -lraylib -lGL -lc -lm -lpthread -ldl -lrt -lX11

: foreach *.cpp ^main_cli.cpp ^main_gui.cpp ^png_impl.cpp |> ^ CXX %f^ clang++ -c %f -o %o $(CPPFLAGS) |> %B.o {objs}
: {objs} |> ^ AR %o^ ar rcs %o %f |> libpacking.a

: foreach main_cli.cpp png_impl.cpp |> ^ CXX %f^ clang++ -c %f -o %o $(CPPFLAGS) |> %B.o {cli}
: libpacking.a {cli} |> ^ LINK %o^ clang++ %f -o %o $(LINK_FLAGS) |> ../packing_cli

: main_gui.cpp |> ^ CXX %f^ clang++ -c %f -o %o $(CPPFLAGS) $(GUI_FLAGS) |> %B.o {gui}
: libpacking.a {gui} | 3rd-party/<raylib> |> ^ LINK %o^ clang++ %f -o %o $(GUI_LINK_FLAGS) |> ../packing_gui
