#:ts=8
#
# $Id: Makefile,v 0.19 1994/01/28 18:51:42 cncl-adm Exp cncl-adm $
#
# Makefile CNCL lib
#
TOPDIR	= ..

include $(TOPDIR)/make.conf



OBJS	= CNCL.o Object.o Class.o Param.o

# Comment if you don't want the UNIX specific classes
UNIXDIR = unix
# Comment if you don't want the ezd interface classes
EZDDIR  = ezd
# Comment if you don't want the fuzzy logic classes
FUZZYDIR= fuzzy

SUBDIRS	= stat container random misc events array\
	  $(UNIXDIR) $(EZDDIR) $(FUZZYDIR)


LIBCNCL	= libcncl.a
LIBCNCLG= libcncl_g.a
LIBCNCLP= libcncl_p.a

objs:	$(OBJS)

all:	objs subdirs lib

subdirs:
	for d in $(SUBDIRS); do \
	  (cd $$d && echo $$d && $(MAKE) all) || exit; \
	done

tests:
	(cd test && $(MAKE) all) || exit
	for d in $(SUBDIRS); do \
	  (cd $$d/test && echo $$d/test && $(MAKE) all) || exit; \
	done

lib:	$(LIBCNCL)

lib_o:
	$(MAKE) all DEBUG="-O6 -Wall" LIBCNCL=$(LIBCNCL)

lib_g:
	$(MAKE) all DEBUG="-g -Wall" LIBCNCL=$(LIBCNCLG)

lib_p:
	$(MAKE) all DEBUG="$(DEBUG) -pg" LIBCNCL=$(LIBCNCLP)

$(LIBCNCL)::
	rm -f $(LIBCNCL)
	ar rv $(LIBCNCL) *.o
	for d in $(SUBDIRS); do (echo $$d; cd $$d; ar rv ../$(LIBCNCL) *.o); done
	ranlib $(LIBCNCL)

clean veryclean templates::
	for d in $(SUBDIRS); do (cd $$d; echo $$d; $(MAKE) $@); done
	for d in $(SUBDIRS); do (cd $$d/test; echo $$d/test; $(MAKE) $@); done
	(cd test; $(MAKE) $@)	

clean-test::
	for d in $(SUBDIRS); do (cd $$d/test; echo $$d/test; $(MAKE) clean); done
	(cd test; $(MAKE) clean)	

clean-lib:
	rm -f libcncl*.a

veryclean::	clean-lib

sub-rcs-ci::
	for d in $(SUBDIRS); do (cd $$d; echo $$d; $(MAKE) $@); done

install:	install-h install-lib install-lib_g install-lib_p

install-h:
	-mkdir $(includedir)/CNCL
	cp *.h $(includedir)/CNCL
	cp Template.hP Template.cP $(includedir)/CNCL
	for d in $(SUBDIRS); do \
	  (cd $$d; echo $$d; $(MAKE) install); \
	done

install-lib:
	if [ -f $(LIBCNCL) ]; then \
		cp $(LIBCNCL) $(libdir); \
		(cd $(libdir); ranlib $(LIBCNCL)); \
	fi

install-lib_g:
	if [ -f $(LIBCNCLG) ]; then \
		cp $(LIBCNCLG) $(libdir); \
		(cd $(libdir); ranlib $(LIBCNCLG)); \
	fi

install-lib_p:
	if [ -f $(LIBCNCLP) ]; then \
		cp $(LIBCNCLP) $(libdir); \
		(cd $(libdir); ranlib $(LIBCNCLP)); \
	fi

# Common stuff
include $(TOPDIR)/make.common

# depend stuff
dep::
	for d in $(SUBDIRS); do (cd $$d; echo $$d; $(MAKE) dep); done
	for d in $(SUBDIRS); do (cd $$d/test; echo $$d/test; $(MAKE) dep); done
	(cd test; $(MAKE) dep)	

depend::
	for d in $(SUBDIRS); do (cd $$d; echo $$d; $(MAKE) depend); done
	for d in $(SUBDIRS); do (cd $$d/test; echo $$d/test; $(MAKE) depend); done
	(cd test; $(MAKE) depend)	
