
#
# Pablo System: Visual/Src/System/Build/Makefile
# 
# The default target "all" is set before we include Makefile.common so
# that we don't pick up the target defined in that file.
#		
#
MYTOP := .

.PHONY : Makefile Makefile.common all # explicitly mark PHONY to save time

all : Pablo  

#
# Definitions:
#   LOCAL_FLAGS: flags added to C++FLAGS; these are also exported to submakes
#   OBJECTS_ARCHIVE: The name of our master archive which is used if
#	$(LD_RELOC) isn't defined in Makefile.defines.  This also gets
#	exported to any submakes.
#   SUBDIRS: Subdirectories where we also run make
#   Makefile.common: contains definitions which are also used by subdirectories
#   $(TOP)/Makefile.defines (included by Makefile.common): contains the Pablo 
#	configuration parameters.
#   $(TOP)/MakeRules/local.implicit.rules (included by Makefile.common): cancels
#       the predefined rules and defines ones used in the Pablo system.
#   AUDIO_LIBS: libraries we need if using audio portion
#   LIBS:  libraries we link with
#   LD_OBJECTS: Object files for the subdirs - either in archive or *.o format
#	depending on value of LD_RELOC.
#   

#export LOCAL_FLAGS = -g
export OBJECTS_ARCHIVE = $(MYTOP)/Objects.a

SUBDIRS := Analysis \
           Base \
           Descriptors \
           Dictionaries \
           FUConfig \
           FunctionalUnits \
           Interface \
           Iterators \
           Managers \
           Pipes \
           Primitives \
           UsefulClasses \
           Wrapper \
           XInterface 

include Makefile.common	             

ifeq ($(strip $(USE_AUDIO)),yes)
AUDIO_LIBS := $(TOP)/Visual/Src/Audio/Build/Clients/libSonify.a \
	      $(WCL_LIBDIR) -lWc -lXmp
endif

LIBS       := $(MOTIF_LIBDIR) \
	      $(X11_LIBDIR) \
	      $(AUDIO_LIBS) \
	      $(XPM_LIB) \
              $(TOP)/Visual/Src/Widgets/Build/libPerfWidgets.a \
	      $(TOP)/Visual/Src/Motif/Build/libMotif.a \
	      -lXm -lXaw -lXt -lXmu -lXext -lX11 -lm $(XTRA_LIBS)

ifneq ($(strip $(LD_RELOC)),)
LD_OBJECTS := $(foreach dir,$(SUBDIRS),$(dir)/Objects.o) 
else
LD_OBJECTS := $(OBJECTS_ARCHIVE)
endif

# 
# Pablo target:  
#   	Mark appropriate targets as PHONY to force rebuild.
#	Order of dependencies for Pablo target shouldn't be changed because 
#	  of archive updates.
#	If $(LD_RELOC) is defined (usually done in Makefile.defines), then
#	  we use it to build individual $(SUBDIRS)/Objects.o files which are
#	  used in the final link.  If it isn't defined, then we use our
#	  'master archive' $(OBJECTS_ARCHIVE) instead and the RmLibrary and
#	  RandomLibrary targets actually do something.  The subdirectory makes
#	  update $(OBJECTS_ARCHIVE)
#
.PHONY : Pablo rmLibrary subDirs randomLibrary executable

Pablo: PabloOptions.o rmLibrary subDirs randomLibrary executable

rmLibrary:
ifeq ($(strip $(LD_RELOC)),)
	rm -f $(OBJECTS_ARCHIVE)
endif

subDirs:
	for dir in $(SUBDIRS); do \
	    ( $(MAKE) -C $$dir ) || exit $$?; \
	done

randomLibrary:
ifeq ($(strip $(LD_RELOC)),)
	$(RANLIB) $(OBJECTS_ARCHIVE)
endif

executable:
	$(C++) -o Pablo $(LOCAL_FLAGS) $(CNFG_C++LDFLAGS) $(CNFG_C++FLAGS) \
		PabloOptions.o $(LD_OBJECTS) \
		$(LIBS)

#
# PabloOptions.o -- we explicitly have a line for the dependencies in 
# the Makefile so that we don't have to include a *.dep that may not exist
# even when we do our "clean" target.  The rules for building this .o and .c
# are defined explicitly here. Rules for PabloOptions.def and makeOptions.perl 
# are also stated explicitly to avoid searching implicit rules for the targets.
#
PabloOptions.o : PabloOptions.C ../Includes/CString.h \
		 ../Includes/Obj.h ../Includes/Assert.h \
		 ../Includes/Defines.h 

PabloOptions.C: ./PabloOptions.def ../Scripts/makeOptions.perl
	$(PERL) ../Scripts/makeOptions.perl ./PabloOptions.def > PabloOptions.C

PabloOptions.def            : ;
../Scripts/makeOptions.perl : ;

#
# Targets install and clean
#
.PHONY : install clean test

install : Pablo
	$(MAKEDIRHIER) $(PABLOBIN) 
	install -c -m 755 Pablo $(PABLOBIN) 
	../Scripts/makerunscript $(PABLOBIN) $(PABLOAPPDEFAULTS) $(SOUNDDIR)

clean : 
	for dir in $(SUBDIRS); do \
	    echo; echo Making Clean in $$dir; \
	    (cd $$dir; makeClean) || exit $$?; \
	done
	rm -f Pablo *.a *.o *.dep PabloOptions.C *.bak core
