#
############################################################################
############################################################################
# Makefile: configuration build file for Unix LISTSERV
#           distribution
#
# Copyright 1996-2019 by L-Soft international. All rights reserved.
#
# Permission granted to modify this file to specify installation
# information at your site. You may not redistribute this file. 
#
# Maintenance:
# Tracking #    Prg            Desc      
#---------------------------------------------------------------------------
# 1996-0001     deb     If prebuilt lsv executable exists,
#                       perform setup tasks w/o compile step
# 1996-0002     NB      Add -search-request alias to list creation step
# 1999-0001     NB	    Added 1.8d -subscribe-request, -signoff-request, and 
#                       -unsubscribe-request aliases to 'list' stage
# 1999-0002     NB/LK   Fixed bug in "directories:" stage that kept
#                       LSVROOT/home directory from being made and
#                       populated
# 1999-0003     NB      Added CGIDIR macro and code to copy "wa" into cgi-bin
#                       directory if CGIDIR is set (commented out by default)
# 2002-0001     NB      Changed LSV_aliases to allow full paths if 
#                       LSVAMIN_TYPE is "paths" instead of blindly making
#                       '-t' entries if LSVAMIN_TYPE is not "links".
# 2002-0002     NB/LK   Added nooci.o and nocli.o to CFLAGS_`uname` where
#                       applicable.  Moved this section into the user
#                       customization area.
# 2007-0001	NB	Added code to move go2 into LSVROOT.
# 2007-0002 NB  Added LDAP support (mandatory at this time)
# 2008-0001	NB	In lsv_util, reversed order of CFLAGS & CFLAGS_uname
#          			(needed primarily for Solaris)
# 2008-0002	NB	CFLAGS missing from lsv_prog
# 2009-0001	NB	listserv-initd-script.sample added
# 2009-0002	NB	lsv-logger.pl was not being moved into LSVROOT
# 2009-0003	NB	added note to CFLAGS_Linux re nooci.o
# 2010-0001	NB	Solaris 10 does not need -llber and does need -m64
# 2010-0002	NB	Added note regarding -llber and Solaris 8
# 2018-0001 NB  Cleanup and CFLAGS changes for newer Linux distros
#               Removed old, no longer supported OSF1 and HP/UX CFLAGS 
# 2019-0001 NB  Added section to move site.wwwtpl to site165.wwwtpl for 
#               17.0 legacy compatibility @ line 434
#
############################################################################ 
# Begin user customization area. Do not edit the file after the            #
# "End of user customization area" line.                                   #
############################################################################ 
# -- Which C compiler to use to compile the incoming mail interface?
CC=cc
# -- Compiler options?
CFLAGS=-O
# -- Where should the LISTSERV mail and command line interfaces be installed?
BINDIR=/usr/local/bin
# -- Where should the server code and data files LISTSERV needs be placed?
LSVROOT=/home/listserv
# -- Where should incoming mail messages be stored?
LSVSPOOL=/home/listserv/spool
# -- The username of the listserv server.
LSVNAME=listserv
# -- Where is the sendmail "aliases" file?
ALIASES=/etc/aliases
# -- Set LSVAMIN_TYPE depending on how target userids are to be
# -- passed to lsv_amin.  Use "links" to symbolic links to "lsv_amin"
# -- for each LISTSERV e-mail address.  Users of older ZMAILER versions 
# -- must choose this option since programs run from ZMAILER "aliases"
# -- files can't have arguments.  Choose "flags" to have the target 
# -- userid passed to "lsv_amin" with the "-t user" flag.  Choose 
# -- "paths" to have the target userid passed to lsv_amin with the 
# -- full path to LSVSPOOL instead of the "-t" flag.  (Using "paths"
# -- can be important if you use the 'make aliases' or 'make list'
# -- stages to create entries in /etc/aliases and are planning to
# -- use the precompiled binaries.)
# -- 
# -- The recommended setting (and thus the default) is "paths".
LSVAMIN_TYPE=paths
#
# -- If you are planning to use the web archive/administration 
# -- interface and want the Makefile to install the 'wa' script in
# -- your cgi-bin directory, uncomment the next line and set CGIDIR
# -- to the appropriate value.  (The default value seems to be a
# -- common default both for NCSA httpd and for the Apache server
# -- but your installation may vary -- do not accept this default
# -- setting blindly!)
#CGIDIR=/var/www/cgi-bin
#
WHOAMI=/usr/bin/whoami
#WHOAMI=/usr/ucb/whoami		# Uncomment for Solaris
#                           However: OpenSolaris 10 uses /usr/bin/whoami
#
# -- OS-specific flags
# >> DO NOT CHANGE THESE unless you know EXACTLY what you are doing!
# -- If you need DBMS support for one of the unixes noted below, simply 
# -- remove the reference(s) to nooci.o and/or nocli.o for your unix.
# -- See the installation guide if you do not understand this.  Do not
# -- remove nooci.o or nocli.o blindly, because if you do not actually
# -- have SQL*Net / DB2 / unixODBC on your machine, the link operation 
# -- will fail.
#
# -- Also note that LDAP support is REQUIRED.  See below for details.
#
# -- There are two classes of CFLAGS_`uname` variables: CFLAGS_`uname` 
# -- and CFLAGS_LSV_`uname`.  The idea is to avoid binding unnecessary
# -- library support to executables that don't require it.  Typically,
# -- LISTSERV requires external library support that its various utilities
# -- (such as lcmd and jobview) don't need.
# --
# -- Thus, CFLAGS_`uname` represents those compiler flags that are required in
# -- ALL cases both for LISTSERV and its companion executables to properly 
# -- compile and link.
# -- 
# -- CFLAGS_`uname`_LSV is intended to contain compiler flags that relate 
# -- to options such as DBMS and LDAP support that are required only by 
# -- LISTSERV itself; the Makefile will ignore CFLAGS_LSV_`uname` when 
# -- compiling and linking the various LISTSERV utilities.
# --
# -- General note for all CFLAGS variables:  When making changes, ensure
# -- that references to object files precede references to libraries.
#
# -- For AIX
CFLAGS_AIX=
CFLAGS_LSV_AIX=nooci.o nocli.o -lldap -llber
# -- For SOLARIS
# -- Solaris requires -lsocket and -lnsl to be linked in all cases.
# -- NOTICE:  If you are installing the Solaris 8 kit with OpenLDAP, you 
# --          MUST add "-llber" to CFLAGS_LSV_Solaris or relinking will
# --          FAIL.  We recommend upgrading to Solaris 10 if possible.
# -- ALSO NOTE:  All LISTSERV 16.5 kits are 64-bit only. The -m64 
# --          compilation flag in CFLAGS_LSV_Solaris is therefore REQUIRED.
CFLAGS_Solaris=-lsocket -lnsl
CFLAGS_LSV_Solaris=nooci.o nocli.o -lldap -m64
# -- For LINUX
# -- NOTE that RedHat/CentOS 7 requires the -llber and -lresolv libraries,
# --          which is a change from RedHat/CentOS 6 and earlier.  Other dis-
# --          tributions may have other requirements.  LISTSERV for Linux kits
# --          (other than those for Linux S/390) are built on RedHat/CentOS,
# --          but can be run successfully under other x64 Linux distributions 
# --          such as Debian/Ubuntu.
# -- ALSO NOTE that sites intending to interface LISTSERV with a DBMS via
# --          unixODBC should omit the 'nocli.o' object file when compiling.
# --          Because of shared namespaces between DB2 CLI and unixODBC, the
# --          'nocli.o' and 'nouodbc.o' files are effectively interchangeable.  
# --          See the Advanced Topics Manual for LISTSERV for more information.
CFLAGS_Linux=
CFLAGS_LSV_Linux=nooci.o nocli.o -lldap -llber -lresolv
#
# NOTE: LDAP MUST be installed on your machine or the relink will fail.  
# For LDAP support for Solaris, the flag
#     -lldap 
# has been added to the appropriate CFLAGS_`uname` variable above.
# For LDAP support for AIX and Linux, the flags 
#     -lldap -llber
# have been added to the appropriate CFLAGS_`uname` variable above.
#
# For more information about LISTSERV's LDAP support, please see the full
# LISTSERV documentation.
#
###########################################################################
# End of user customization area. Do not edit the remainder of            #
# this file unless directed to do so by an L-Soft engineer.               #
###########################################################################
# -- Directories used by LISTSERV.
LSVDIRS=$(LSVROOT) $(LSVROOT)/home $(LSVROOT)/tmp
#
SHELL=/bin/sh
#
WHICH=$(NAME)$(name)
#
IS_SOLARIS=`uname` = 'SunOS' -a \
	`uname -r | awk '{ if(\$$1<5) printf("0"); else printf("1") }'` = 1 

