##############################################################################
#                                                                            #
# @FILE@: put_a_description_here
#                                                                            #
# Toplevel makefile for @PROJECTNAME@
#                                                                            #
# Adjust at will                                                             #
#                                                                            #
##############################################################################
#                                                                            #
# (C)Copyright 1995-1997 Ripley Software Development                         #
# All Rights Reserved                                                        #
#                                                                            #
# @PROJECT@
#                                                                            #
# This @APPTYPE@ is free software; you can redistribute it and/or              #
# modify it under the terms of the GNU @LICTYPE@ General Public                #
# License as published by the Free Software Foundation; either               #
# version 2 of the License, or (at your option) any later version.           #
#                                                                            #
# This @APPTYPE@ is distributed in the hope that it will be useful,            #
# but WITHOUT ANY WARRANTY; without even the implied warranty of             #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          #
# @LICTYPE@ General Public License for more details.                           #
#                                                                            #
# You should have received a copy of the GNU @LICTYPE@ General Public          #
# License along with this @APPTYPE@; if not, write to the Free                 #
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         #
##############################################################################
#
# The defaults in this Makefile are for linux

# Name of this @APPTYPE@
TARGET=@PROJECTNAME@

# List of subdirectories to visit
SUBDIRS=src examples

# some common definitions
#
CP    = cp
RM    = rm -f
MV    = mv
LN    = ln -sf

# for building a library. 
AR    = ar cq 
# replace with echo or /bin/true if you system doesn't have/need ranlib
RANLIB= ranlib

SHELL     = /bin/sh
MAKE      = make 
# change this to makedepend if your system doesn't have gcc
MAKEDEPEND= gccmakedep

#####################
#                   #
# Compiler Settings #
#                   #
#####################
CC       = gcc
CFLAGS   = -g -funroll-loops -Wall -pipe -ansi 
LDFLAGS  = 

# It might be troublesome to know what the correct defines are for your
# system. A possible set of defines for some OS's is given below. Pick
# your choice.
#
# HPUX:
# 	-D_HPUX_SOURCE -D_POSIX_SOURCE
#
# Linux:
#	-D_BSD_SOURCE -D_GNU_SOURCE -D_POSIX_SOURCE
#
# AIX 4.1.5:
#	-DHAVE_STRINGS_H
#
#	(AIX 4.1.5 has str[n]casecmp, but it's defined in strings.h)
#
# Unixware 1.1.2
#	-DNEED_STRCASECMP -DNEED_STRERROR -DSVR4 -DHAVE_MEMCPY
#
# Unixware 2.1.1
#	-DNEED_STRCASECMP -D_POSIX_SOURCE
#
# LynxOS
#	-DNEED_STRCASECMP
#
# SCO 3.2
#	-DNEED_STRCASECMP -D_POSIX_SOURCE
#
# If you have dmalloc, you might wish to add -DDMALLOC
#
# If your system does not have str[n]casecmp, add -DNEED_STRCASECMP (unixware)
# If your system does not have strerror, add -DNEED_STRERROR
#
# Add -DDEBUG to enable selective debug output (see the file DEBUGGING for more
# info).
#
CPPFLAGS = -DDEBUG -D_GNU_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE

#######################
#                     #
# Include Directories #
#                     #
#######################

# Project includes
PRJINC= -I. -I../include

# X11 includes
X11INC= -I/usr/X11R6/include

# Motif includes
XMINC= -I/usr/X11R6/include

# If using dmalloc, add the path where the dmalloc.h include file can be 
# found. On my system it's in /usr/local/include
DMALLOCINC=-I/usr/local/include

# Additional includes
EXTRAINC=

#######################
#                     #
# Library Directories #
#                     #
#######################

# Project libraries
PRJLIB=

# X11 Libraries
X11LIB= -L/usr/X11R6/lib -lXpm -lXmu -lXt -lXext -lX11 -lSM -lICE

# Motif Libraries
XMLIB= -L/usr/X11R6/lib -lXm

# dmalloc Libraries
DMALLOCLIB=

# Additional Libraries
EXTRALIB=

########################################
###                                  ###
### End of User configurable section ###
###                                  ###
########################################

# Final list of include directories
INCLUDES = $(PRJINC) $(X11INC) $(XMINC) $(DMALLOCINC) $(EXTRAINC)

# Final list of libraries
LOADLIBES= $(PRJLIB) $(XMLIB) $(X11LIB) $(DMALLOCLIB) $(EXTRALIB)

# Flags to pass to the various subdirectories
pass_flags = SHELL='$(SHELL)' \
	VERSION='$(VERSION)' \
	CC='$(CC)' \
	RM='$(RM)' \
	AR='$(AR)' \
	MV='$(MV)' \
	CP='$(CP)' \
	LN='$(LN)' \
	RANLIB='$(RANLIB)' \
	MAKEDEPEND='$(MAKEDEPEND)' \
	CFLAGS='$(CFLAGS)' \
	LDFLAGS='$(LDFLAGS)' \
	CPPFLAGS='$(CPPFLAGS)' \
	INCLUDES='$(INCLUDES)' \
	LOADLIBES='$(LOADLIBES)'

include_flags = SHELL='$(SHELL)' \
	RM='$(RM)' \
	LN='$(LN)'

#######################
###                 ###
### Targets to make ###
###                 ###
#######################

all:: includes

all::
	@( for dir in $(SUBDIRS) ; do \
		(set -x ; cd $$dir ; $(MAKE) all $(pass_flags) ) ; \
	done)

# Separate rules for all targets 
src: includes
	@(set -x; cd src; $(MAKE) all $(pass_flags) )

examples: includes
	@(set -x; cd src; $(MAKE) all $(pass_flags) )
	@(set -x; cd examples; $(MAKE) all $(pass_flags) )

tools: includes
	@(set -x; cd tools; $(MAKE) all $(pass_flags) )

# Global target for building everything
World:
	$(MAKE) clean
	$(MAKE) includes
	$(MAKE) depend
	$(MAKE) src
	$(MAKE) examples

# All public headers files are placed in ./include/@PROJECTNAME@

stamp-includes:
	@if [ -d include ]; then set +x; \
	else (set -x; mkdir include); fi
	@if [ -d include/@PROJECTNAME@ ]; then set +x; \
	else (set -x; mkdir include/@PROJECTNAME@); fi
	@(set -x ; for dir in $(SUBDIRS); do \
		(cd $$dir; $(MAKE) includes $(include_flags) ) ; \
		done)
	touch $@

includes:: stamp-includes

depend:: 
	@( for dir in $(SUBDIRS) ; do \
		(set -x ; cd $$dir ; $(MAKE) depend $(pass_flags)) ; \
	done)

clean:: 
	@( for dir in $(SUBDIRS) ; do \
		(set -x ; cd $$dir ; $(MAKE) clean $(pass_flags) ) ; \
	done)

distclean:: 
	@( for dir in $(SUBDIRS) ; do \
		(set -x ; cd $$dir ; $(MAKE) distclean $(pass_flags) ) ; \
	done)
	$(RM) stamp-includes
	$(RM) docs/sources.desc
	$(RM) -r ./include
	$(RM) core *.out *.log make.world *.bak *.last *.auto *.rej *.orig
	$(CP) Makefile.org Makefile

dist:: distclean
	$(LN) . $(TARGET)-$(ARCHIVE)
	tar cvf - $(TARGET)-$(ARCHIVE)/* | gzip -c > $(TARGET)-$(ARCHIVE).tar.gz

docs::
	tools/scansrc.sh ./src > docs/sources.desc

