# ================================================================================
# Makefile for EarthPoints:
#   Note that the AnsiCmd link library is built as a stand-alone library 
#   so that it can be exported to other applications.
#     "gmake"           Build the EarthPoints application
#     "gmake clean"     Delete the executable file, all object files and AnsiCmd.lib
#     "gmake gslib"     Build the stand-alone gString-class link library.
#     "gmake buildlib"  Build the AnsiCmd link library
# 
# Mahlon R. Smith
# Tools: G++ / Gcc 15.2.1 for Linux (Fedora 42 workstation)
# 
# 05-Apr-2026

# This variable is defined for technical reasons
# i.e. to eliminate tab characters from the makefile.
.RECIPEPREFIX = >

# Header-file groups and Object-file groups
AC_HFILES  = AnsiCmd.hpp AnsiCmdDef.hpp TFMan.hpp gString.hpp
AC_OFILES  = AnsiCmd.o AnsiCmdApi.o AnsiCmdWin.o AnsiCmdWix.o AnsiCmdDlg.o \
             AnsiCmdSkf.o AnsiCmdAca.o AnsiCmdTest.o
WIN_HFILES = AnsiCmdWin.hpp AnsiCmdDlg.hpp

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

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


epts: $(OFILES) $(AC_OFILES) AnsiCmd.lib gString.lib
> g++ -o epts $(OFILES) gString.lib 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) gString.lib
> ar -Pcrv AnsiCmd.lib gString.lib $(AC_OFILES)

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

# Note that both the header file and source code file for the
# WaylandCB class are set as dependencies for compiling this module.
# Note: Compiling the WaylandCB source and header will not produce a 
#       WaylandCB.o file because the compiled code is located within 
#       the AnsiCmdApi.o object file.
AnsiCmdApi.o: AnsiCmdApi.cpp $(AC_HFILES) WaylandCB.hpp WaylandCB.cpp 
> $(COMPILE) AnsiCmdApi.cpp

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

AnsiCmdWix.o: AnsiCmdWix.cpp $(AC_HFILES) $(WIN_HFILES)
> $(COMPILE) AnsiCmdWix.cpp

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

AnsiCmdDlg.o: AnsiCmdDlg.cpp $(AC_HFILES)  $(WIN_HFILES)
> $(COMPILE) AnsiCmdDlg.cpp

AnsiCmdAca.o: AnsiCmdAca.cpp $(AC_HFILES)  $(WIN_HFILES)
> $(COMPILE) AnsiCmdAca.cpp

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

#** Build the Library Only **
.PHONY: buildlib
buildlib:
> rm --force $(OFILES) $(AC_OFILES) AnsiCmd.lib epts
> ./report.pl nobump
> $(COMPILE) AnsiCmd.cpp
> $(COMPILE) AnsiCmdWin.cpp
> $(COMPILE) AnsiCmdWix.cpp
> $(COMPILE) AnsiCmdDlg.cpp
> $(COMPILE) AnsiCmdAca.cpp
> $(COMPILE) AnsiCmdApi.cpp
> $(COMPILE) AnsiCmdSkf.cpp
> $(COMPILE) AnsiCmdTest.cpp
> ar -Pcrv AnsiCmd.lib gString.lib $(AC_OFILES)

#** Build gString Library **
.PHONY: gslib
gslib:
> rm --force gString.o gString.lib
> $(COMPILE) gString.cpp
> ar -Pcrv gString.lib gString.o

#** 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
> ./report.pl nobump
> gmake --no-print-directory gslib
> gmake --no-print-directory

#** Remove old object files and the executable for a clean build **
# Note: Does not remove gString object file or library.
.PHONY: clean
clean:
> rm --force $(OFILES) $(AC_OFILES) AnsiCmd.lib epts

