##
## Makefile    For the NYS YP (NIS version 2) server
##
## Copyright (c) 1996-2000 Thorsten Kukuk, Germany
##           (c) 1993,1994 Signum Support AB, Sweden
##
## This file is part of the NYS YP Server.
##
## The NYS YP Server is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The NYS YP Server is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public
## License along with the NYS YP Server; see the file COPYING.  If
## not, write to the Free Software Foundation, Inc., 675 Mass Ave,
## Cambridge, MA 02139, USA.
##
## Author: Peter Eriksson <pen@signum.se>
##
## Changed for configure: Thorsten Kukuk <kukuk@suse.de>
##
#### Start of system configuration section. ####

prefix = @prefix@
exec_prefix = @exec_prefix@

## Remember to modify the ypMakefile if you modify YPBINDIR !
YPBINDIR= @libexecdir@
YPMAPDIR= /var/yp
SBINDIR = $(exec_prefix)/sbin
UBINDIR = $(exec_prefix)/bin
CONFDIR = @sysconfdir@
MANDIR  = @mandir@
MAN1DIR = $(MANDIR)/man1
MAN5DIR = $(MANDIR)/man5
MAN8DIR = $(MANDIR)/man8
INCDIR	= $(prefix)/include

## Where to install makedbm (normal /usr/lib/yp, Solaris: /usr/sbin)
MAKEDBMDIR = @MAKEDBM@

## Change this only, if your securenets file is in an
## unusual place. Normaly, ypserv will search for a file
## "securenets" in YPMAPDIR.
#SECURENETS = $(YPMAPDIR)/securenets

## How many children of ypserv should be run max. at one time
MAXCHILDREN = 40
XFRBLOCKSIZE= 65535

## Should we install ypmake ("yes" OR "no")
build-ypmake = @YPMAKE@

## Should we allow root to change NIS passwords ? ("yes" OR "no")
checkroot = @CHECKROOT@

## Should we always use FQDN ? ("yes" OR "no")
use_fqdn = @USE_FQDN@

## Where the ypmake sources are:
YPMAKESRC = @srcdir@/ypmake

srcdir  = @srcdir@
VPATH   = @srcdir@

CC   = @CC@
CPP  = @CPP@
AWK  = @AWK@
MAKE = @MAKE@
BASH = @BASH@
ALIASES = @MAIL_ALIASES@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ -m 755
INSTALL_DATA = @INSTALL_DATA@

# General compile options and libs:
DEFS = @DEFS@
LIBS = @LIBS@
LIBDBM = @LIBDBM@
RESOLV = @RESOLV@
TCP_WRAP = @TCP_WRAP@
LIBRPC = @LIBRPC@
LIBCRYPT = @LIBCRYPT@

CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@ -DYPMAPDIR='"$(YPMAPDIR)"' -DYPBINDIR='"$(YPBINDIR)"'\
		-DCONFDIR='"$(CONFDIR)"' -DMAX_CHILDREN=$(MAXCHILDREN)\
		-DXFRBLOCKSIZE=$(XFRBLOCKSIZE)

ifneq ($(SECURENETS)x,x)
CPPFLAGS += -DSECURENETS='"$(SECURENETS)"'
endif

ifneq ($(checkroot),no)
CPPFLAGS += -DCHECKROOT=1
else
CPPFLAGS += -DCHECKROOT=0
endif

ifneq ($(use_fqdn),no)
CPPFLAGS += -DUSE_FQDN=1
else
CPPFLAGS += -DUSE_FQDN=0
endif

LDFLAGS = @LDFLAGS@
WARNFLAGS = @WARNFLAGS@

#### End of system configuration section. ####

SHELL = /bin/sh

PGMS=		ypserv yppush makedbm ypxfr revnetgroup ypinit mknetid\
		ypMakefile ypxfr_1perhour ypxfr_2perday ypxfr_1perday\
		rpc.ypxfrd pwupdate rpc.yppasswdd yphelper create_printcap\
		match_printcap
SRCS=		server.c ypserv.c ypserv_xdr.c yppush.c yppush_xdr.c\
		ypxfr.c ypxfr_xdr.c ypxfr_clnt.c makedbm.c hash.c\
		dns_hosts.c access.c yp_msg.c revnetgroup.c getnetgrent.c\
		ypserv_conf.c mknetid.c netid_hash.c ypxfrd_svc.c ypserv_v1.c\
		ypxfrd_server.c ypxfrd.c ypxfrd_getmap.c yp_db.c ypxfrd_xdr.c\
		yphelper.c
