##
## Makefile     			For the NYS YP (NIS version 2) server
##
## Copyright (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>
##

MAKE=make

##
## Modify to suit your system, or comment out if not needed.
##
GDBMINC=	-I/usr/gnu/include 
GDBMLIB=	-L/usr/gnu/lib -lgdbm


##
## Use this for Sun Solaris 2.*
##
#


##
## Un hash the following four lines if you want some level of security
## Set up the corect path to the tcp_wrappers source tree
##
# TCP_WRAPPER=1
# TCPW_INC=	-I/tmp/tcpd
# TCPW_LIB=	-L/tmp/tcpd -lwrap
# TCPW_FACILITY=	LOG_DAEMON

SUNOSCOMPAT=	-DSUNOS_COMPATIBILITY_KLUDGE

sunos4:
	$(MAKE) all

sunos5:
	$(MAKE) all NETLIBS="-lrpcsvc -lnsl -lsocket"

linux:
	$(MAKE) all GDBMINC= GDBMLIB=-ldbm


INSTDIR=	/usr/sbin
YPMAPDIR=	/var/yp

## Remember to modify the ypMakefile if you modify YPBINDIR !
YPBINDIR=	/usr/lib/yp

CC=		gcc
CFLAGS=		-O2 -pedantic -ansi -Wall $(GDBMINC) $(TCPW_INC) \
			$(SUNOSCOMPAT) \
			-DTCP_WRAPPER=0$(TCP_WRAPPER) \
			-DTCPW_FACILITY=$(TCPW_FACILITY)
LDLIBS=		$(GDBMLIB) $(TCPW_LIB) $(NETLIBS)

PGMS=ypserv dbload dbcat dbnext
OBJS=server.o yp_svc.o yp_xdr.o version.o

all:	$(PGMS)

server.o:	server.c
	$(CC) $(CFLAGS) -D_PATH_YP='"$(YPMAPDIR)"' -c $(<)

$(OBJS): system.h yp.h

ypserv:	$(OBJS)
	$(CC) -o ypserv $(OBJS) $(LDFLAGS) $(LDLIBS)

dbload:	dbload.o
#	$(CC) $(CFLAGS) -o dbload dbload.c $(GDBMLIB) $(NETLIBS)

dbnext:	dbnext.o
#	$(CC) $(CFLAGS) -o dbnext dbnext.c $(GDBMLIB) $(NETLIBS)

dbcat:	dbcat.o
#	$(CC) $(CFLAGS) -o dbcat dbcat.c $(GDBMLIB) $(NETLIBS)

clean:
	rm -f $(PGMS) core *~ *.o

dbload.o:	dbload.c  system.h
dbcat.o:	dbcat.c system.h
dbnext.o:	dbnext.c system.h

version:
	(PACKNAME=`basename \`pwd\`` ; echo 'char version[] = "'`echo $$PACKNAME | cut -d- -f2`'";' >version.c)

dist distz:	clean version
	(PACKNAME=`basename \`pwd\`` ; cd .. ; tar cf - $$PACKNAME | gzip -9 >$$PACKNAME.tar.gz)

install: ypserv dbload
	install -c -s -o bin -g bin -m 755 ypserv $(INSTDIR)/ypserv
	install -c -o bin -g bin -m 644 ypMakefile $(YPMAPDIR)/Makefile
	install -c -o bin -g bin -m 755 dbload $(YPBINDIR)/dbload
	install -c -o bin -g bin -m 755 mknetid $(YPBINDIR)/mknetid
