#
# Pablo System: SDDFlibrary/Pablo/Build/Makefile
#
TOP := ../..

.PHONY : Makefile $(TOP)/Makefile.defines   # explicitly mark PHONY to save time
include $(TOP)/Makefile.defines		    # Pablo configuration parameters

#
# Some definitions for this particular Makefile
#   LOCAL_FLAGS : flags added to C++FLAGS and CFLAGS
#   CREATELIB   : name of library to build (with duplicate member names)
#   INCLUDES    : -I format for include directories
#   SRCDIRS     : source file directories
#   SRCFILES    : list of sources with paths
#   SOURCES     : sources without paths
#   OBJECTS     : objects for all sources (no paths)
#   DEPFILES    : dependency files for all objects
#   C++FLAGS    : c++ build flags 
#   CFLAGS      : c build flags 
#
LOCAL_FLAGS := -DASSERT
CREATELIB   := libPablo.a		    
INCLUDES    := -I../Includes
SRCDIRS     := $(wildcard ../Source/*)	    
SRCFILES    := $(wildcard ../Source/*/*.C)  
SOURCES	    := $(notdir $(SRCFILES))	    
OBJECTS	    := $(SOURCES:.C=.o)	            
DEPFILES    := $(OBJECTS:.o=.dep)	    
C++FLAGS    := $(LOCAL_FLAGS) $(CNFG_C++FLAGS) $(INCLUDES) 
CFLAGS      := $(LOCAL_FLAGS) $(CNFG_CFLAGS) $(INCLUDES)

vpath %.C   $(shell echo $(SRCDIRS) | sed 's/ /:/g')

#
# Default target is all (the library libPablo.a)
#
.PHONY : all

all:   $(CREATELIB) 

#
# The object file "DataCharacteristics.o" is not built from the default
# implicit rule because we need the extra endian definition for it.
# Don't expand XTRA_DEFINES until it's used so that EndianDefinition can
# be make.
#
XTRA_DEFINES = $(shell cat EndianDefinition) 

DataCharacteristics.o: DataCharacteristics.C EndianDefinition
	$(C++) $(C++FLAGS) $(XTRA_DEFINES) -c $<

ifdef TARGET_ENDIAN
EndianDefinition: endian.sh
	$(SHELL) endian.sh > EndianDefinition

endian.sh:
	echo "echo -D$(TARGET_ENDIAN)" > endian.sh 
	     
else
EndianDefinition: determineEndian
	determineEndian > EndianDefinition
endif

#
# Files containing dependencies for all the objects listed in $OBJECTS
#
include $(DEPFILES)

#
# Pablo implicit rules (cancels all predefined rules)
#
.PHONY : $(TOP)/MakeRules/local.implicit.rules 
include $(TOP)/MakeRules/local.implicit.rules