YPSERVOBJ=	server.o ypserv.o ypserv_xdr.o dns_hosts.o access.o yp_msg.o\
		ypserv_conf.o yp_db.o ypserv_v1.o
YPPUSHOBJ=	yppush.o yppush_xdr.o yp_msg.o
YPXFRDOBJ=	ypxfrd_svc.o ypxfrd_server.o access.o ypxfrd.o ypxfrd_xdr.o \
		ypserv_conf.o yp_msg.o dns_hosts.o yp_db.o
YPXFROBJ=	ypxfr.o ypxfr_clnt.o ypxfr_xdr.o yp_msg.o ypxfrd_getmap.o \
		ypxfrd_xdr.o
YPPASSWDDOBJ=	update.o yppasswd_xdr.o yppasswdd.o yp_msg.o
MAKEDBMOBJ=	makedbm.o
REVNETGROUPOBJ=	revnetgroup.o getnetgrent.o hash.o
MKNETIDOBJ=	mknetid.o netid_hash.o
YPHELPEROBJ=    yphelper.o ypserv_xdr.o
MANPAGES=	ypserv.8 ypserv.conf.5 yppush.8 ypxfr.8 ypinit.8 netgroup.5\
		revnetgroup.8 rpc.ypxfrd.8 ypxfrd.8 mknetid.8 yppasswdd.8\
		rpc.yppasswdd.8 pwupdate.8 makedbm.8

COMPILE = $(CC) -c $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) $(CFLAGS) $(WARNFLAGS)

.c.o:
	$(COMPILE) $<

all:	.depend sedscript $(PGMS) $(MANPAGES)

ypserv: $(YPSERVOBJ)
	$(CC) -o ypserv $(YPSERVOBJ) $(LDFLAGS) $(LIBS) $(RESOLV) $(TCP_WRAP) $(LIBDBM)

yppush: $(YPPUSHOBJ)
	$(CC) -o yppush $(YPPUSHOBJ) $(LDFLAGS) $(LIBS) $(LIBDBM)

ypxfr:	$(YPXFROBJ)
	$(CC) -o ypxfr $(YPXFROBJ) $(LDFLAGS) $(LIBS) $(LIBDBM) $(LIBRPC)

makedbm: $(MAKEDBMOBJ)
	$(CC) $(CFLAGS) -o makedbm $(MAKEDBMOBJ) $(LIBS) $(LIBDBM)

yphelper: $(YPHELPEROBJ)
	$(CC) $(CFLAGS) -o yphelper $(YPHELPEROBJ) $(LIBS)

revnetgroup: $(REVNETGROUPOBJ)
	$(CC) $(CFLAGS) -o revnetgroup $(REVNETGROUPOBJ) $(LIBS)

mknetid: $(MKNETIDOBJ)
	$(CC) $(CFLAGS) -o mknetid $(MKNETIDOBJ) $(LIBS)

rpc.ypxfrd: $(YPXFRDOBJ)
	$(CC) $(CFLAGS) -o rpc.ypxfrd $(YPXFRDOBJ) $(LIBS) $(RESOLV) $(TCP_WRAP) $(LIBDBM)

rpc.yppasswdd: $(YPPASSWDDOBJ)
	$(CC) $(CFLAGS) -o rpc.yppasswdd $(YPPASSWDDOBJ) $(LIBS) $(TCP_WRAP) $(LIBCRYPT)

ypinit: $(srcdir)/ypinit.in sedscript
	rm -f ypinit
	./sedscript < $(srcdir)/ypinit.in > ypinit
	chmod 755 ypinit

ypxfr_1perhour: $(srcdir)/ypxfr_1perhour.in sedscript
	rm -f ypxfr_1perhour
	./sedscript < $(srcdir)/ypxfr_1perhour.in > ypxfr_1perhour
	chmod 755 ypxfr_1perhour

ypxfr_2perday: $(srcdir)/ypxfr_2perday.in sedscript
	rm -f ypxfr_2perday
	./sedscript < $(srcdir)/ypxfr_2perday.in > ypxfr_2perday
	chmod 755 ypxfr_2perday

ypxfr_1perday: $(srcdir)/ypxfr_1perday.in sedscript
	rm -f ypxfr_1perday
	./sedscript < $(srcdir)/ypxfr_1perday.in > ypxfr_1perday
	chmod 755 ypxfr_1perday

ypMakefile: $(srcdir)/ypMakefile.in sedscript
	rm -f ypMakefile
	./sedscript < $(srcdir)/ypMakefile.in > ypMakefile

