# RIPE Database Software Makefile
#
# Site specific configuration is in Makefile.config
# This file just creates Makefile's and runs make in subdirectories.
#
#	$RCSfile: Makefile,v $
#	$Revision: 2.15 $
#	$Author: chris $
#	$Date: 1997/11/10 11:04:50 $
#
# $Id: Makefile,v 2.15 1997/11/10 11:04:50 chris Exp $
#
# Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999 by 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.
#


SUBDIRS=  doc etc man src

BUILDTOOLSDIR = build-tools

default: all

# Generate Makefiles in the subdirectories by prepending
# Makefile.config (or maybe by prepending an include line)
#
# If you change Makefile.config you'll need to remember to do
# 'make config'. Doing 'make clean' first is a good idea.

.PHONY: config
config: Makefiles buildtools

.PHONY: Makefiles
Makefiles: 
	@for subdir in $(SUBDIRS) $(BUILDTOOLSDIR); do \
	  if [ -d $$subdir ] ; then \
	    [ ! -f $$subdir/Makefile ] || rm -f $$subdir/Makefile; \
	    echo "Creating Makefile in $$subdir"; \
	    { \
	      echo "# $$subdir/Makefile - Auto generated from" \
	           "Makefile.config & $$subdir/Makefile.in" && \
	      echo "# at" `date`        && \
	      echo "#"		      && \
	      cat Makefile.config       && \
	      cat $$subdir/Makefile.in  ; \
	    } >  $$subdir/Makefile && chmod 444 $$subdir/Makefile ; \
	  fi ; \
	done

# treat build tools specially rather than trying to build them as part
# of the build process

.PHONY: buildtools
buildtools:
	    cd $(BUILDTOOLSDIR) && $(MAKE) all

# There isn't a standard way of doing includes in Makefiles
# but you can do something like this if you have GNU make or somesuch
#
#.PHONY: Makefiles
#Makefiles:
#	@for subdir in $(SUBDIRS); do \
#	  echo "Creating Makefile in $$subdir"; \
#	  { echo "include ../Makefile.config >  $$subdir/Makefile && \
#	    cat $$subdir/Makefile.in         >> $$subdir/Makefile || \
#	    exit 1; } \
#	done

# all of the work is done by the Makefiles in the sub-directories

.PHONY: all install uninstall clean 
all install uninstall clean: 
	@for subdir in $(SUBDIRS); do \
	  if [ -d $$subdir  ] ; then \
	    if [ -f $$subdir/Makefile ] ; then \
	      echo "making $@ in $$subdir"; \
	      ( cd $$subdir && $(MAKE) $@ ) ; \
	    else \
	      echo "$$subdir/Makefile does not exist" ; \
	    fi; \
	  fi; \
	done

#
# remove the Makefiles
#
.PHONY: distclean
distclean: clean
	@for subdir in $(SUBDIRS) ; do \
	  if [ -d $$subdir ] ; then \
	    echo "removing Makefile from $$subdir"; \
	    rm -f $$subdir/Makefile ; \
	  fi; \
	done
	@( cd $(BUILDTOOLSDIR) && if test -f Makefile ; then $(MAKE) $@ ; fi )

#
# Create new release
#
# Add a CVS tag and create a tar file
#
# takes version number from Makefile.config
# make sure you update it before making 'dist'
#
# make sure you have checked in all modified files before running this
# use 'make dist-check' to run 'cvs -n update'
#

.PHONY: dist-check
dist-check:
	cvs -n update

# Files that are not included in the distribution
#
NON_DIST_FILES = src/checkreg.pl src/test.pl

.PHONY: dist
dist: distclean
	directory='ripe-dbase-' ; \
	version=`< Makefile.config grep VERSION= | cut -d= -f2` ;\
	cvstag=rel_`echo $$version | tr . _` ; \
	  cvs log -h Makefile.config |grep "$$cvstag: " && \
	    echo Version $$version already exists && \
	    echo update VERSION= line in Makefile.config  && \
	    exit 1 ;\
	  test -d ../$${directory}$${version} && \
	    echo Directory ../$${directory}$${version} already exists. && exit 1;\
	  rm -f $(NON_DIST_FILES) || exit 1; \
	  cvs tag -c $$cvstag || exit 1; \
	  cd .. || exit 1 ;\
	  cvs export -d $${directory}$${version} -r $$cvstag dbase || exit 1 ;\
	  tar cvf - $${directory}$${version} | gzip -9 > $${directory}$${version}.tar.gz


