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

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


#######
# Root of the installation
topdir=@prefix@
bindir=@bindir@
confdir=@confdir@
scriptdir=@scriptdir@
utildir=@utildir@
docdir=@docdir@
vardir=@vardir@
tmpdir=@tmpdir@
lockdir=@lockdir@

libdir = @libdir@
mandir = @mandir@

#######
# Log infrastructure
logdir = @logdir@
qrylog = @qrylog@
dbuperr = @dbuperr@
allriperr = @allriperr@
ripaudit = @ripaudit@
ripmirlog = @ripmirlog@
ripsvrlog = @ripsvrlog@
sqlog = @sqlog@
ripupdlog = @ripupdlog@
updlog = @updlog@
acklog = @acklog@
notiflog = @notiflog@
forwlog = @forwlog@
crosslog = @crosslog@


BINPROGRAMS = bin/rip/whois_rip bin/dbupdate/dbupdate bin/load/loader utils/whoisd_start

SCRIPTS = bin/load/make_db \
          bin/load/load_all.sh utils/ripe2rpsl \
          utils/whoisd.server

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

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

CONFFILES = conf/rip.config.sample conf/sources.config.sample \
            conf/rip.config.sample.q conf/sources.config.sample.q \
            conf/ack_template conf/ack_text conf/forw_create_template \
            conf/frwd_template conf/frwd_text conf/notif_template \
            conf/notif_text

UTILS = utils/remadmin/remadmin.pl utils/getvar/getvar \
	utils/text_export/text_export utils/mr/mr utils/make_mysql_user

DOCFILES = doc/AUTO-DBM-HELP doc/WHOIS-HELP

SAMPLEDB = bin/load/SAMPLE/sample.db.gz bin/load/SAMPLE/SAMPLE.CURRENTSERIAL


@SET_MAKE@


default: all

all: links libs rip load dbupdate utils

install:
	${mkinstalldirs} ${topdir} ${bindir} ${confdir} \
                         ${scriptdir} ${scriptdir}/SQL \
                         ${docdir} ${vardir} ${tmpdir} ${tmpdir}/load ${tmpdir}/load/SAMPLE ${lockdir} \
                         ${logdir} ${qrylog} ${dbuperr} ${allriperr} ${ripaudit} \
                         ${ripmirlog} ${ripsvrlog} ${sqlog} ${ripupdlog} \
                         ${updlog} ${acklog} ${notiflog} ${forwlog} ${crosslog}
	for p in $(BINPROGRAMS); do \
	 ${INSTALL} -m 0755 $$p ${bindir}; \
	done
	for p in $(SCRIPTS); do \
	 ${INSTALL} -m 0755 $$p ${scriptdir}; \
	done
	for p in $(SQLLOADSCRIPTS); do \
	 ${INSTALL} -m 0755 $$p ${scriptdir}/SQL; \
	done
	for p in $(SQLLOADDATA); do \
	 ${INSTALL} -m 0644 $$p ${scriptdir}/SQL; \
	done
	for p in $(CONFFILES); do \
	 ${INSTALL} -m 0644 $$p ${confdir}; \
	done
	for p in ${DOCFILES}; do  \
	${INSTALL} -m 0644 $$p ${docdir}; \
	done
	for p in ${SAMPLEDB}; do \
	${INSTALL} -m 0644 $$p  ${tmpdir}/load/SAMPLE; \
	done
#install-utils:
	${mkinstalldirs} ${utildir}
	for p in $(UTILS); do \
	 ${INSTALL} -m 0755 $$p ${utildir}; \
	done

upgrade:
	for p in $(BINPROGRAMS); do \
	 ${INSTALL} -m 0755 $$p ${bindir}; \
	done
	for p in $(SQLLOADSCRIPTS); do \
	 ${INSTALL} -m 0755 $$p ${scriptdir}/SQL; \
	done
	for p in $(SQLLOADDATA); do \
	 ${INSTALL} -m 0644 $$p ${scriptdir}/SQL; \
	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 ../..
load:
	cd bin/load; $(MAKE); cd ../..
dbupdate:
	cd bin/dbupdate; $(MAKE); cd ../..

# Utilities - they are not built with "make all"
utils:  text_export getvar mr

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

getvar:
	cd utils/getvar; $(MAKE); cd ../..
        
mr:
	cd utils/mr; $(MAKE); cd ../..


########
# Documentation
GTAGS = /usr/local/bin/gtags
HTAGS = /usr/local/bin/htags -na

docs: 
	${mkinstalldirs} ./doc/cxref
	cd doc;  $(MAKE); cd ..
	${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 aclocal.m4 configure.in configure index.html install-sh mkinstalldirs build.sh README README.freebsd README.linux README.solaris RELEASE-NOTES PRODUCT VERSION bin conf defs design doc include modules utils tests

kit: distclean
	mkdir ${PRODUCT}-${VERSION}
	@(cd ${PRODUCT}-${VERSION}; for i in ${DISTFILES}; do ln -s ../$$i $$i; done)
	gtar -cvzhf ${PRODUCT}-${VERSION}.tar.gz `find ${PRODUCT}-${VERSION} -follow ! -type d | egrep -v -f EXCLFILE`
	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

# 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 utilities
clean_utils: clean_text_export clean_getvar clean_mr

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

clean_getvar:
	cd utils/getvar; $(MAKE) clean; cd ../..

clean_mr:
	cd utils/mr; $(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:
	${RM} Makefile Makefile.site config.status config.cache config.log utils/lnsafe utils/remadmin/remadmin.pl include/config.h

distclean: clean config-clean