create_printcap: $(srcdir)/create_printcap.in sedscript
	rm -f create_printcap
	./sedscript < $(srcdir)/create_printcap.in > create_printcap
	chmod 755 create_printcap

match_printcap: $(srcdir)/match_printcap.in sedscript
	rm -f match_printcap
	./sedscript < $(srcdir)/match_printcap.in > match_printcap
	chmod 755 match_printcap

ypserv.8: $(srcdir)/ypserv.8.in sedscript
	rm -f ypserv.8
	./sedscript < $(srcdir)/ypserv.8.in > ypserv.8

ypserv.conf.5: $(srcdir)/ypserv.conf.5.in sedscript
	rm -f ypserv.conf.5
	./sedscript < $(srcdir)/ypserv.conf.5.in > ypserv.conf.5

rpc.ypxfrd.8: $(srcdir)/rpc.ypxfrd.8.in sedscript
	rm -f rpc.ypxfrd.8
	./sedscript < $(srcdir)/rpc.ypxfrd.8.in > rpc.ypxfrd.8

rpc.yppasswdd.8: $(srcdir)/rpc.yppasswdd.8.in sedscript
	rm -f rpc.yppasswdd.8
	./sedscript < $(srcdir)/rpc.yppasswdd.8.in > rpc.yppasswdd.8

yppush.8: $(srcdir)/yppush.8.in sedscript
	rm -f yppush.8
	./sedscript < $(srcdir)/yppush.8.in > yppush.8

ypxfr.8: $(srcdir)/ypxfr.8.in sedscript
	rm -f ypxfr.8
	./sedscript < $(srcdir)/ypxfr.8.in > ypxfr.8

ypinit.8: $(srcdir)/ypinit.8.in sedscript
	rm -f ypinit.8
	./sedscript < $(srcdir)/ypinit.8.in > ypinit.8

mknetid.8: $(srcdir)/mknetid.8.in sedscript
	rm -f mknetid.8
	./sedscript < $(srcdir)/mknetid.8.in > mknetid.8

revnetgroup.8: $(srcdir)/revnetgroup.8.in sedscript
	rm -f revnetgroup.8
	./sedscript < $(srcdir)/revnetgroup.8.in > revnetgroup.8

pwupdate: $(srcdir)/pwupdate.in sedscript
	rm -f pwupdate
	./sedscript < $(srcdir)/pwupdate.in > pwupdate
	chmod 755 pwupdate

pwupdate.8: $(srcdir)/pwupdate.8.in sedscript
	rm -f pwupdate.8
	./sedscript < $(srcdir)/pwupdate.8.in > pwupdate.8

makedbm.8: $(srcdir)/makedbm.8.in sedscript
	rm -f makedbm.8
	./sedscript < $(srcdir)/makedbm.8.in > makedbm.8

sedscript: Makefile
	@rm -f sedscript
	@echo "sed \\" > sedscript
	@echo "	-e 's;@YPBINDIR@;$(YPBINDIR);g'\\" >> sedscript
	@echo "	-e 's;@YPMAPDIR@;$(YPMAPDIR);g'\\" >> sedscript
	@echo "	-e 's;@SBINDIR@;$(SBINDIR);g'\\" >> sedscript
	@echo " -e 's;@CONFDIR@;$(CONFDIR);g'\\" >> sedscript
	@echo "	-e 's;@AWKPRG@;$(AWK);g'\\" >> sedscript
	@echo " -e 's;@MAKEPRG@;$(MAKE);g'\\" >> sedscript
	@echo " -e 's;@MAKEDBMPRG@;$(MAKEDBMDIR);g'\\" >> sedscript
	@echo " -e 's;@BASHPRG@;$(BASH);g'\\" >> sedscript
	@echo " -e 's;@ALIASES@;$(ALIASES);g'" >> sedscript
	@chmod 700 sedscript

clean:
	rm -f $(PGMS) sedscript core *.o *~ ypserv.conf.5 .depend mknetid.8
	rm -f revnetgroup.8 ypinit.8 yppush.8 ypserv.8 ypxfr.8 rpc.ypxfrd.8
	rm -f rpc.yppasswdd.8 pwupdate.8 makedbm.8
	(cd $(YPMAKESRC); make -f Makefile.in clean)

distclean: clean
	rm -f .depend config.log config.cache config.status config.h Makefile
	(cd $(YPMAKESRC); rm -f Makefile; rm -f defs.sed)

