#
# Copyright (c) 1988 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by the University of California, Berkeley.  The name of the
# University may not be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#	@(#)Makefile	5.11 (Berkeley) 1/3/89
#	@(#)$Id: Makefile,v 1.40 1992/10/05 03:34:45 paul Exp paul $
#
HDRS=	conf.h mailstats.h sendmail.h useful.h flock.h def.h
SRCS=	alias.c arpadate.c clock.c collect.c conf.c convtime.c daemon.c \
	deliver.c domain.c envelope.c err.c getloadavg.c headers.c \
	initgroups.c macro.c main.c malloc.c parseaddr.c queue.c readcf.c \
	recipient.c savemail.c srvrsmtp.c stab.c stats.c sysexits.c trace.c \
	usersmtp.c util.c ../ida/charset/strcnv.c flock.c syslog.c \
	vprintf.c version.c
OBJS=	alias.o arpadate.o clock.o collect.o conf.o convtime.o daemon.o \
	deliver.o domain.o envelope.o err.o getloadavg.o headers.o \
	initgroups.o macro.o main.o malloc.o parseaddr.o queue.o readcf.o \
	recipient.o savemail.o srvrsmtp.o stab.o stats.o sysexits.o trace.o \
	usersmtp.o util.o strcnv.o flock.o syslog.o vprintf.o \
	version.o
CONFIGS = \
	config/3b1.h      config/esix.h     config/s5r4.h \
	config/aix3.h     config/hpux7.h    config/sco.h \
	config/aixrt.h    config/hpux8.h    config/sunos3.h \
	config/bsd42.h    config/irix.h     config/sunos4.h \
	config/bsd43.h    config/isc.h      config/sunos5.h \
	config/bsd44.h    config/newsos5.h  config/ultrix3.h \
	config/convex.h   config/next.h     config/ultrix4.h \
	config/dgux.h     config/osx.h      config/umax.h \
	config/domainos.h config/proto.h    config/unisoft.h \
	config/dynix.h    config/ptx.h      config/usg.h \
	config/epix.h     config/riscos.h

MAN=	sendmail.0 newaliases.0 aliases.0
MACROS=	-mandoc
#MACROS=	-man

SHELL=	/bin/sh

# Reasonable defaults.  A CPU type must usually be specified with ANSI C
# compilers in order to select the correct byte-ordering in <arpa/nameser.h>
# and to use the right getloadavg() routine.  IT'S LIKELY THAT THE -Dvax
# BELOW WILL BE WRONG FOR YOUR MACHINE.
CC=	cc -O
#CC=	gcc -Dvax -ansi -fpcc-struct-return -g
DEFS=	
CFLAGS=	${DEFS} -I. 
LDFLAGS= 

# Choose the dbm library based on the setting in conf.h.
# GDBM: -lndbm, SDBM: -lsdbm, HDBM: -lhash, MDBM: -lmdbm, else: -ldbm or none
DBMLIB=	
# Uncomment if AUTH is defined in conf.h
# AUTHLIB=	-lauthuser
LIBS=	${DBMLIB} ${AUTHLIB}

# Installation locations
#  Location of external sendmail files (not sendmail.{cf,fc})
LIBDIR=	/var/apps/mail
#LIBDIR= /usr/lib
#  Location of sendmail executable
BINDIR= /usr/sbin
#BINDIR= /usr/lib
#  Location of symlinks to sendmail
LINKDIR= /usr/sbin
#LINKDIR= /usr/ucb
#  Location of man pages
MANDIR= /usr/local/src/man
#MANDIR= /usr/man

