# Makefile for Dialog1 and the NcDialog link library
#   Invoke using "gmake"         (build)
#         or     "gmake clean"   (remove old intermediate files)
#         or     "gmake all"     (both 'clean' and 'build)
#         or     "gmake publish" (refresh library and .hpp files for test apps)
# Mahlon R. Smith, The Software Samurai
# Tools: Developed under:
#          G++ / Gcc 3.2.2 for Linux (RedHat 9 ), then
#                    4.4.2 for Linux (Fedora 12), then
#                    4.6.1 for Linux (Fedora 15), then
#                    4.8.0 for Linux (Fedora 16), then
#                    4.8.3 for Linux (Fedora 20), then
#                    5.4.0 for Linux (Ubuntu 16), then
#                    9.2.1 for Linux (Fedora 30), then                
#                   10.2.1 for Linux (Fedora 32), then                
#                   12.3.1 for Linux (Fedora 37), then                
#        Current build  :
#          G++ / Gcc 13.3.1 20240522 (Red Hat 13.3.1-1) for Linux (Fedora 39)                      
# Note: The libraries and applications compiled with this makefile use 
#       functionality defined by the C++11 standard. As such you will need to 
#       use the -std=gnu++11 compile-time switch which became fully supported 
#       in GCC 4.8.1 and higher.
#       Earlier versions of the compiler using other switches that preceeded 
#       the C++11 standard may also work: -std=gnu++0x or -std=c++0x 
#       C++11 support is required for:
#        1) instantiating arrays of initialized class instances
#        2) scoped enums.
#        3) std::chrono
#        4) std::thread
#        5) std::mutex
#        6) various additional functionality
# Note: In future releases, C++17 support (Gcc 8+) may be required, but 
#       those new features are not currently required.
# 21-Mar-2025

OFILES = Dialog1.o 

# Files for NcDialog Library, NcDialog.a
NC_HFILES = GlobalDef.hpp NCurses.hpp NCursesKeyDef.hpp NcWindow.hpp gString.hpp
ND_HFILES = $(NC_HFILES) NcDialog.hpp WaylandCB.hpp
NC_OFILES = NCurses.o NcKey.o NcWindow.o NcwScroll.o NcwKey.o \
            NcDialog.o NcdControl.o \
            NcdControlPB.o NcdControlRB.o NcdControlTB.o \
            NcdControlBB.o NcdControlSB.o NcdControlDD.o \
            NcdControlMW.o NcdControlSE.o NcdControlSP.o \
            NcdControlSL.o NcdKey.o gString.o WaylandCB.o

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

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

#** Build the Dialog1 test application **
Dialog1: Dialog1.o NcDialog.a
> g++ -o Dialog1 $(OFILES) NcDialog.a -lncursesw

Dialog1.o: Dialog1.cpp $(ND_HFILES) DialogAppShared.hpp 
> $(COMPILE) Dialog1.cpp

#** Build the NcDialog link library **
NcDialog.a: $(NC_OFILES)
> ar -Pcrv NcDialog.a $(NC_OFILES)

# NCurses class
NCurses.o: NCurses.cpp $(NC_HFILES)
> $(COMPILE) NCurses.cpp

NcKey.o: NcKey.cpp $(NC_HFILES)
> $(COMPILE) NcKey.cpp

# NcWindow class
NcWindow.o: NcWindow.cpp $(NC_HFILES)
> $(COMPILE) NcWindow.cpp

NcwKey.o: NcwKey.cpp $(NC_HFILES)
> $(COMPILE) NcwKey.cpp

NcwScroll.o: NcwScroll.cpp $(NC_HFILES)
> $(COMPILE) NcwScroll.cpp

# NcDialog class
NcDialog.o: NcDialog.cpp $(ND_HFILES)
> $(COMPILE) NcDialog.cpp

NcdControl.o: NcdControl.cpp $(ND_HFILES)
> $(COMPILE) NcdControl.cpp

NcdControlPB.o: NcdControlPB.cpp $(ND_HFILES)
> $(COMPILE) NcdControlPB.cpp

NcdControlRB.o: NcdControlRB.cpp $(ND_HFILES)
> $(COMPILE) NcdControlRB.cpp

NcdControlTB.o: NcdControlTB.cpp $(ND_HFILES)
> $(COMPILE) NcdControlTB.cpp

NcdControlBB.o: NcdControlBB.cpp $(ND_HFILES)
> $(COMPILE) NcdControlBB.cpp

NcdControlSB.o: NcdControlSB.cpp $(ND_HFILES)
> $(COMPILE) NcdControlSB.cpp

NcdControlDD.o: NcdControlDD.cpp $(ND_HFILES)
> $(COMPILE) NcdControlDD.cpp

NcdControlMW.o: NcdControlMW.cpp $(ND_HFILES)
> $(COMPILE) NcdControlMW.cpp

NcdControlSE.o: NcdControlSE.cpp $(ND_HFILES)
> $(COMPILE) NcdControlSE.cpp

NcdControlSP.o: NcdControlSP.cpp $(ND_HFILES)
> $(COMPILE) NcdControlSP.cpp

NcdControlSL.o: NcdControlSL.cpp $(ND_HFILES)
> $(COMPILE) NcdControlSL.cpp

NcdKey.o: NcdKey.cpp $(ND_HFILES)
> $(COMPILE) NcdKey.cpp

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

# WaylandCB class
WaylandCB.o: WaylandCB.cpp WaylandCB.hpp gString.cpp gString.hpp
> $(COMPILE) WaylandCB.cpp

.PHONY: publish
publish:
> rsync -pogtiu $(ND_HFILES) DialogAppShared.hpp ../Dialog2
> rsync -pogtiu NcDialog.a ../Dialog2
> rsync -pogtiu $(ND_HFILES) DialogAppShared.hpp ../Dialog3
> rsync -pogtiu NcDialog.a ../Dialog3
> rsync -pogtiu $(ND_HFILES) DialogAppShared.hpp ../Dialog4
> rsync -pogtiu NcDialog.a ../Dialog4
> rsync -pogtiu $(ND_HFILES) DialogAppShared.hpp ../Dialogw
> rsync -pogtiu NcDialog.a ../Dialogw
> rsync -pogtiu $(ND_HFILES) gString.cpp WaylandCB.cpp ../Dialogx
> rsync -pogtiu NcDialog.a ../Dialogx
> rsync -pogtiu $(ND_HFILES) ../Keymap
> rsync -pogtiu NcDialog.a ../Keymap
   
#** Build All **
.PHONY: all
all:
> gmake -si clean
> gmake --no-print-directory

#** Remove object files and binary **
.PHONY: clean
clean:
> rm -f $(OFILES) $(NC_OFILES) Dialog1 NcDialog.a 1>/dev/null 2>/dev/null