installdirs:
	$(srcdir)/mkinstalldirs $(ROOT)$(YPBINDIR) $(ROOT)$(YPMAPDIR)
	$(srcdir)/mkinstalldirs $(ROOT)$(SBINDIR) $(ROOT)$(MAN5DIR)
	$(srcdir)/mkinstalldirs $(ROOT)$(MAN8DIR) $(ROOT)$(CONFDIR)
	$(srcdir)/mkinstalldirs $(ROOT)$(UBINDIR) $(ROOT)$(MAN1DIR)
	$(srcdir)/mkinstalldirs $(ROOT)$(INCDIR)/rpcsvc $(ROOT)/etc

install: all installdirs install_progs install_ypmake

install_progs:
	$(INSTALL_PROGRAM) -s ypserv $(ROOT)$(SBINDIR)
	$(INSTALL_DATA) ypserv.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_DATA) ypserv.conf.5 $(ROOT)$(MAN5DIR)
	$(INSTALL_PROGRAM) -s rpc.ypxfrd $(ROOT)$(SBINDIR)
	$(INSTALL_DATA) rpc.ypxfrd.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_DATA) $(srcdir)/ypxfrd.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) -s yppush $(ROOT)$(SBINDIR)
	$(INSTALL_DATA) yppush.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) -s ypxfr $(ROOT)$(YPBINDIR)
	$(INSTALL_PROGRAM) ypxfr_1perhour $(ROOT)$(YPBINDIR)
	$(INSTALL_PROGRAM) ypxfr_2perday $(ROOT)$(YPBINDIR)
	$(INSTALL_PROGRAM) ypxfr_1perday $(ROOT)$(YPBINDIR)
	$(INSTALL_DATA) ypxfr.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) -s makedbm $(ROOT)$(MAKEDBMDIR)
	$(INSTALL_DATA) makedbm.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) ypinit $(ROOT)$(YPBINDIR)
	$(INSTALL_DATA) ypinit.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) -s rpc.yppasswdd $(ROOT)$(SBINDIR)
	$(INSTALL_DATA) rpc.yppasswdd.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_DATA) $(srcdir)/yppasswdd.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) -s revnetgroup $(ROOT)$(YPBINDIR)
	$(INSTALL_DATA) revnetgroup.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) -s mknetid $(ROOT)$(YPBINDIR)
	$(INSTALL_PROGRAM) -s yphelper $(ROOT)$(YPBINDIR)
	$(INSTALL_PROGRAM) pwupdate $(ROOT)$(YPBINDIR)
	$(INSTALL_DATA) pwupdate.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_PROGRAM) create_printcap $(ROOT)$(YPBINDIR)
	$(INSTALL_PROGRAM) match_printcap $(ROOT)$(YPBINDIR)
	$(INSTALL_DATA) mknetid.8 $(ROOT)$(MAN8DIR)
	$(INSTALL_DATA) $(srcdir)/netgroup.5 $(ROOT)$(MAN5DIR)
	if [ -f $(ROOT)$(YPMAPDIR)/Makefile ]; then \
	   $(INSTALL_DATA) ypMakefile $(ROOT)$(YPMAPDIR)/Makefile.new; \
	else \
	   $(INSTALL_DATA) ypMakefile $(ROOT)$(YPMAPDIR)/Makefile; \
	fi
	if [ ! -f $(ROOT)$(YPMAPDIR)/securenets ]; then \
	   $(INSTALL_DATA) $(srcdir)/etc/securenets $(ROOT)$(YPMAPDIR); \
	fi
	if [ ! -f $(ROOT)/etc/netgroup ]; then \
	   $(INSTALL_DATA) $(srcdir)/etc/netgroup $(ROOT)/etc/netgroup; \
	fi
	if [ ! -f $(ROOT)/etc/timezone ]; then \
	   $(INSTALL_DATA) $(srcdir)/etc/timezone $(ROOT)/etc/timezone; \
	fi
	if [ ! -f $(ROOT)/etc/locale ]; then \
	   $(INSTALL_DATA) $(srcdir)/etc/locale $(ROOT)/etc/locale; \
	fi
	if [ ! -f $(ROOT)/etc/netmasks ]; then \
	  $(INSTALL_DATA) $(srcdir)/etc/netmasks $(ROOT)/etc/netmasks; \
	fi
	$(INSTALL_DATA) $(srcdir)/ypxfrd.x $(ROOT)$(INCDIR)/rpcsvc

install_ypmake:
ifneq ($(build-ypmake),no)
	(cd $(YPMAKESRC) && ./configure && make && make install)
endif

ifeq (.depend,$(wildcard .depend))
include .depend
endif

depend dep .depend: $(SRCS)
	$(CPP) $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) -M $(addprefix $(srcdir)/, $(SRCS)) > .depend
