#
#   Copyright 2008 Free Software Foundation, Inc.
#
#  This program 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 3 of the License, or
#  (at your option) any later version.
#
#  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
#	Makefile for LPD interface programs
#

SHELL		=	/bin/sh
@SET_MAKE@
prefix		=	@prefix@
exec_prefix	=	@exec_prefix@
PARENT		=	..
BASE		=	../..
HDRS		=	$(PARENT)/hdrs
CC		=	@CC@
CCFLAGS		=	-O @gcc_useful_options@ @funny_compiler_options@
SHLIBCC		=	libtool --mode=link $(CC) $(CCFLAGS)
LDFLAGS		=
LIBNET		=	@SOCKLIBS@
LIBS		=	@LIBS@
CFLAGS		=	$(CCFLAGS) -I$(HDRS) -I$(BASE) -I$(PARENT)
MYLIBDIR	=	$(PARENT)/lib
SHLIB		=	$(MYLIBDIR)/libgnuspool_int.la
RM		=	rm -f
INSTALL		=	@INSTALL@
INSTALL_DATA	=	@INSTALL_DATA@
SPOOLUSER	=	@SPOOLUSER@
USERMODES	=	-o $(SPOOLUSER) -g root -m 4755
ROOTMODES	=	-o root -g root -m 4755
BINDIR		=	$(DESTDIR)@bindir@
INTBINDIR	=	$(DESTDIR)@pkgexecdir@
DATADIR		=	$(DESTDIR)@pkgdatadir@
HELPFILEDIR	=	$(DESTDIR)@sphelpdir@
SYSCONFDIR	=	$(DESTDIR)@sysconfdir@
SPOOLDIR	=	$(DESTDIR)@spooldir@

all:	xtlpd xtlpc xtlpq xtlprm gspl-lpq gspl-lprm

xtlpd:	xtlpd.o lpdparse.o proccmd.o lpdproto.o
	$(SHLIBCC) $(LDFLAGS) -o $@ xtlpd.o lpdparse.o proccmd.o lpdproto.o $(SHLIB) $(LIBNET) $(LIBS)

xtlpc:	xtlpc.o lpcparse.o
	$(SHLIBCC) $(LDFLAGS) -o $@ xtlpc.o lpcparse.o $(SHLIB) $(LIBNET) $(LIBS)

xtlpq:	xtlpq.o
	$(SHLIBCC) $(LDFLAGS) -o xtlpq xtlpq.o $(SHLIB) $(LIBNET) $(LIBS)

xtlprm:	xtlprm.o
	$(SHLIBCC) $(LDFLAGS) -o xtlprm xtlprm.o $(SHLIB) $(LIBNET) $(LIBS)

gspl-lpq:	sp.lpq.o
	$(SHLIBCC) $(LDFLAGS) -o $@ sp.lpq.o $(SHLIB) $(LIBS)

gspl-lprm:	sp.lprm.o
	$(SHLIBCC) $(LDFLAGS) -o $@ sp.lprm.o $(SHLIB) $(LIBS)

xtlprm.o:	xtlpq.c
	ln xtlpq.c xtlprm.c
	$(CC) -c $(CCFLAGS) -I$(HDRS) -I$(BASE) -I$(PARENT) -DXTLPRM xtlprm.c
	rm -f xtlprm.c

sp.lprm.o:	sp.lpq.c
	ln sp.lpq.c sp.lprm.c
	$(CC) -c $(CCFLAGS) -I$(HDRS) -I$(BASE) -I$(PARENT) -DSP_LPRM sp.lprm.c
	rm -f sp.lprm.c

install:	all
	libtool --mode=install $(INSTALL) $(ROOTMODES) xtlprm xtlpd xtlpq xtlpc $(INTBINDIR)
	libtool --mode=install $(INSTALL) $(USERMODES) gspl-lpq gspl-lprm $(BINDIR)
	$(INSTALL) -d $(DATADIR)
	$(INSTALL) remove longlist shortlist $(DATADIR)
	$(INSTALL) -d -o $(SPOOLUSER) -g root -m 755 $(SPOOLDIR)/xtlpc $(SPOOLDIR)/xtlpd
	sed -e 's|SPOOLDIR|@spooldir@|' -e 's|DATADIR|@pkgdatadir@|' xtlpc-ctrl >$(DATADIR)/xtlpc-ctrl
	sed -e 's|SPOOLDIR|@spooldir@|' -e 's|DATADIR|@pkgdatadir@|' xtlpd-ctrl >$(DATADIR)/xtlpd-ctrl
	chown $(SPOOLUSER) $(DATADIR)/xtlpc-ctrl $(DATADIR)/xtlpd-ctrl
	echo '1  BSD  -  -' >$(SYSCONFDIR)/gnuspool.ext

install-strip:	all
	libtool --mode=install $(INSTALL) -s $(ROOTMODES) xtlprm xtlpd xtlpq xtlpc $(INTBINDIR)
	libtool --mode=install $(INSTALL) -s $(USERMODES) gspl-lpq gspl-lprm $(BINDIR)
	$(INSTALL) -d $(DATADIR)
	$(INSTALL) remove longlist shortlist $(DATADIR)
	$(INSTALL) -d -o $(SPOOLUSER) -g root -m 755 $(SPOOLDIR)/xtlpc $(SPOOLDIR)/xtlpd
	sed -e 's|SPOOLDIR|@spooldir@|' -e 's|DATADIR|@pkgdatadir@|' xtlpc-ctrl >$(DATADIR)/xtlpc-ctrl
	sed -e 's|SPOOLDIR|@spooldir@|' -e 's|DATADIR|@pkgdatadir@|' xtlpd-ctrl >$(DATADIR)/xtlpd-ctrl
	chown $(SPOOLUSER) $(DATADIR)/xtlpc-ctrl $(DATADIR)/xtlpd-ctrl
	echo '1  BSD  -  -' >$(SYSCONFDIR)/gnuspool.ext

clean:
	$(RM) *.o xtlpd xtlpc xtlpq xtlprm gspl-lpq gspl-lprm

distclean:	clean
	$(RM) Makefile
