# Makefile for libpasswd
#
# $Author: kinch $
# $Id: Makefile,v 1.14 1995/11/27 18:14:14 kinch Exp kinch $
# $Source: /usr/src/usr.local/security/libpasswd/RCS/Makefile,v $
# $Locker: kinch $
#
# Build and install things in the right places.
#
# Original work August 1994 by Dave Kinchlea <kinch@julian.uwo.ca>
#
#  Copyright (c) 1994 The University of Western Ontario.  All rights
#  reserved.  Redistribution is permitted provided that this notice is
#  preserved and that due credit is given to the authors as well as The
#  University of Western Ontario.
#
#  Start of Configuration Section

SHELL=  	/bin/sh
ENVIRONMENT=	SYSV
OLD=		/uwo/ccs/old
BIN=		/uwo/ccs/lib
PROG=		$(LIB)
MANEXT=		3
MAN=		/uwo/ccs/man/man${MANEXT}
DIRS=		$(MAN) $(BIN)
HDRS= passwd.h passwd-return.h
OBJS= passwd-config.o passwd-crack.o passwd-match.o passwd-return.o
SRCS= passwd-config.c passwd-crack.c 	passwd-match.c passwd-return.c

# This assumes a BSD version of install, use 'make INSTALL=... install' to
# use your version of BSD install. If you don't know how to do that you
INSTALL= /uwo/ccs/share/bin/ucbinstall
OWNER= kinch
GROUP= guru
GET=		co

# When testing I often do 'make FUNCTION= OPTIMIZE=-g' to skip my 
# setuid code and build something I can trace with dbx

FUNCTION= 	-DSETUID
OPTIMIZE=	-O ${FUNCTION}
debug=		0
# End of Global Configuration section.

all:	
	@echo "You must pick a platform, there is NO default"
	@echo "Choose from: $(SYSTEMS)"
	@echo "Or create your own!"

# To get things out of RCS

$(SRCS):;	$(GET) $@

.c.o:
	$(CC) $(CFLAGS) $(OPTIMIZE) -Ddebug=$(debug) -c $*.c -D$(ENVIRONMENT)
# Make the image(s)

# special target for AIX who must do this in two steps
archive: $(LIB)
	rm -f libpass.a
	rm -f $(LIB).`uname -m`
	ar rv libpass.a $(LIB)
	cp libpass.a libpass.a.`uname -m`

$(LIB): $(OBJS) Makefile
	$(LIB_BUILD) $(LIB_BUILD_OPT) $(LIB) $(OBJS) $(LIBS)
	cp $(LIB) $(LIB).`uname -m`
	
# Make some directories

$(DIRS):
	umask 022; mkdir -p $@

# Install things in the right places: 
# Because of the myriad of systems this runs on, and the differing
# ways that shared libraries are dealt with, this install will not
# work `out of the box' -- use the install targets below.
#
#         the program, setuid (remove setuid bit on old executable)
#         the passwd database, readable only by root
#         the man page
# this assumes a ucb compatible install

install: $(DIRS) $(SRCS) 
	cp $(LIB).`uname -m` $(LIB)
	-mv -f $(BIN)/$(LIB) $(OLD)
	$(INSTALL) -c -m 444 -o $(OWNER) -g $(GROUP) $(LIB) $(BIN)
	-mv -f $(MAN)/$(PROG).$(MANEXT) $(OLD)
	$(INSTALL) -c -m 444  -o $(OWNER) -g $(GROUP) $(PROG).man $(MAN)/$(PROG).$(MANEXT)

# And clean up after yourself. Assume *~ are emacs backup files and
#     #*# files are emacs automatic backups.

clean:
	rm -f *.o *.a *.so.1

reallyclean:
	rm -f *.o *.c *.h  TAGS  $(PROG) $(CONFIG) $(CONFIG).in


sunos.install:;	make LIB="libpass.a" install
solaris.install:;	make LIB="libpass.so.1" install
epix.install:;	make LIB="libpass.a" install
irix.install:;	make LIB="libpass.so.1" install
aix.install:;	make LIB="libpass.a" install

# The following are supported enviornments
SYSTEMS=	sunos, solaris, aix, irix, epix
# This seems to work:
# [2:05pm suncon] uname -a
# SunOS suncon.cc 4.1.3_U1 1 sun4c
# [2:05pm suncon] date
# Thu Sep 22 14:05:45 EDT 1994

sunos:
	make ENVIRONMENT=BSD \
	     CC=gcc \
	     CFLAGS="-O -Wall" \
	     OPTIMIZE="$(OPTIMIZE)" debug=$(debug) \
	     LIB="libpass.a"\
	     LIB_BUILD="/usr/5bin/ar" \
	     LIB_BUILD_OPT="r" \
	     LDFLAGS="-static" \
	     libpass.a

# This seems to work:
# [2:21pm falcon] uname -a
# SunOS falcon.ccs.uwo.ca 5.3 Generic_Patch sun4m sparc
# [2:21pm falcon] date
# Thu Sep 22 14:21:53 EDT 1994

solaris:
	make LIB_BUILD=ld \
	     LIB_BUILD_OPT="-G -o" \
	     LIB=libpass.so.1 \
	     CC=gcc \
	     CFLAGS="-Wall -O" \
	     OPTIMIZE="$(OPTIMIZE)" debug=$(debug) \
	     libpass.so.1

# This one works now:
# [1:54pm julian] uname -a 
# julian.uwo.ca julian.uwo.ca 1.4.3 UMIPS mips
# [1:54pm julian] date 
# Mon Oct  3 13:54:37 EDT 1994
#
# NOTE: There is still a problem with ICANNON being
# mistakenly on with the EPIX environment, but 
# this works acceptably well for now.

epix:
	make ENVIRONMENT=BSD \
	     CC=gcc \
	     CFLAGS="-O -Wall" \
	     OPTIMIZE="$(OPTIMIZE)" debug=$(debug) \
	     LIB="libpass.a"\
	     LIB_BUILD="ar" \
	     LIB_BUILD_OPT="rs" \
	     libpass.a
#
#  This seems to work:
# [12:11pm xia] uname -a
# AIX xia 2 3 000065074100
# [12:11pm xia] date
# Tue Oct  4 12:12:01 EDT 1994

aix:
	make ENVIRONMENT=BSD \
	     CC=xlc langlvl=extended \
	     CFLAGS="${CFLAGS} -DNO_PWD_QUOTA \
		     -D__aix__ -D_ALL_SOURCE \
		     -DNO_FGETPWENT" \
	     OPTIMIZE="$(OPTIMIZE)" debug=$(debug) \
	     LIB=libpass.o \
	     LIB_BUILD="ld" \
	     LIB_BUILD_OPT="-bE:libpass.exp -bM:SRE -T512 -H512 -lc -o" \
	     LIBS="-lbsd" \
	     archive
irix:
	make ENVIRONMENT=SYSV \
	     CC=cc \
	     CFLAGS="-xansi ${CFLAGS}" \
	     OPTIMIZE="$(OPTIMIZE)" debug=$(debug) \
	     LIB="libpass.so.1" \
	     LIB_BUILD=ld \
	     LIB_BUILD_OPT="-elf -shared -no_unresolved -o " \
	     LIBS=-lc \
	     libpass.so.1

julian:	solaris
mango:	irix
xia:	aix
panther: epix
suncon:	sunos

# DO NOT DELETE THIS LINE -- make depend depends on it.
passwd-config.o:	passwd-config.c passwd.h
passwd-match.o:		passwd-match.c passwd.h
passwd-crack.o:		passwd-crack.c passwd.h
