# Copyright (c) 2000                    RIPE NCC
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of the author not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
# AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


########
# "Parent" Makefile for the package.

SHELL = /bin/sh
VPATH = @srcdir@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = ${exec_prefix}/bin
infodir = ${prefix}/info
libdir = ${prefix}/lib/gnudl
mandir = ${prefix}/man/man1
confdir = ${prefix}/conf
loaderdir = ${prefix}/load
utildir = ${prefix}/utils

PRODUCT = @PRODUCT@
VERSION = @VERSION@
#RIP=`pwd`
INSTALL = @INSTALL@
mkinstalldirs = utils/mkinstalldirs
LN = utils/lnsafe

BINPROGRAMS = bin/rip/rip bin/rip/whois_rip bin/mr/mr bin/rip/ripe2rpsl \
	      bin/dbupdate/dbupdate

LOADPROGRAMS = bin/load/loader bin/load/load_all.sh \
	       bin/load/make_db bin/load/empty_db

SQLLOADSCRIPTS = bin/load/SQL/create.first-stage \
		 bin/load/SQL/create.second-stage \
		 bin/load/SQL/create.third-stage

SQLLOADDATA = bin/load/SQL/aux.index.2 bin/load/SQL/creat.RIPE4.sql \
	      bin/load/SQL/drop.RIPE4.sql bin/load/SQL/create.RIPADMIN.sql \
	      bin/load/SQL/leaf.index.2 bin/load/SQL/main.index.1 

CONFFILES = conf/rip.config.sample conf/sources.config.sample 

UTILS = utils/remadmin/remadmin.pl utils/hs_cleanup/hs_cleanup \
	utils/text_export/text_export utils/whoisRIP/whoisRIP

CONFIG_SUBDIRS = utils/whoisRIP modules/up/src


@SET_MAKE@


default: all

all: links libs rip mr load dbupdate

install:
	${mkinstalldirs} ${bindir} ${confdir} \
	                 ${loaderdir} ${loaderdir}/SQL
	for p in $(BINPROGRAMS); do \
	 ${INSTALL} -m 0755 $$p ${bindir}; \
	done
	for p in $(LOADPROGRAMS); do \
	 ${INSTALL} -m 0755 $$p ${loaderdir}; \
	done
	for p in $(SQLLOADSCRIPTS); do \
	 ${INSTALL} -m 0755 $$p ${loaderdir}/SQL; \
	done
	for p in $(SQLLOADDATA); do \
	 ${INSTALL} -m 0644 $$p ${loaderdir}/SQL; \
	done
	for p in $(CONFFILES); do \
	 ${INSTALL} -m 0644 $$p ${confdir}; \
	done
	${LN} ${bindir}/ripe2rpsl ${loaderdir}/ripe2rpsl

install-utils:
	${mkinstalldirs} ${utildir}
	for p in $(UTILS); do \
	 ${INSTALL} -m 0755 $$p ${utildir}; \
	done


########
# Code: modules and binaries

links:
	cd include; $(MAKE); cd ..
definitions:
	cd defs; $(MAKE); cd ..
libs:
	${mkinstalldirs} lib; cd modules; $(MAKE); cd ..
test:
	cd tests; $(MAKE); cd ..
rip:
	cd bin/rip; $(MAKE); cd ../..
mr:
	cd bin/mr; $(MAKE); cd ../..
load:
	cd bin/load; $(MAKE); cd ../..
dbupdate:
	cd bin/dbupdate; $(MAKE); cd ../..

# Utilities - they are not built with "make all"
utils:  whoisRIP text_export hs_cleanup

whoisRIP:
	cd utils/whoisRIP; $(MAKE); cd ../..

text_export:
	cd utils/text_export; $(MAKE); cd ../..

hs_cleanup:
	cd utils/hs_cleanup; $(MAKE); cd ../..


########
# Documentation

docs: cxref global

