BIN_DIR = ../lib
BIN = $(BIN_DIR)/libgame.a

# ---------------------------------------------------------------------------
# ### LINUX-BLOCK-BEGIN (Makefile platform detection)
# FreeBSD takes the else branch, which is verbatim the original Makefile.
# ---------------------------------------------------------------------------
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)

CXX	= g++

# attribute.cc and targa.cc include ../../libthecore/include/stdafx.h, and
# grid.cc includes ../../common/stl.h, so this must be compiled with the same
# C++ standard as game/ and db/ (-std=c++23) and the same word size (-m32).
# -fno-strict-aliasing: targa.cc walks a TGA pixel buffer through casted
# BYTE*/WORD* pointers and grid.cc bit-twiddles its cell array the same way;
# GCC 13 is entitled to reorder those accesses at -O2 without it.
CFLAGS = -Wall -O2 -pipe -mtune=i686 -m32 -std=c++23 -fno-exceptions -fno-strict-aliasing -I../include

ARFLAGS_GAME = cr

else

CXX	= clang++-devel

CFLAGS = -Wall -O2 -pipe -mtune=i686 -fno-exceptions -I../include

ARFLAGS_GAME = cru

endif
# ### LINUX-BLOCK-END (Makefile platform detection)

LIBS =

OBJFILES = grid.o attribute.o targa.o

default:
	$(MAKE) $(BIN)

$(BIN): $(OBJFILES)
	if [ ! -d $(BIN_DIR) ]; then mkdir $(BIN_DIR); fi
	ar $(ARFLAGS_GAME) $(BIN) $(OBJFILES) $(LIBS)
	ranlib $(BIN)
	chmod 700 $(BIN)

clean:
	rm -f *.o
	rm -f $(BIN)

dep:
	touch Depend
	$(CXX) $(CFLAGS) -MM *.cc > Depend

$(OBJFILES):
	$(CXX) $(CFLAGS) -c $<

include Depend