help:
	@echo " ";\
	echo "Before you build either the LISTSERV server or the mail"\
		"interface";\
	echo "check the BINDIR, LSVROOT and LSVSPOOL macros in this"\
		"Makefile.";\
	echo " ";\
	echo "To make the LISTSERV server enter,  make listserv";\
	echo "To make the LISTSERV mail interface enter,  make mailer";\
	echo "To make the command line interface enter,  make lcmd";\
	echo "To make the job viewer utility enter,  make jobview";\
	echo "To install/update just the mailer enter,  make install_mailer";\
	echo "To install/update just the server enter,  make install_server";\
	echo "To install/update just 'lcmd' enter,  make install_lcmd";\
	echo "To install/update just 'jobview' enter,  make install_jobview";\
	echo "Once you're sure everything built successfully,"\
		"  make install";\
	echo "To refresh/upgrade programs/files on an existing system,  make update";\
	echo "To add entries to the sendmail aliases file for LISTSERV,"\
		"  make aliases";\
	echo "To add aliases file entries for a new mailing list,"\
		"  make list name=XXX";\
	echo "(where XXX is the name of the list).";\
	echo " ";\
	echo "Please refer to the installation guide for more detailed"\
		"information."

# -- creating the executables
#
# -- The ")" test is to catch systems with make's that can't handle
# --   $(AA$(BB)) type macros.
lsv_prog:
	if [ "$(CFLAGS_$(UNAME))" = ")" ]; then \
		$(CC) -o lsv lsv.o $(CFLAGS); \
	else \
		$(CC) -o lsv lsv.o $(CFLAGS) `echo "$(CFLAGS_LSV_$(UNAME)) $(CFLAGS_$(UNAME))"`; \
	fi