# cxref
# The include directories are local to the RIPE NCC; 
# they have to be changed if you want to regenerate the documentation.
INCDIRS = -I./include -I/ncc/dbwork/platforms/sparc-sun-solaris2.7/lib/glib/include -I/opt/package/mysql/include/mysql
DEF = -DHAVE_STRTOK_R
CXREF = /usr/local/bin/cxref ${INCDIRS} ${DEF}
cxref: links clean_cxref
	${mkinstalldirs} ./doc/cxref
	${CXREF} -O ./doc/cxref -N index -verbatim-comments -xref-all -index-all -html32-src ./modules/*/*.c modules/*/*.h ./include/*.h

# global
GTAGS = /usr/local/bin/gtags
HTAGS = /usr/local/bin/htags -na
global: clean_global
	${GTAGS}
	${HTAGS}
	${RM} GPATH GRTAGS GSYMS GTAGS
	${mkinstalldirs} doc
	mv HTML doc/global


########
# Distribution kit

# Files and directories to be included in the kit
DISTFILES = COPYING INSTALL Makefile.in Makefile.site.in configure.in configure install-sh mkinstalldirs build.sh README RELEASE-NOTES PRODUCT VERSION bin conf defs design doc include modules utils

kit: distclean
	mkdir ${PRODUCT}-${VERSION}
	@(cd ${PRODUCT}-${VERSION}; for i in ${DISTFILES}; do ln -s ../$$i $$i; done)
	gtar -c -v -z -h --exclude-from=EXCLFILE -f ${PRODUCT}-${VERSION}.tar.gz ${PRODUCT}-${VERSION}
	rm -rf ${PRODUCT}-${VERSION}

# Release tag
RELEASE_TAG = @RELEASE_TAG@

release_tag: 
	cvs tag ${RELEASE_TAG}
	@echo tagged with ${RELEASE_TAG}

release: docs kit 



########
# Autoconf stuff

#Makefile: Makefile.in config.status
#	./config.status
#config.status: configure
#	./config.status --recheck



########
# Cleaning

clean: clean_include clean_modules clean_libs clean_definitions clean_test clean_rip clean_kit clean_dbupdate clean_load clean_mr

# code
clean_include:
	cd include; $(MAKE) clean; cd ..

clean_modules:
	cd modules; $(MAKE) clean; cd ..

clean_libs:
	$(RM) lib/*.a

clean_definitions:
	cd defs; $(MAKE) clean; cd ..

clean_test:
	if [ -d tests ] ; then cd tests; $(MAKE) clean; cd ..;  fi

clean_rip:
	cd bin/rip; $(MAKE) clean; cd ../..

clean_dbupdate:
	cd bin/dbupdate; $(MAKE) clean; cd ../..

clean_load:
	cd bin/load; $(MAKE) clean; cd ../..

clean_mr:
	cd bin/mr; $(MAKE) clean; cd ../..

# Clean utilities
clean_utils: clean_whoisRIP clean_text_export clean_hs_cleanup

clean_whoisRIP:
	cd utils/whoisRIP; $(MAKE) clean; cd ../..

clean_text_export:
	cd utils/text_export; $(MAKE) clean; cd ../..

clean_hs_cleanup:
	cd utils/hs_cleanup; $(MAKE) clean; cd ../..

# Clean release stuff
clean_kit:
	rm -rf ${PRODUCT}-${VERSION}

clean_release_tag:
	cvs tag -d ${RELEASE_TAG}


# Clean docs

clean_docs: clean_cxref clean_global
	rm -rf doc

clean_global:
	rm -rf doc/global/*/*
	rm -rf doc/global

clean_cxref:
	rm -rf doc/cxref/include/*
	rm -rf doc/cxref

# Autoconf clean

config-clean: confclean-recursive

confclean-recursive: cfg-clean
	for i in $(CONFIG_SUBDIRS); do RIP=`pwd`; cd $$i; $(MAKE) $(MFLAGS) confclean-recursive; cd $$RIP; done

cfg-clean:
	${RM} Makefile Makefile.site config.status config.cache config.log utils/lnsafe utils/remadmin/remadmin.pl include/config.h

distclean: clean config-clean
