# Makefile for EarthPoints -  Invoke using "gmake" or "gmake clean"
#   Note that the AnsiCmd link library is built as a stand-alone library 
#   so that it can be exported to other applications.
# 
# Mahlon R. Smith
# Tools: G++ / Gcc 12.3.1 for Linux (Fedora 37 workstation)
# 
# 08-Jul-2023

# This variable is defined for technical reasons
# (see 'make' documentation for more information)
.RECIPEPREFIX = >

# Header-file groups and Object-file groups
AC_HFILES = AnsiCmd.hpp AnsiCmdDef.hpp AnsiCmdWin.hpp
AC_OFILES = AnsiCmd.o AnsiCmdWin.o AnsiCmdApi.o AnsiCmdSkf.o AnsiCmdTest.o gString.o

HFILES = EarthPoints.hpp gString.hpp $(AC_HFILES)
OFILES = EarthPoints.o EpParse.o gString.o

COMPILE = g++ -x c++ -std=gnu++11 -Wall -c
# Special compile: stop-on-error
#COMPILE = g++ -x c++ -std=gnu++11 -Wall -fmax-errors=1 -c


epts: $(OFILES) $(AC_OFILES) AnsiCmd.lib
> g++ -o epts $(OFILES) AnsiCmd.lib

EarthPoints.o: EarthPoints.cpp $(HFILES)
> $(COMPILE) EarthPoints.cpp

EpParse.o: EpParse.cpp $(HFILES) 
> $(COMPILE) EpParse.cpp

#** Build the AnsiCmd link library **
# P == use full path of objects
# c == create the archive
# r == insert objects with replacement
# v == verbose information
AnsiCmd.lib: $(AC_OFILES)
> ar -Pcrv AnsiCmd.lib $(AC_OFILES)

AnsiCmd.o: AnsiCmd.cpp $(AC_HFILES) 
> $(COMPILE) AnsiCmd.cpp

AnsiCmdWin.o: AnsiCmdWin.cpp $(AC_HFILES) 
> $(COMPILE) AnsiCmdWin.cpp

AnsiCmdApi.o: AnsiCmdApi.cpp $(AC_HFILES) 
> $(COMPILE) AnsiCmdApi.cpp

AnsiCmdSkf.o: AnsiCmdSkf.cpp $(AC_HFILES) 
> $(COMPILE) AnsiCmdSkf.cpp

AnsiCmdTest.o: AnsiCmdTest.cpp $(AC_HFILES) 
> $(COMPILE) AnsiCmdTest.cpp

gString.o: gString.cpp gString.hpp
> $(COMPILE) gString.cpp


#** Build All **
# NOTE: The '-i' (ignore) option is used here in case none of the targets to 
#       be removed by "clean" exist. The '-s' (silent) option is also used here.
.PHONY: all
all:
> gmake -si clean
> gmake --no-print-directory

#** Remove old object files and the executable for a clean build **
.PHONY: clean
clean:
> rm --force $(OFILES) $(AC_OFILES) AnsiCmd.lib epts

