#============================================================================= 
#                       Top Level Platform Makefile
#
# This makefile compiles all the sub-projects and demos to produce all the
# executables available on this platform. 
# The main purpose is to descend the project tree and build all the sub-projects
# so that one can invoke 'make' from a single place and be gauranteed that all
# files build and all executable demos build and link, verifying that installation
# and environment are correctly setup.
#
# The build rules are in the file rules.make that is included by all sub-makes
# found in the lower sub-directories.
# The build tools, compiler options and include paths are pulled in from
# rules.make 
#============================================================================= 

include rules.make

# Export all these symbols so recursive makes use these defs too
export


#-----------------------------------------------------------------
# Build all the sub-projects as needed
# the build the demos
#-----------------------------------------------------------------
ifdef PLATFORM_DIR
.PHONY: all
all:
# Build driver and platform modules first
	$(MAKE) -f Makefile  -C ./Utils
	$(MAKE) -f Makefile  -C ./AccessLayer
	$(MAKE) -f Makefile  -C ./Platform
	$(MAKE) -f Makefile  -C ./API
# Build all the demos
#	$(MAKE) -f Makefile  dll         -C ./Applications/JavaGUI/Cpp_DLL
	$(MAKE) -f Makefile  PCIe_menu   -C ./Applications/menu

.PHONY: release
release:
	export CC_OPTS="-O3 -DRELEASE"; $(MAKE) -f Makefile all



#-----------------------------------------------------------------
# Auto build all dependencies in all sub-projects
# Demos don't need dependencies - always rebuild every time
#-----------------------------------------------------------------
.PHONY: depends
depends:
	$(MAKE) -f Makefile depends  -C ./AccessLayer
	$(MAKE) -f Makefile depends  -C ./Utils
	$(MAKE) -f Makefile depends  -C ./Platform
	$(MAKE) -f Makefile depends  -C ./API


#-----------------------------------------------------------------
# Clean C code (but Java) in all sub-projects
#-----------------------------------------------------------------
.PHONY: clean
clean:
	$(MAKE) -f Makefile clean     -C ./AccessLayer
	$(MAKE) -f Makefile clean     -C ./Utils
	$(MAKE) -f Makefile clean     -C ./Platform
	$(MAKE) -f Makefile clean     -C ./API
	$(MAKE) -f Makefile clean     -C ./Applications/menu
	


#-----------------------------------------------------------------
# Clean everything, everywhere, in all sub-projects
# Demos don't need clean - always rebuild every time
#-----------------------------------------------------------------
.PHONY: allclean
allclean:
	$(MAKE) -f Makefile clean     -C ./AccessLayer
	$(MAKE) -f Makefile clean     -C ./Utils
	$(MAKE) -f Makefile clean     -C ./Platform
	$(MAKE) -f Makefile clean     -C ./API
#	$(MAKE) -f Makefile allclean  -C ./Applications/JavaGUI/Cpp_DLL
	$(MAKE) -f Makefile clean     -C ./Applications/menu
	

else
abort:
	echo "ERROR! Environment Variable PLATFORM_DIR not defined."
	exit -1
endif
