##
## $Id: Makefile,v 1.6 1997/06/24 14:24:53 morgan Exp morgan $
##
## $Log: Makefile,v $
## Revision 1.6  1997/06/24 14:24:53  morgan
## update for .55
##
## Revision 1.5  1997/02/24 06:09:59  morgan
## update for .54
##
## Revision 1.4  1997/01/29 03:19:09  morgan
## make -> $(MAKE)
##
## Revision 1.3  1996/12/01 00:56:34  morgan
## update for .52
##
## Revision 1.2  1996/11/10 15:41:30  morgan
## revised for new task
##
## Revision 1.1  1996/07/08 07:10:26  morgan
## Initial revision
##
##

# this should be the name of this directory
RELNAME = SimplePAMApps-0.56

# this is the name of the archive file
DISTFILE = $(RELNAME).tar.gz

# This is where you would indicate you do not want to use libpwdb
# make the following line: WANT_PWDB=no
ifndef WANT_PWDB
WANT_PWDB=yes
endif

# If you want to link the application to a static libpam.a library
# you should un-comment the following:
#
# STATICALLY_LINK=true

# ////////////////////////////////////////////////////
# // You should not modify anything below this line //
# ////////////////////////////////////////////////////

#
# This section is for Andrew to help him compile the binaries
#
WHERE_AM_I=$(shell cd .. ; pwd)
ifeq ($(WHERE_AM_I),/home/morgan/misc/pam)
MY_INCLUDES = -I$(WHERE_AM_I)/Linux-PAM-0.59/include
MY_LIBS = -L$(WHERE_AM_I)/Linux-PAM-0.59/libpam -L$(WHERE_AM_I)/Linux-PAM-0.59/libpam_misc
endif

# the shared libraries for including by applications... 

PAMLIB=$(MY_LIBS) -lpam -lpam_misc 
#-lefence

ifeq ($(WANT_PWDB),no)
# nothing to add
else
PAMLIB+=-lpwdb 
EXTRAS+=-DHAVE_PWDB
endif

CC=gcc
export CC
ifndef COPTFLAGS
COPTFLAGS=-O2
endif
CFLAG=-pipe $(COPTFLAGS) $(EXTRAS) # -ggdb
#DEBUG=-DDEBUG

# memory debugging? ( to work it must be defined here and for compiling
# libpam{,_misc} )
#MEMORY_DEBUG=-DMEMORY_DEBUG
ifdef MEMORY_DEBUG
export MEMORY_DEBUG
endif

# the following is used for linking the executables in apps: this
# ifdef is needed because the libpam functions will then be in the
# executable

ifdef STATICALLY_LINK
RDYNAMIC=-rdynamic
endif

LIBDL=-ldl

#
LOADLIBES = $(PAMLIB) $(RDYNAMIC) $(LIBDL)
export LOADLIBES
#
DIRS = conf apps

WARNINGS = -ansi -D_POSIX_SOURCE -Wall -Wwrite-strings \
        -Wpointer-arith -Wcast-qual -Wcast-align \
        -Wtraditional -Wstrict-prototypes -Wmissing-prototypes \
        -Wnested-externs -Winline -Wshadow -pedantic
# -Wenum-clash

CFLAGS  = -DLINUX $(WARNINGS) $(DEBUG) $(MEMORY_DEBUG) $(CFLAG) $(MY_INCLUDES)
export CFLAGS

all:
	for i in $(DIRS) ; do \
		$(MAKE) -C $$i all ; \
		if [ $$? -ne 0 ]; then break ; fi ; \
	done

install:
	for i in $(DIRS) ; do \
		$(MAKE) -C $$i install ; \
		if [ $$? -ne 0 ]; then break ; fi ; \
	done

sterile:
	@$(MAKE) remove
	@$(MAKE) extraclean

remove:
	for i in $(DIRS) ; do $(MAKE) -C $$i remove ; done

clean:
	rm -f *~ core
	for i in $(DIRS) ; do \
		$(MAKE) -C $$i clean ; \
	done

extraclean:
	for i in $(DIRS) ; do \
		$(MAKE) -C $$i extraclean ; \
	done

check:
	$(MAKE) -C conf check

RCScheck:
	$(MAKE) -C conf RCScheck

# this can be used to see what hasn't been check'd into RCS

open:
	find . \( -type f -a -perm 644 \) -print

release:
	$(MAKE) extraclean
	rm -f .freezemake
	touch .filelist .RCSlist
	chmod 600 .filelist .RCSlist
	cd .. ; find $(RELNAME) \! -type d -print | grep -v RCS | grep -v 'conf/.md5sum' > $(RELNAME)/.filelist
	cd .. ; find $(RELNAME) -type f -print | grep RCS | fgrep -v 'conf/.RCSsum' > $(RELNAME)/.RCSlist
	chmod 400 .filelist .RCSlist
	$(MAKE) check
	$(MAKE) RCScheck
	(cat .filelist ; echo $(RELNAME)/conf/.md5sum) | (cd .. ; tar -cz -f$(DISTFILE) -T-)
	chmod 444 .RCSlist
	(cat .RCSlist ; echo $(RELNAME)/conf/.RCSsum) | (cd .. ; tar -cz -fRCS+$(DISTFILE) -T-)