lsv: lsv.o
	if [ $(IS_SOLARIS) ]; then \
		make lsv_prog UNAME=Solaris; \
	else \
		make lsv_prog UNAME=`uname`; \
	fi

lsv_util:
	if [ "$(CFLAGS_$(UNAME))" = ")" ]; then \
	  $(CC) -o $(PROG) $(PROG).c $(CFLAGS) $(XOPT); \
	else \
	  $(CC) -o $(PROG) $(PROG).c $(CFLAGS) `echo "$(CFLAGS_$(UNAME))"` \
		$(XOPT); \
	fi
	if [ `$(WHOAMI)` != "$(LSVNAME)" ]; \
	then chown $(LSVNAME) $(PROG); \
	else true; \
	fi
	if [ ".$(UMOD)" != "." ]; then chmod 4755 $(PROG); fi

lsv_amin: lsv_amin.c lsv_amin.h
	if [ $(IS_SOLARIS) ]; then \
		make lsv_util UNAME=Solaris PROG=$@ UMOD=4755 \
			XOPT='-DSPOOL_DIR=\"$(LSVSPOOL)\"'; \
	else \
		make lsv_util UNAME=`uname` PROG=$@ UMOD=4755 \
			XOPT='-DSPOOL_DIR=\"$(LSVSPOOL)\"'; \
	fi

