#
#         Top level Makefile for building the DICT-OBJ-FILE production
#         construction applications and all supporting libraries.
#
#

SHELL=/bin/sh
MAKE=make

MAKEFILE=Makefile
DIRS = bin include lib
FILES = Makefile README
ETCFILES = platform.sh initlib.sh cifinstall LICENSE \
           make.platform.gnu2 make.platform.gnu3 make.platform.gnu4 \
           make.platform.darwin2 make.platform.darwin3 make.platform.darwin4 \
           make.platform.osf make.platform.sgi6 make.platform.sunos5 \
           make.platform.cygwin

VERFILE = ./local/VERSION

CHECKOUT_SCRIPT_MODULE = util
CHECKOUT_SCRIPT = checkout.sh

LIBDIRS = common-v4.5 \
          tables-v8.0 \
          regex-v2.2 \
          cif-file-v1.0 \
          misclib-v2.2 \
          cifparse-obj-v7.0 \
          dict-obj-file-v8.0

all:	compile 

build:  checkout compile

doc:
	@sh -c 'cd ./etc; ./createdoc.sh'

testall:   test

test:   compile
	cd dict-obj-file-v8.0; $(MAKE) -f $(MAKEFILE) test

#	
checkout:
	@echo -------- Getting module checkout script --------
	@echo 
	@cvs co $(CHECKOUT_SCRIPT_MODULE)/$(CHECKOUT_SCRIPT)
	@sh -c 'cd ./$(CHECKOUT_SCRIPT_MODULE); ./$(CHECKOUT_SCRIPT)'

update:
	@for libdir in $(LIBDIRS); do \
		echo updating $$libdir; \
		(cd $$libdir && cvs update) || exit 1; \
	done
#
compile:
	@sh -c 'cd ./etc; ./platform.sh'
	@for libdir in $(LIBDIRS); do \
		echo " "; \
		echo "------------------------------------------------------------"; \
		echo "**** Making $$libdir ****"; \
		echo "------------------------------------------------------------"; \
		(cd $$libdir && $(MAKE) -f $(MAKEFILE)  "OPT=-O" install) || exit 1; \
	done

debug:
	@sh -c 'cd ./etc; ./platform.sh'
	for libdir in $(LIBDIRS); do \
		echo " "; \
		echo "------------------------------------------------------------"; \
		echo "**** Making (debug) $$libdir ****"; \
		echo "------------------------------------------------------------"; \
		(cd $$libdir && $(MAKE) -f $(MAKEFILE) "OPT=-g" install) || exit 1; \
	done
#
commit:
	@for libdir in $(LIBDIRS); do \
		echo commiting changes in $$libdir; \
		(cd $$libdir && cvs commit) || exit 1; \
	done
#
libclean:
	@echo "Cleaning project directory"
#	@(rm -rf ./lib/[ABD-Za-z0-9]*)
#	@(rm -rf ./lib/*.a)
#	@(rm -rf ./include/[ABD-Za-z0-9]*)
#	@(rm -rf ./include/*.h)
#	@(rm -rf ./bin/[ABD-Za-z0-9]*)
#
distclean:   
	@for libdir in $(LIBDIRS); do \
		echo removing $$libdir; \
		(rm -rf $$libdir) || exit 1; \
	done
#
clean:  libclean
	@for libdir in $(LIBDIRS); do \
		echo cleaning $$libdir; \
		(cd $$libdir && $(MAKE) -f $(MAKEFILE) clean) || exit 1; \
	done
#

clean_doc:
	@rm -rf docs;

clean_build:
	@for libdir in $(LIBDIRS); do \
		echo cleaning $$libdir; \
		(cd $$libdir && $(MAKE) -f $(MAKEFILE) clean_build) || exit 1; \
	done
#

clean_test:
	(cd dict-obj-file-v8.0 && $(MAKE) -f $(MAKEFILE) clean_test) || exit 1;
#


export: clean
	@mkdir -p ../Exported

	@cp -r $(DIRS) ../Exported
	@cp  $(FILES) ../Exported

	@cd ../Exported;mkdir -p etc
	@cd etc; cp $(ETCFILES) ../../Exported/etc
	@cd ../Exported/etc; cat make.platform.gnu3 | grep -v "^WARNINGS_AS_ERRORS" > make.platform.gnu3 
	@cd ../Exported/etc; cat make.platform.gnu4 | grep -v "^WARNINGS_AS_ERRORS" > make.platform.gnu4 
	@cd ../Exported/etc; cat make.platform.darwin3 | grep -v "^WARNINGS_AS_ERRORS" > make.platform.darwin3 
	@cd ../Exported/etc; cat make.platform.darwin4 | grep -v "^WARNINGS_AS_ERRORS" > make.platform.darwin4 
	@cd ../Exported/etc; cat make.platform.sunos5 | grep -v "^WARNINGS_AS_ERRORS" > make.platform.sunos5
	@cd ../Exported/etc; cat make.platform.cygwin | grep -v "^WARNINGS_AS_ERRORS" > make.platform.cygwin

	@cp $(VERFILE) ../Exported

	@for libdir in $(LIBDIRS); do \
		echo exporting $$libdir; \
		(cd $$libdir && $(MAKE) -f $(MAKEFILE) export) || exit 1; \
		mv $$libdir/export_dir ../Exported/$$libdir; \
	done

	@rm -rf ../Exported/bin/*;

	@perl ./etc/exportPackage.pl $(VERFILE) ../Exported

