CDEVSRC = $(shell pwd)
CDEVINC = $(CDEVSRC)/../include

ifneq ("$(VERBOSE)", "YES")
	MAKE := $(MAKE) -s VERBOSE=NO
endif

DIRS =  $(CDEVSRC)/callback \
	$(CDEVSRC)/cdevIO \
	$(CDEVSRC)/common \
	$(CDEVSRC)/directory \
	$(CDEVSRC)/collection \
	$(CDEVSRC)/group \
	$(CDEVSRC)/system \
	$(CDEVSRC)/device \
	$(CDEVSRC)/regexp \
	$(CDEVSRC)/c_interface \
	$(CDEVSRC)/ca

# add your own service directory or comment ca
#	$(CDEVSRC)/skeleton
#	$(CDEVSRC)/ca

BINDIRS = $(CDEVSRC)/utility
LIBDIRS = $(CDEVSRC)/lib

default:
	@echo "Type one of the following:"
	@echo "	make hpux		for HP systems"
	@echo "	make hpux-sl		for HP systems building shared library"
	@echo "	make hpux-cl		for HP systems with CenterLine"
	@echo "	make hpux-cl-sl		for HP systems with CenterLine Building shared library"
	@echo "	make irix5		for SGI running irix5"
	@echo "	make irix5-sl		for SGI running irix5 building shared library"
	@echo "	make sunos4-gcc		for SunOs 4.x and gcc"
	@echo "	make sunos4-gcc-sl	for SunOs 4.x and gcc building shared library"
	@echo "	make solaris		for Solaris2.x"	
	@echo "	make solaris-sl		for Solaris2.x and building shared library"
	@echo "	make solaris-gcc	for Solaris2.x and gcc"
	@echo "	make solaris-gcc-sl	for Solaris2.x and gcc building shared library"
	@echo "	make ultrix-gcc	for 	ultrix 4.x and gcc"
	@echo "	make aix	for 	IBM AIX 4.x"
	@echo "	make linux-sl   for     linux shared library"
	@echo "	make linux      for     linux archived library"	
	@echo "	make clean"

hpux hpux-sl hpux-cl hpux-cl-sl irix5 irix5-sl sunos4-gcc sunos4-gcc-sl solaris solaris-sl solaris-gcc solaris-gcc-sl ultrix-gcc aix linux-sl linux: 
	@echo "---------------------------------------------------------------"
	@echo "Building CDEV Libraries for Target : $@"
	@echo "---------------------------------------------------------------"
	@mkdir -p $(CDEVINC)
	@mkdir -p ../lib/$(TARGETDIR)
	@mkdir -p ./lib/.obj
	@mkdir -p ./lib/.shobj
	@for dir in $(DIRS) $(LIBDIRS) $(BINDIRS); \
	do \
		echo "=> Compiling directory $$dir"; \
		$(MAKE) -C $$dir ARCH=$@ $@; \
		echo "<= Done...\n"; \
	done
	@echo "---------------------------------------------------------------"
	@echo "CDEV Libraries Have Been Built for Target : $@"
	@echo "---------------------------------------------------------------"

clean:
	@echo "=> Cleaning source directories..."
	@for dir in $(DIRS); \
	do \
		$(MAKE) -C $$dir ARCH=common clean; \
		echo "      Done..."; \
	done
	@echo "<= Done...\n"
	@echo "=> Cleaning library directories"	
	@for dir in $(LIBDIRS); \
	do \
		cd $$dir; \
		rm -rf *.o *.a *.sl *.so .shobj .obj; \
		cd $(CDEVSRC); \
	done
	@echo "<= Done...\n"
	@for dir in $(BINDIRS); \
	do \
		$(MAKE) -C $$dir ARCH=common purge; \
	done

purge: clean
	@echo "=>Purging binary directories..."
	@rm -rf ../bin
	@rm -rf ../lib
	@rm -f ../include/*.h ../include/*.i
	@echo "<= Done...\n"
