UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
	LDFLAGS=-l:libglfw.so.3 -lGL
endif
ifeq ($(UNAME),Darwin)
	LDFLAGS=-lglfw3 -lgl
endif

SOURCES=$(wildcard *.c)
OBJS=$(SOURCES:.c=.o)
ifdef DEBUG
# enable debugging and profiling
FLAGS=-g -pg
else
FLAGS=-Ofast
endif

default: lattice_sq lattice_hex test_LatticeWorld
clean:
	rm -f *.o test/*.o lattice_sq lattice_hex test_LatticeWorld

lattice_sq: $(SOURCES) Makefile
	$(CC) $(FLAGS) -o $@ -DSIDES=4 main.c SquareLatticeWorld.c LatticeWorld.c LatticeWindow.c $(LDFLAGS)

lattice_hex: $(SOURCES) Makefile
	$(CC) $(FLAGS) -o $@ -DSIDES=6 main.c HexLatticeWorld.c LatticeWorld.c LatticeWindow.c $(LDFLAGS)

test_LatticeWorld: test/test_LatticeWorld.o LatticeWorld.o SquareLatticeWorld.o Makefile
	$(CC) $(FLAGS) -o $@ test/test_LatticeWorld.o LatticeWorld.o SquareLatticeWorld.o $(LDFLAGS)

%.o: %.c Makefile
	$(CC) -c $(FLAGS) -o $@ $<