lcmd: lcmd.c
	if [ $(IS_SOLARIS) ]; then \
		make lsv_util UNAME=Solaris PROG=$@ UMOD=4755 \
			XOPT='-DSPOOL_DIR=\"$(LSVSPOOL)\"'; \
	else \
		make lsv_util UNAME=`uname` PROG=$@ UMOD=4755 \
			XOPT='-DSPOOL_DIR=\"$(LSVSPOOL)\"'; \
	fi

jobview: jobview.c
	if [ $(IS_SOLARIS) ]; then \
		make lsv_util UNAME=Solaris PROG=$@; \
	else \
		make lsv_util UNAME=`uname` PROG=$@; \
	fi

# -- installing the executables and data files needed to run LISTSERV
$(LSVDIRS) $(LSVSPOOL):
	if [ `$(WHOAMI)` = $(LSVNAME) ]; \
	then umask 066;mkdir -p $@; \
	else su $(LSVNAME) -c "umask 066;mkdir -p $@"; \
	fi

directories: $(LSVDIRS) $(LSVSPOOL)

# -- Generic entries for files in the LSV-root and LSV-root/home directories
$(LSVROOT)/$(RFILE): $(RFILE)
	cp $(RFILE) $@
	if [ ".$(RMOD)" != "." ]; then chmod $(RMOD) $@; else true; fi

$(LSVROOT)/home/$(HFILE): home/$(HFILE)
	cp -r home/$(HFILE) $@

# -- installed copies of programs
$(BINDIR)/lcmd: lcmd
	cp lcmd $@
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; else true; fi
	chmod 4755 $@
	if [ `pwd` != $(LSVROOT) ]; then \
		if [ -s $(LSVROOT)/lcmd.c ]; then \
			mv $(LSVROOT)/lcmd.c $(LSVROOT)/lcmd.c.OLD; \
		else true; \
		fi; \
		cp lcmd.c $(LSVROOT)/lcmd.c; \
	else true; \
	fi

$(BINDIR)/lsv_amin: lsv_amin
	cp lsv_amin $@
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; else true; fi
	chmod 4755 $@
	if [ `pwd` != $(LSVROOT) ]; then \
		if [ -s $(LSVROOT)/lsv_amin.c ]; then \
			mv $(LSVROOT)/lsv_amin.c $(LSVROOT)/lsv_amin.c.OLD; \
		else true; \
		fi; \
		cp lsv_amin.c $(LSVROOT)/lsv_amin.c; \
		if [ -s $(LSVROOT)/lsv_amin.h ]; then \
			mv $(LSVROOT)/lsv_amin.h $(LSVROOT)/lsv_amin.h.OLD; \
		else true; \
		fi; \
		cp lsv_amin.h $(LSVROOT)/lsv_amin.h; \
	else true; \
	fi

$(LSVSPOOL)/jobview: jobview
	cp jobview $@
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; else true; fi
	if [ `pwd` != $(LSVROOT) ]; then \
		if [ -s $(LSVROOT)/jobview.c ]; then \
			mv $(LSVROOT)/jobview.c $(LSVROOT)/jobview.c.OLD; \
		else true; \
		fi; \
		cp jobview.c $(LSVROOT)/jobview.c; \
	else true; \
	fi

$(LSVROOT)/lsv: lsv
	cp lsv $@
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; else true; fi

$(LSVROOT)/go.user: $(LSVROOT)
	if [ ! -s $@ ]; then \
		cp go.user.sample $@; \
		chmod 750 $@; \
		if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; \
		else true; \
		fi; \
	else true; \
	fi