# Look for any missing routines in ../support and add them as needed to the
# SRCS/OBJS after copying them over to .  Also be sure that the pathnames
# in conf.h reflect reality for your system.  Platform-specific settings
# are located in config/foo.h where foo is the OS name.
#
# LINUX systems 0.99-13 and gcc2.4.5 or later
#
#CC=	cc -ansi -Dlinux -DBSD4_4 -O
#CFLAGS=	${DEFS} -I. 
#LIBS= ${AUTHLIB} -ldbm
#
# HP-UX v7.0 systems will need strcasecmp.c and sysexits.h from ../support.
#  Delete the -Wl,-z option from CFLAGS on Series 300/400 machines
# CFLAGS= ${DEFS} -I. -Wl,-z
# LIBS= ${AUTHLIB} -lndbm -lBSD
#
# HP-UX v8.0 no longer requires -lBSD for compilation but is required to
#  ensure Berkeley signal semantics. The alternative means that zombies
#  are left hanging around.  Delete the -Wl,-z option from CFLAGS on
#  Series 300/400 machines
# CC= cc
# CFLAGS= ${DEFS} -I. -Aa -Wc,-O3 -Wl,-z -D_HPUX_SOURCE -D__hpux
# LIBS= ${AUTHLIB} -lndbm -lBSD
#
# HP Apollos must be running >= 10.3.  Don't use -A nansi or -A ansi.
#  You may need the stdarg.h file from the ../support directory.  The 10.3
#  libresolv file does not seem to work, best results are obtained by
#  installing libresolv.a from Bind 4.9 sources (uxc has them).
#  You must take care to not freeze the sendmail.fc file from two different
#  nodes at the same time. Alias autorebuild is disabled for the same reason
#  but cannot be controlled. See the top-level INSTALL file for comments 
#  about /bin/mail as well as README_APOLLO.
# CFLAGS= -I. -W0,-runtype,BSD4.3,-systype,any ${DEFS}
# CFLAGS= -I. -a -r -W0,-runtype,BSD4.3,-systype,any,-exp ${DEFS}
# CFLAGS= -I. -Y0,//scatter/usr/apollo/lib -W0,-runtype,BSD4.3,-systype,any ${DEFS}
#
# Encore MultiMax will need a more recent version of the Bind software if
#  the vendor libresolv.a file is missing the res_search() call.  
# CFLAGS=	${DEFS} -q host_is_target -q optimize=time -I.
# PARALLEL=	4
#
# Sequents running Dynix can use the defaults above.  Systems running PTX
#  will need
# CC= cc
# CFLAGS=	${DEFS} -Wc,-O3 -I.
# LIBS= ${AUTHLIB} -lseq -lsocket -linet -lnsl -lmalloc
#  Uncommenting the next line will result in faster compilation with both.
# PAR=	&
#
# Sony NEWS machines need malloc(3X) instead of malloc(3C) for frozen config
#  files to work.
#
# Sony NEWS machines running SVR4 can use following and choose
#  config/newsos5.h configuration file
#CFLAGS= ${DEFS} -I. -I/usr/ucbinclude
# If not running NAMED (or not wishing to use it)
#LIBS=   -lucb -lsocket -lnsl -lmld -lmalloc
# If running named
#LIBS=  -lucb -lresolv -lsocket -lnsl -lmld -lmalloc
#
# Mips running RISC/os or EP/IX (CDC brand).
# CFLAGS=	${DEFS} -systype bsd43 -Olimit 600 -I.
# LIBS=	${AUTHLIB} -ldbm -lmld
#
# System 5 Release 3 systems can try the following.  Tested only on Unisoft
#  systems at present.  Most will probably need one of the ndbm replacements
#  listed in conf.h installed.  N.B., sdbm will need -DBSD changed to
#  -DSEEK_SET=0 in the makefile.
# CFLAGS=       ${DEFS} -I. -I../../../lib/sdbm
# DBMLIB=       -L../../../lib/sdbm -lsdbm
#
# System 5 Release 4 systems can try the following.  Tested only on UHC systems
#  at present.  Copy sysexits.h from ../support.
# CFLAGS=	${DEFS} -I. -I/usr/ucbinclude
# DBMLIB=	-L/usr/ucblib -lucb
# LIBS=	${DBMLIB} ${AUTHLIB} -lsocket -lnsl -lelf -lc
#
# SCO Xenix systems will need one of the ndbm replacements listed in conf.h
#  installed.  N.B., sdbm will need -DBSD changed to -DSEEK_SET=0 in the
#  makefile.
# CFLAGS= ${DEFS} -I. -Oacls -w
# DBMLIB=       -L../../../lib/sdbm -lsdbm
# LIBS= ${DBMLIB} ${AUTHLIB} -lsocket -lc_s
#
# Interactive Systems Corp (ISC) SVR3.2 UNIX systems.  -Xp (POSIX environment)
#  required for initgroups().  cc can use both -g and -O ala GNU C.
#CFLAGS=	-Xp
#LIBS=	${DBMLIB} ${AUTHLIB} -linet -lPW
#
# Silicon Graphics Iris systems.  SGI broke vfork() for some mysterious reason.
#  Add -lsun if #define YP is set in conf.h .
# LIBS=	${AUTHLIB} -lmld -lsun
#
# Next systems cannot use sendmail.fc as Mach lacks sbrk().  Don't use
#  -fpcc-struct-return!
# CFLAGS=	${DEFS} -fstrength-reduce -ansi -DNeXT -bsd -I.
#
# OSF/1 on DEC Alphas
# CFLAGS=	${DEFS} -non_shared -I.
#
# Convexen will need to add -DSHARE to DEFS and -lshare to LIBS if the share
#  scheduler is used.  -pcc is no longer required. /usr/include/arpa/nameser.h
#  should have the bit field type changed from u_char to u_int and
#  "|| defined(__convex__)" added to the #if clause for
#  BIT_ZERO_ON_LEFT (BIG_ENDIAN).
# DEFS=	-DSHARE
# LIBS=	${AUTHLIB} -lshare
#
# AIX 3.0 systems can now use sendmail.fc with the LDFLAGS below.  If sendmail
#  still core dumps with frozen config files, add LACK_MALLOC to the 
#  config/aix3.h file.  RTs under AIX can now use sendmail.fc and will
#  also need a ndbm replacement.
# LDFLAGS=	-bnso -bI:/lib/syscalls.exp	# AIX on RS/6000 only
# LIBS=	${AUTHLIB} -lc -lbsd -lm		# AIX on RS/6000 only
#
# Suns with shared libraries need to be linked with -Bstatic for reliable
#  operation.  If when sendmail.fc is used and the executable either complains
#  when re-building the alias database or spawns runaway child processes,
#  then you have the localtime() bug introduced in SUNOS 4.1 (it stomps
#  on byte 9 of an 8 byte malloc).  Add NEED_MALLOC to the config/sunos4.h
#  file or get the fix from SUN.  If your SUN has more 8 Mbytes of memory
#  and running sendmail crashes it, you have the 'pmeg' bug.  Get patch
#  100092-03 and install it.  It's available via anon-FTP from princeton.edu
#  in pub/sun-fixes/sunos4.1/{100092-03.tar.Z,README.100092-03}
#
#  (from the GCC info entry on Incompatibilities)
#  On the Sparc, GNU CC uses an incompatible calling convention for
#  structures.  It passes them by including their contents in the argument
#  list, whereas the standard compiler passes them effectively by reference.
#  The convention for structure returning is also incompatible, and
#  `-fpcc-struct-return' does not help.  Will be fixed in gcc V2.00.
#
#  Suns will also need to link with -lresolv.  The vendor version should
#  be replaced (what else is new) as it can't fail-over to backup DNS
#  servers.  Alternately, get and apply patch 100465-02 -- it's listed
#  as applying to 4.1.3.  And 4.1.1 and 4.1.2; Sun never rolled it into
#  a 4.1.x release. *sigh*
# CFLAGS= ${DEFS} -Bstatic -I.
#
#  Solaris notes:
#  This definition fixes the broken gethostbyname() call in the standard
#  distribution.  Omit if using a replacement libresolv.so || libresolv.a file!
#DEFS= -Dgethostbyname=__switch_gethostbyname
#
#  Solaris systems can't use the -dn -Bstatic flags as several static libraries
#  are missing and some calls, e.g., getpwent(), though present, don't work. 
#  Thank you ever so much Sun.  Copy sysexits.h from ../support.
#  The -lpasswd library contains hashed password file routines used at UIUC.
##LIBS= -L/usr/local/lib -lresolv -lsocket -lnsl -lelf -lpasswd
#LIBS= -dn -Bstatic -L/usr/local/lib -lresolv -lstatic -lsocket -lnsl -lelf -lintl -lpasswd -lstatic
#
# Suns running V3.5 will need libresolv.a built from the Bind 4.9 sources.
#  Sendmail must be built using the include files from those sources as well.
#  The pathname below is just an example unless you arrange your source tree
#  the same way I do.
# CFLAGS= ${DEFS} -I. -I../../../services/bind/include
# 
# Get and install Bind 4.9 if your libc.a || libresolv.a lack the 
# res_search() call.
#
LIBS= -ldbm

