##
## $Id: Makefile,v 1.24 1996/07/08 00:07:53 morgan Exp $
##
## $Log: Makefile,v $
## Revision 1.24  1996/07/08 00:07:53  morgan
## updated for .50 added option to compile pam_fail_delay() functionality
##
##

# this should be the name of this directory
RELNAME = Linux-PAM-0.50

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

# Comment out either line to disable that type of linking for *modules only*
# Both at once is a legal configuration!
DYNAMIC=-DPAM_DYNAMIC
export DYNAMIC
#STATIC=-DPAM_STATIC
#export STATIC

# Comment out these lines to disable building dynamic/static libpam.*
DYNAMIC_LIBPAM=yes
export DYNAMIC_LIBPAM
#STATIC_LIBPAM=yes
#export STATIC_LIBPAM

#
# All combinations of the above four variable definitions are legal,
# however, not defining either dynamic or static modules and yet
# creating a some flavor of LIBPAM will make an authentication library
# that always fails!
#

# Uncomment this for the pam_fail_delay() libpam function to be
# activated. There is an example of how it might be used in
# examples/blank.c

EXTRAS= -DPAM_FAIL_DELAY_ON

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

CC=gcc
CFLAG=-O7 -pipe $(EXTRAS) # -ggdb
DEBUG= -g #-DDEBUG
AR=ar -cr
LD=ld
RANLIB=ranlib
LDCONFIG=/sbin/ldconfig

INCLUDEDIR=$(shell pwd)/include

# the shared library for including by applications... [eventutally,
# this should be replaced with an absolute path since there may be
# some security issue involved with respect to LD_LIBRARY_PATH?]  this
# uses the libpam/libpam.so file for compilation but the system
# library for running... So 'make install' before you try it!

PAMLIB=-L$(shell pwd)/libpam -lpam # -lefence

PREFIX=
export PREFIX
SYSINCLUDES=$(PREFIX)/usr/include/security
LIBDIR=$(PREFIX)/usr/lib
SECUREDIR=$(PREFIX)/usr/lib/security

#
# the following is used for linking the executables in examples:
# this ifdef is needed because the functions will be in the executable
#
ifdef DYNAMIC
LIBDL=-ldl
ifdef STATIC_LIBPAM
RDYNAMIC = -rdynamic
endif
endif
#
LOADLIBES = $(PAMLIB) $(RDYNAMIC) \
	-L$(shell pwd)/libpam_misc -lpam_misc \
	$(LIBDL)
export LOADLIBES
#

DIRS = modules libpam conf libpam_misc examples # 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) $(CFLAG) -I$(INCLUDEDIR) -fPIC
export CFLAGS

all: .freezemake
	for i in $(DIRS) ; do \
		make -C $$i all "CC=$(CC)" "AR=$(AR)" \
		"RANLIB=$(RANLIB)" "LIBDIR=$(LIBDIR)" \
		"INCLUDEDIR=$(SYSINCLUDES)" "PAMLIB=$(PAMLIB)" \
		"LDCONFIG=$(LDCONFIG)" ; \
		if [ $$? -ne 0 ]; then break ; fi ; \
	done

.freezemake: Makefile
	touch .freezemake
	@echo "Reminder: did you 'make sterile' first?"
	exit 1

install:
	for i in $(DIRS) ; do \
		make -C $$i install "CC=$(CC)" "AR=$(AR)" \
		"RANLIB=$(RANLIB)" "LIBDIR=$(LIBDIR)" "PAMLIB=$(PAMLIB)" \
		"INCLUDEDIR=$(SYSINCLUDES)" "SECUREDIR=$(SECUREDIR)" \
		"LDCONFIG=$(LDCONFIG)" ; \
		if [ $$? -ne 0 ]; then break ; fi ; \
	done

sterile:
	@make remove
	@make extraclean

remove:
	for i in $(DIRS) ; do \
		make -C $$i remove  "LIBDIR=$(LIBDIR)" \
		"INCLUDEDIR=$(SYSINCLUDES)" "SECUREDIR=$(SECUREDIR)" \
		"LDCONFIG=$(LDCONFIG)" ; \
	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 .filelist .RCSlist .freezemake
	cd .. ; find $(RELNAME) \! -type d -print | grep -v RCS | grep -v 'conf/.md5sum' > $(RELNAME)/.filelist
	chmod 444 .filelist
	@make check
	(cat .filelist ; echo $(RELNAME)/conf/.md5sum) | (cd .. ; tar -cz -f$(DISTFILE) -T-)
	cd .. ; find $(RELNAME) -type f -print | grep RCS | fgrep -v 'conf/.RCSsum' > $(RELNAME)/.RCSlist
	chmod 444 .RCSlist
	@make RCScheck
	(cat .RCSlist ; echo $(RELNAME)/conf/.RCSsum) | (cd .. ; tar -cz -fRCS+$(DISTFILE) -T-)
