# COPYRIGHT
#
# This file is part of Mustajuuri.
#
# Author: Tommi Ilmonen, 1999-2001.
#
# Mustajuuri is licensed under GNU Lesser General Public License
# (LGPL). The LGPL text can be founs in file "LGPL" that is
# distributed with this source package. The Mustajuuri way to
# interpret LGPL can be found in file "MUSTAJUURI_LICENSE" that is
# distributed with the mustajuuri source code.  
#
#
# Load compile time parameters
#

# Guess a path if it is undefined

ifeq ($(FLUID_ROOT),)
	FLUID_ROOT=$(shell pwd)/..
endif

include $(FLUID_ROOT)/src/Makeconf

DATE=$(shell date '+%d-%m-%Y')

#
# Local variables
#

FLUIDDIRS     = base \
		cbase \
		processors \
		processorlib \
		vrjuggler-export

# Directories that contain headers that need to be available to all

SUPPORTDIRS   = divabase

SUPPORTDIRS2   = smuggler bglproj

MAINDIRS      = $(SUPPORTDIRS) \
		$(FLUIDDIRS) \
		$(SUPPORTDIRS2)



#IRIX Specific:
#ifeq ($(findstring IRIX,$(FLUID_PLATFORM)),IRIX)
#        MAINDIRS += vrjuggler-export
#endif

# DIRS: Libraries and applications in compilation order
DIRS	      =	$(MAINDIRS) \
		plugins \
		examples


default: all

all \
dmain \
smain \
dlib \
slib \
dep \
dependoff \
dependon:;	@for DIR in $(DIRS); \
		 do \
		   $(MAKE) FLUID_ROOT=$(FLUID_ROOT) MODE=$(MODE) -C $$DIR $@; \
		 done

don: dependon


doff: dependoff

clean \
cleaner \
cleanest:;	@for DIR in $(DIRS); \
		 do \
		   $(MAKE) FLUID_ROOT=$(FLUID_ROOT) -C $$DIR $@; \
		 done
		@echo "Removing object files and core ..."
		@-rm -f *.o core
		@echo "Removing emacs backup files ..."
		@-rm -f *~ #*#

yetcleaner: ;
		rm -rf $(FLUID_ROOT)/include/*
		rm -rf $(FLUID_ROOT)/lib/*
		rm -rf $(FLUID_ROOT)/plugins/*
		find $(FLUID_ROOT)/* \( -name "foo" -o -name "foo2" -o -name "*.so" -o -name "*.[ao]" -o -name "[sdk]main" -o -name "Depends" -o -name "*~"  -o -name "*.wav" -o -name "core" -o -name ".nfs*" -o -name "*_moc.C" -o -name "config.log" -o -name "config.cache"  -o -name "*.ii"  -o -name "ii_files" \) -exec rm -rf {} \; ;

dirs:;		@echo "Creating global include and library directories ..."
		-mkdir ../include/$(BASEPLATFORM)
		-mkdir ../lib
		-mkdir ../lib/$(PLATFORM)
		@echo "Creating local library directories ..."
		@for DIR in $(DIRS); \
		 do \
		   $(MAKE) FLUID_ROOT=$(FLUID_ROOT) -C $$DIR $@; \
		 done

# Generate Mustajuuri core API documentation
doc-fluidcore:;	echo "Removing old html files ..."; \
		rm -rf $(FLUID_ROOT)/src/doxygen/html; \
		echo "Running doxygen ..."; \
		$(DOXYGEN) doxygen/doxygen-conf

doc: doc-fluidcore

../include/$(BASEPLATFORM):
		mkdir ../include/$(BASEPLATFORM)

../include/Fluid:
		mkdir ../include/Fluid

incdirs: ../include ../include/$(BASEPLATFORM) ../include/Fluid


# Link stuff from Fluid directories under ../include/Fluid
# Also copy stuff from divabase under ../include

links: incdirs 
		@echo "Creating include links ..."
		 cd ../include/Fluid; \
		 rm *.hpp *.h; \
		ls -al; \
		for DIR in $(FLUIDDIRS); \
		 do \
		  echo "ln -s -f ../../src/$$DIR/*.hpp ."; \
		  ln -s -f ../../src/$$DIR/*.hpp .; \
		  ln -s -f ../../src/$$DIR/*.h .; \
		 done; \
		cd ..; \
		rm *.h; \
		for DIR in $(SUPPORTDIRS) $(SUPPORTDIRS2); \
		 do \
		  pwd; \
		  echo "ln -s -f ../src/$$DIR/*.h ."; \
		  ln -s -f ../src/$$DIR/*.h .; \
		  ln -s -f ../src/$$DIR/*.hpp .; \
		 done
		 cd ..; \


# Create a gzipped tar package (for distribution/backup)
tgz:;
		@echo "Creating tgz package ..."
		cd ../../; ln -sf $(FLUID_ROOT) fluid-$(DATE); \
		tar cvfz fluid-$(DATE).tgz fluid-$(DATE)/* ;\
		rm fluid-$(DATE);