# One of sendmail or dsendmail to set your local default make target
#all:	dsendmail $(MAN)
all:	sendmail $(MAN)

# The date sendmail was compiled is written to the freeze file,
# to avoid reading in a .fc file created by a different version.
sendmail:${PAR} ${OBJS}
	echo 'char datecompiled[] = "' `date` '";' >datecompiled.c
	${CC} ${CFLAGS} ${LDFLAGS} -o $@ datecompiled.c ${OBJS} ${LIBS}
	size sendmail; ls -l sendmail; ${WHAT} < version.o

dsendmail:${PAR} ${OBJS}
	echo 'char datecompiled[] = "' `date` '";' >datecompiled.c
	${CC} ${CFLAGS} ${LDFLAGS} -o sendmail datecompiled.c ${OBJS} -lresolv ${LIBS}
	size sendmail; ls -l sendmail; ${WHAT} < version.o

install: sendmail ${MAN}
	install -c -s -o root -m 4511 sendmail ${BINDIR}
	-mkdir ${LIBDIR}
	-mkdir ${LIBDIR}/char
	install -c -o bin -g bin -m 666 /dev/null ${LIBDIR}/sendmail.st
	install -c -o bin -g bin -m 444 sendmail.hf ${LIBDIR}/sendmail.hf
	install -c -o bin -g bin -m 444 sendmail.8 ${MANDIR}/man8
	install -c -o bin -g bin -m 444 aliases.5 ${MANDIR}/man5
	install -c -o bin -g bin -m 444 newaliases.1 ${MANDIR}/man1
	-mkdir /usr/spool/mqueue
	chown root.wheel /usr/spool/mqueue
	chmod 755 /usr/spool/mqueue
	cd ${LINKDIR}; rm -f newaliases mailq bsmtp smtpd runq
	ln -s ${BINDIR}/sendmail ${LINKDIR}/mailq;
	ln -s ${BINDIR}/sendmail ${LINKDIR}/newaliases;
	ln -s ${BINDIR}/sendmail ${LINKDIR}/bsmtp;
	ln -s ${BINDIR}/sendmail ${LINKDIR}/smtpd;
	ln -s ${BINDIR}/sendmail ${LINKDIR}/runq;