$(LSVROOT)/go.sys:
	echo "#!/bin/sh" >go.sys.temp
	echo "LSVROOT="$(LSVROOT) >>go.sys.temp
	echo "LSVSPOOL="$(LSVSPOOL) >>go.sys.temp
	cat go.sys >>go.sys.temp
	cp go.sys.temp $@
	chmod 750 $@
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; else true; fi
	rm go.sys.temp

$(CGIDIR)/wa: wa
	cp wa $@
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then chown $(LSVNAME) $@; else true; fi
	chmod 4755 $@
	if [ `pwd` != $(LSVROOT) ]; then \
		if [ -s $(LSVROOT)/wa ]; then \
			mv $(LSVROOT)/wa $(LSVROOT)/wa.OLD; \
		else true; \
		fi; \
		cp wa $(LSVROOT)/wa; \
	else true; \
	fi

# -- aliases used to install specific pieces
install_lcmd: $(BINDIR)/lcmd

install_jobview: $(LSVSPOOL)/jobview

install_mailer: $(BINDIR)/lsv_amin

install_server: $(LSVROOT)/lsv

install_wa: $(CGIDIR)/wa

install: $(LSVROOT)/go.user $(LSVDIRS) $(LSVSPOOL)
	if [ -s lsv.o ]; then make install_server; else true; fi
	if [ -s lsv_amin.c ]; then make install_mailer; else true; fi
	if [ -s lcmd.c ]; then make install_lcmd; else true; fi
	if [ -s jobview.c ]; then make install_jobview; else true; fi
	if [ $(CGIDIR) ]; then \
		if [ -s wa ]; then make install_wa; else true; fi \
	else true; \
	fi
	if [ -s u-install.memo ]; then \
		make $(LSVROOT)/u-install.memo RFILE=u-install.memo; \
	else true; \
	fi
	if [ -s go.sys ]; then \
		if [ -s $(LSVROOT)/go.sys ]; then \
			mv $(LSVROOT)/go.sys $(LSVROOT)/go.sys.OLD; \
		else true; \
		fi; \
		make $(LSVROOT)/go.sys; \
	else true; \
	fi
	if [ -s go ]; then \
		if [ -s $(LSVROOT)/go ]; then \
			mv $(LSVROOT)/go $(LSVROOT)/go.OLD; \
		else true; \
		fi; \
		cp go $(LSVROOT)/go; \
		chmod 750 $(LSVROOT)/go; \
	else true; \
	fi
	if [ -s go2 ]; then \
		if [ -s $(LSVROOT)/go2 ]; then \
			mv $(LSVROOT)/go2 $(LSVROOT)/go2.OLD; \
		else true; \
		fi; \
		cp go2 $(LSVROOT)/go2; \
		chmod 750 $(LSVROOT)/go2; \
	else true; \
	fi
	if [ -s Makefile ]; then \
		if [ -s $(LSVROOT)/Makefile ]; then \
			mv $(LSVROOT)/Makefile $(LSVROOT)/Makefile.OLD; \
		else true; \
		fi; \
		cp Makefile $(LSVROOT)/Makefile; \
	else true; \
	fi
	if [ -s license.merge ]; then \
		cp license.merge $(LSVROOT)/home/license.merge; \
	else true; \
	fi
	if [ -s listserv-initd-script.sample ]; then \
		if [ -s $(LSVROOT)/listserv-initd-script.sample ]; then \
			mv $(LSVROOT)/listserv-initd-script.sample $(LSVROOT)/listserv-initd-script.sample.OLD; \
		else true; \
		fi; \
		cp listserv-initd-script.sample $(LSVROOT)/listserv-initd-script.sample; \
	else true; \
	fi
	if [ -s lsv-logger.pl ]; then \
		if [ -s $(LSVROOT)/lsv-logger.pl ]; then \
			mv $(LSVROOT)/lsv-logger.pl $(LSVROOT)/lsv-logger.pl.OLD; \
		else true; \
		fi; \
		cp lsv-logger.pl $(LSVROOT)/lsv-logger.pl; \
		chmod 700 $(LSVROOT)/lsv-logger.pl; \
	else true; \
	fi
