BIN = ./libpoly.a

# ---------------------------------------------------------------------------
# ### LINUX-BLOCK-BEGIN (Makefile platform detection)
# On FreeBSD "uname -s" reports "FreeBSD", the ifeq is false, and every variable
# below is assigned exactly as in the original Makefile.  Only the Linux branch
# is new.  (Note the original's GCC_VERSION probe reads $(CC), which this
# Makefile never sets - it is dead in the original too and is kept verbatim.)
# ---------------------------------------------------------------------------
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)

CXX	= g++

# -m32                    : 32-bit server build.
# -std=c++23              : matches game/src/Makefile and db/src/Makefile, so
#                           libpoly's headers (Poly.h uses std::string,
#                           std::vector, std::list) are parsed the same way in
#                           the library and in its consumers.
# -fno-exceptions -fno-rtti and -D_GLIBCXX_USE_CXX11_ABI=1 are kept from the
# original: the ABI macro in particular MUST stay 1 or std::string would not
# match game/ and db/.
CFLAGS  = -Wall -O2 -pipe -mtune=i686 -m32 -std=c++23 -D_GLIBCXX_USE_CXX11_ABI=1 -fno-exceptions -fno-rtti

ARFLAGS_POLY = cr

else

CXX	= clang++-devel

GCC_VERSION = $(shell $(CC) --version 2>&1 | grep "(GCC)" | cut -d' ' -f3  | cut -d'.' -f1)

CFLAGS  = -Wall -O2 -pipe -mtune=i686 -D_GLIBCXX_USE_CXX11_ABI=1 -fno-exceptions -fno-rtti

ARFLAGS_POLY = cru

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

LIBS =

# main.cc is deliberately NOT in this list, in the original Makefile as well:
# it is a standalone test driver whose first include is <windows.h>.
OBJFILES = Base.o Poly.o SymTable.o Symbol.o

default:
	$(MAKE) $(BIN)

$(BIN): $(OBJFILES)
	ar $(ARFLAGS_POLY) $(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
