# Makefile -- builds sttp.exe (Windows, MinGW-w64: mingw32-make) or sttp
# (Linux and others: make).  Lua 5.3.6 is built from its source in lua/ and
# linked in statically, so sttp.exe needs nothing installed where it runs.
#
# sttp.exe is written one folder up, beside examples\, as in the STTP
# download: the examples' test.bat files run ..\..\sttp.exe.
#
#   mingw32-make           build
#   mingw32-make clean     remove what the build made

CC       = gcc
CXX      = g++
CFLAGS   = -O2 -DLUA_COMPAT_5_2
CXXFLAGS = -O2 -I lua
LDFLAGS  = -static

ifeq ($(OS),Windows_NT)
  EXE = .exe
endif

LUA_O = $(patsubst %.c,%.o,$(wildcard lua/*.c))

STTP = ../sttp$(EXE)

$(STTP): sttp.o anyoption.o liblua.a
	$(CXX) -o $@ $(LDFLAGS) sttp.o anyoption.o liblua.a

liblua.a: $(LUA_O)
	$(AR) rcs $@ $^

sttp.o: sttp.cpp anyoption.h lua.hpp
anyoption.o: anyoption.cpp anyoption.h

.PHONY: clean
clean:
ifeq ($(OS),Windows_NT)
	-del /q ..\sttp.exe sttp.exe sttp.o anyoption.o liblua.a lua\*.o 2>nul
else
	-rm -f ../sttp sttp sttp.o anyoption.o liblua.a lua/*.o
endif