# section added for 17.0 legacy
	if [ -d $(LSVROOT)/home ]; then \
		if [[ -s $(LSVROOT)/home/site.wwwtpl ]] && [[ ! -s $(LSVROOT)/home/site165.wwwtpl ]]; then \
			mv $(LSVROOT)/home/site.wwwtpl $(LSVROOT)/home/site165.wwwtpl; \
		else true; \
		fi; \
	fi
# end of section added for 17.0 legacy
	if [ -d $(LSVROOT)/home ]; then \
		FLIST=`ls home`; \
		set -e; \
		for CHK in $$FLIST; do \
			make $(LSVROOT)/home/$$CHK HFILE=$$CHK; \
		done; \
	else true; \
	fi
	if [ `$(WHOAMI)` != $(LSVNAME) ]; then \
		cd $(LSVROOT); \
		chown -R $(LSVNAME) $(LSVDIRS); \
	else true; \
	fi
	@echo " "
	@echo "-- All files have been successfully installed. Next please" \
		"enter,"
	@echo "--    cd $(LSVROOT)"
	@echo "-- and edit 'go.user'. The environment variables defined in" \
		"that file"
	@echo "-- must be customized before you start LISTSERV."

LSV_aliases:
	if [ ".$(LSVAMIN_TYPE)" = ".links" ]; then \
	  echo "$(NEW_A): \"|$(BINDIR)/$(NEW_A)\"" >>$(ALIASES); \
	  ln -s $(BINDIR)/lsv_amin $(BINDIR)/$(NEW_A); \
	else \
	  if [ ".$(LSVAMIN_TYPE)" = ".paths" ]; then \
	    echo "$(NEW_A): \"|$(BINDIR)/lsv_amin $(LSVSPOOL) $(NEW_A)\"" >>$(ALIASES); \
	  else \
	    echo "$(NEW_A): \"|$(BINDIR)/lsv_amin -t $(NEW_A)\"" >>$(ALIASES); \
	  fi \
	fi

aliases:
	echo "# -- Aliases for LISTSERV server" >>$(ALIASES)
	make LSV_aliases NEW_A=listserv
	make LSV_aliases NEW_A=owner-listserv
	make LSV_aliases NEW_A=listserv-request
	newaliases
	if [ -s '/etc/sendmail.pid' ]; then \
		kill -HUP `cat /etc/sendmail.pid`; \
	else true; \
	fi

list:
	echo "# -- Aliases for '$(WHICH)' mailing list" >>$(ALIASES)
	make LSV_aliases NEW_A=$(WHICH)
	make LSV_aliases NEW_A=owner-$(WHICH)
	make LSV_aliases NEW_A=$(WHICH)-request
	make LSV_aliases NEW_A=$(WHICH)-search-request
	make LSV_aliases NEW_A=$(WHICH)-server
	make LSV_aliases NEW_A=$(WHICH)-subscribe-request
	make LSV_aliases NEW_A=$(WHICH)-signoff-request
	make LSV_aliases NEW_A=$(WHICH)-unsubscribe-request
	newaliases
	if [ -s '/etc/sendmail.pid' ]; then \
		kill -HUP `cat /etc/sendmail.pid`; \
	else true; \
	fi

# -- aliases for other things (which are defined above)
both: lsv_amin lsv

all world: lsv_amin lsv lcmd jobview

LISTSERV listserv server: lsv

mailer: lsv_amin

update_utils install_utils: install_lcmd install_jobview

update: install

update_mailer: install_mailer

update_lcmd: install_lcmd

update_jobview: install_jobview

update_server: install_server

