# 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.


include VERSION
RIP=`pwd`
INSTALL = /usr/ucb/install -c
mkinstalldirs = utils/mkinstalldirs
LN = utils/lnsafe

prefix = /usr/local/whois_rip
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
libdir = ${exec_prefix}/lib
confdir = ${prefix}/conf
loaderdir = ${prefix}/load

default: all

all: links libs rip mr load dbupdate

install: all
	${mkinstalldirs} ${bindir} ${confdir} \
			 ${loaderdir} ${loaderdir}/SQL
	${INSTALL} 	bin/rip/rip \
			bin/rip/whois_rip \
			bin/mr/mr \
			bin/rip/ripe2rpsl \
			bin/dbupdate/dbupdate \
			${bindir} 
	${INSTALL} 	bin/load/loader \
			bin/load/load1.sh \
			bin/load/load2.sh \
			bin/load/make_db \
			bin/load/empty_db \
			${loaderdir}
	${INSTALL} 	bin/load/SQL/create.first-stage \
			bin/load/SQL/create.second-stage \
			bin/load/SQL/create.third-stage \
			${loaderdir}/SQL
	${INSTALL} -m 644 \
			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 \
			${loaderdir}/SQL
	${INSTALL} -m 644 \
			conf/rip.config.sample \
			conf/sources.config.sample \
			conf/dictionary.txt \
			${confdir}
	${LN} ${confdir}/dictionary.txt ${bindir}/dictionary.txt
	${LN} ${confdir}/dictionary.txt ${loaderdir}/dictionary.txt
	${LN} ${bindir}/ripe2rpsl ${loaderdir}/ripe2rpsl


########
# 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 ../..



########
# 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 Makefile.site Makefile.site.generic README RELEASE-NOTES VERSION bin conf defs design doc include modules utils

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

# Release tag
RELEASE_TAG=V_`cat VERSION | cut -f2 -d'=' | tr -d " .\n"`

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

release: docs kit 



########
# 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:
	cd tests; $(MAKE) clean; cd ..

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_kit:
	rm -rf ripe-dbase-${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