strcnv.o:	../ida/charset/strcnv.c
	${CC} ${CFLAGS} -DMAPDIR=\"${DESTDIR}/${LIBDIR}/char\" -c \
		../ida/charset/strcnv.c

man:	$(MAN)

newaliases.0:	newaliases.1
	nroff ${MACROS} newaliases.1 > newaliases.0

aliases.0:	aliases.5
	nroff ${MACROS} aliases.5 > aliases.0

sendmail.0:	sendmail.8
	nroff ${MACROS} sendmail.8 > sendmail.0

clean: ${SRCS}
	rm -f ${OBJS} core sendmail a.out Version.o datecompiled.*

cleandir: clean
	rm -f ${MAN} tags .depend

depend: ${SRCS} ${HDRS}
	mkdep ${CFLAGS} ${SRCS}

prt:
	@(pr -f READ_ME NOTES Makefile; pr -f -b *.h ${SRCS}) | \
		out -dest 3800 -bin 38 -pagedef L66 -font gt12

tags: ${SRCS}
	ctags ${SRCS}

lint: ${SRCS}
	lint -chpb -I. ${DEFS} ${SRCS}

# However we put in one default dependency, to minimize the problems of those
# who don't do a 'make depend'

$(OBJS):	$(HDRS) $(CONFIGS)

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

