# Hey Emacs, this Makefile is in -*- text -*- mode!
#
# Makefile --
#	Top-level makefile for Finger.
#
# Copyright (C) 1988,1990 Free Software Foundation, Inc.
# Copyright (C) 1991 International Computer Science Institute, Berkeley, USA.
#
# This file is part of GNU Finger.
# 
# GNU Finger is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 1, or (at your
# option) any later version.
#
# GNU Finger 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Finger; see the file COPYING.  If not, write to the
# Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: Makefile,v 1.28 1994/12/24 20:10:55 stolcke Exp $ ICSI (Berkeley)
#
SHELL = /bin/sh

#if !defined(.PMAKE) || !defined(MAKEOBJDIR)
MAKEOBJDIR = .
#endif

# If your cpp doesn't like -P, just get rid of it.
# The file that you most likely want to look at is ./support/cpp-Makefile.

#
# NOTE: The following conditionals are meaningless to most versions of
# make -- you'll have to fix things my hand.  However, pmake will do the
# right thing.
#
#ifdef SVR4
DEFINES = -DSVR4
#else
DEFINES = 
#endif

#ifdef NeXT
CC = cc -bsd
CPP = $(CC) -traditional -E 
#elifdef sun
CC = gcc -pipe -g $(DEFINES)
CPP = $(CC) -traditional -E
#elifdef sgi
CC = cc -g3 $(DEFINES)
CPP = $(CC) -E -cckr
#elifdef bsdi
CC = cc
CPP = $(CC) -traditional -E 
#else
CC = cc $(DEFINES)
CPP = $(CC) -E
#endif

DIRNAME = /tmp/dirname
EXCLUDE = /tmp/exclude
VERSION = 1.0
ARCHIVE = /usr/local/ftp/stolcke/icsi-finger-$(VERSION).tar.Z

SRC = src/
LIB = lib/
INCLUDES = ../include/
SUPPORT = ./support/
EXECUTABLES = $(SRC)fingerd $(SRC)finger $(SRC)in.fingerd $(SRC)in.cfingerd \
		$(SRC)packet2ascii $(SRC)vifinger
TESTPROGS = $(LIB)any-to-any $(LIB)showxbm $(LIB)showmug $(LIB)mail 
MKFILE = $(MAKEOBJDIR)/Makefile

TARDIRS = doc include lib src support
TOPLEVEL_SUPPORT = Makefile README config.h

CPP_DEFINES = -DHAVE_GCC -DHAVE_FIXED_INCLUDES -DHAVE_BISON 
#MAKE = make

CPPFLAGS = $(SYSTEM) $(CPP_DEFINES)
CPP_ARGS = -DCPP_CC="$(CC)" -DIncludes=$(INCLUDES)

all:	$(SRC)$(MKFILE)
#	(cd $(SRC); $(MAKE) -f $(MKFILE) depend)
	(cd $(SRC); $(MAKE) -f $(MKFILE) $(MFLAGS) all)

tags depend libdepend::	$(SRC)$(MKFILE) FRC
	(cd $(SRC); $(MAKE) -f $(MKFILE) $@)

dirs:	FRC
	(cd $(LIB); $(MAKE) $@)
	test -d $(SRC)$(MAKEOBJDIR) || mkdir $(SRC)$(MAKEOBJDIR)

$(SRC)$(MKFILE): support/cpp-Makefile Makefile config.h
	cp $(SUPPORT)cpp-Makefile $(SRC)tmp-Makefile.c
	(cd $(SRC); $(CPP) $(CPP_ARGS) tmp-Makefile.c \
	| sed 's@[ 	]*$$@@' | uniq >$(MKFILE))
	rm -f $(SRC)tmp-Makefile.c

# Subsequent lines contain targets that are correctly handled by an
# existing src/Makefile.

$(EXECUTABLES): $(SRC)$(MKFILE)
	(cd $(SRC); $(MAKE) -f $(MKFILE) CC="$(CC)" $(MFLAGS) $(@\))

install:
	(cd $(SRC); $(MAKE) -f $(MKFILE) $(MFLAGS) install)

client:
	(cd $(SRC); $(MAKE) -f $(MKFILE) $(MFLAGS) client)

clean:
	rm -f TAGS
	rm -f $(EXECUTABLES)
	rm -f $(EXCLUDE) $(DIRNAME)
	(cd $(SRC); $(MAKE) -f $(MKFILE) clean)
	(cd $(LIB); $(MAKE) clean)
	(cd include; rm -f fingerpaths.h)
	(cd doc; $(MAKE) clean)

dist:
	rm -f $(DIRNAME) $(EXCLUDE)
	$(MAKE) $(MFLAGS) \
		VERSION=`awk -f $(SUPPORT)version.awk patchlevel.h` dodist

beta:
	rm -f $(DIRNAME) $(EXCLUDE)
	$(MAKE) $(MFLAGS) \
		VERSION=`awk -f $(SUPPORT)version.awk patchlevel.h`beta dodist

dodist: $(ARCHIVE)

check-dist:
	uncompress < $(ARCHIVE) | tar tvf - 

$(DIRNAME):
	basename `pwd` > $@

$(EXCLUDE): $(DIRNAME) $(SUPPORT)/VERSION Makefile
	(cd ..; find `cat $(DIRNAME)` \
		\( -type d -name \*.md -o -name fingerpaths.h \
		   -o -name \*.o -o -name \*.a  -o -name \*.bak -o -name RCS \
		   -o -name '*.[1-8]' -o -name version -o -name LOCK.make \
		   -o -name FTPLOG \) \
		-print ) \
		> $(EXCLUDE)
	for f in $(EXECUTABLES) $(TESTPROGS); do \
		echo `cat $(DIRNAME)`/$$f >> $(EXCLUDE) ; \
	done
	echo `cat $(DIRNAME)`/src/Makefile >> $(EXCLUDE)
	echo `cat $(DIRNAME)`/$(ARCHIVE) >> $(EXCLUDE)

$(ARCHIVE): $(DIRNAME) $(EXCLUDE)
	(cd ..; tar cofX - $(EXCLUDE) `cat $(DIRNAME)`) | compress > $@

tags::
	etags */*.c */*/*.c */*.h >TAGS

FRC:
