##
## Makefile for SimplePAMApps
##
## $Id: Makefile,v 1.9 1998/06/13 07:48:34 saw Exp $
##

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

# this is the name of the archive file
DISTFILE = $(RELNAME).tar.gz
CVSDISTFILE = CVS+$(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 //
# ////////////////////////////////////////////////////

TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
PARDIR := $(shell cd ..; if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

#
# This section is for Andrew to help him compile the binaries
#
WHERE_AM_I = $(PARDIR)
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

release: extraclean
	rm -f .freezemake
	touch .filelist
	chmod 600 .filelist
	( \
	  cd ..; \
	  if [ -e '$(PARDIR)/$(RELNAME)' ]; then \
	    [ '$(PARDIR)/$(RELNAME)' != '$(TOPDIR)' ] && exit 1; \
	  else \
	    mv '$(TOPDIR)' '$(PARDIR)/$(RELNAME)'; \
	  fi; \
	  find '$(RELNAME)' -name CVS -prune -o \! -type d \! -path '$(RELNAME)/conf/.md5sum' -print > '$(RELNAME)/.filelist' \
	)
	chmod 400 .filelist
	$(MAKE) check
	(cat .filelist; echo '$(RELNAME)/conf/.md5sum') | (cd ..; tar -cz -f'$(DISTFILE)' -T-)
	(cd ..; tar -cz -f'$(CVSDISTFILE)' -C"`cat '$(RELNAME)/CVS/Root'`" "`basename \"\`cat '$(RELNAME)/CVS/Repository'\`\"`")

.PHONY: all install sterile remove clean extraclean check release
