#*******************************************************************************
# Makefile for gString class, gString link library and test applications.
# 1) To build the 'gs_test' application with the gString link library:
#       Invoke using "gmake"
# 2) To build the 'gsmeter' comprehensive test app:
#    a) In gString.hpp, set the preprocessor directive:
#          #define DEBUG_GSTRING (1)
#    b) Invoke using "gmake gsmeter"
#    c) Reset the preprocessor directive:
#          #define DEBUG_GSTRING (0)
# 3) To remove all object files, library and executables:
#        Invoke using "gmake clean"
#
# Mahlon R. Smith, The Software Samurai
# Tools: GNU G++ / Gcc 13.2.1 or greater
# Note: The build requires support for the C++11 standard (C++13 recommended).
#
# Note: The gString class need not be configured as a library. 
#       The object file can be linked directly into your own application.
# The gString class is also integrated into the NcDialog API library 
# and the AnsiCmd library which are available as separate distribution packages.
# 
# 24-Mar-2025
#*******************************************************************************

.RECIPEPREFIX = >

HFILES  = gString.hpp

COMPILE = g++ -x c++ -std=gnu++11 -Wall -c

#******************************************
#** Build the temporary test application **
#******************************************
gs_test: gs_test.o gString.lib $(HFILES)
> g++ -o gs_test gs_test.o gString.lib

gs_test.o: gs_test.cpp
> $(COMPILE) gs_test.cpp

#** Build the gString-class library      **
> gmake --no-print-directory buildlib

#******************************************
#** Build the 'gsmeter' test application **
#******************************************
.PHONY: gsmeter
gsmeter: gsmeter.o gString.lib
> g++ -o gsmeter gsmeter.o gString.lib

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

#** Build the gString-class library      **
> gmake --no-print-directory buildlib

#**********************************************
#** Build gString Library.                   **
#** NOTE: The DEBUG_GSTRING declaration must **
#** be enabled when building the 'gsmeter',  **
#** and should be disabled (set to 0) for    **
#** all other builds. See report.pl which    **
#** scans for and reports the state of this  **
#** declaration.                             **
#**********************************************
.PHONY: buildlib
buildlib:
> rm --force gString.o gString.lib
> ./report.pl nobump
> $(COMPILE) gString.cpp
> ar -Pcrv gString.lib gString.o

#*******************************************
#** Remove old object files, library  and **
#** the executables for a clean build.    **
#*******************************************
.PHONY: clean
clean:
> rm --force gString.o gs_test.o gsmeter.o gString.lib gs_test gsmeter
