# (c) Copyright 1992 by Panagiotis Tsirigotis
# All rights reserved.  The file named COPYRIGHT specifies the terms 
# and conditions for redistribution.

#
# $Id: Makefile,v 1.1 1997/01/19 10:57:57 jan $
#
# Based on Program makefile template: *Revision: 1.14 *
#

#
# Available entries:
#		$(NAME)		--> create the program (this is the default target)
#		install		--> install the program (and man page)
#		uninstall	--> uninstall the program (and man page)
#		clean			--> cleanup
#		spotless		--> clean + uninstall
# 		lint			--> lints a specific file (usage: make lint MODULE=foo.c)
#		lintall		--> lint all files
#		tags			--> creates a tags file
#		checkout 	--> checkout all files
#

NAME		= xinetd
VERSION		= 2.2.1

#
# Possible flags that can be defined in DEFS:
#
#   -DCUSTOMCONF	if you want to change any of the constants that
#			  affect xinetd's behavior (check config.h)
#   -DNO_POSIX_TYPES	if your OS does not know about POSIX types like pid_t
#   -DNO_TERMIOS	if you don't have /usr/include/sys/termios.h
#   -DOLD_WAIT		if your OS supports union wait
#   -DNO_RPC		if your OS does not support RPC
#   -DNO_SIGLIST	if your C library does not contain sys_siglist
#   -DNO_TIMERS		if you don't want to use the timer library
#   -DNO_INITIGROUPS	if your OS does not support the initgroups(3) call
#
#   removed: -DBIND_IF, always use '-host' option and 'Interface' attribute
#			in combination now, see README.
#			(19/1/97 J. Wedekind, jw@Germany.EU.net, jan@ping.de).
#
# About signal handling:
#  Case 1: POSIX signal handling is supported
#     You don't need to define anything
#  Case 2: BSD signal handling is supported (i.e. sigvec(2))
#     Use -DNO_POSIX_SIGS
#  Case 3: None of the above
#     Use -DNO_POSIX_SIGS and -DNO_SIGVEC
#
# Available debug flags:
#   DEBUG		code is being debugged
#   DEBUG_SERVER	forked server will do a sleep
#   DEBUG_INTERCEPTOR	forked interceptor will do a sleep
#   DEBUG_SIGNALS	code that handles SIGSEGV and SIGBUS
#   DEBUG_LOGGING	forked logging server will do a sleep
#   DEBUG_SHUTDOWN	forked shutdown server will do a sleep
#   DEBUG_TPCINT	enable debugging code in the tcp interceptor
#   DEBUG_UDPINT	enable debugging code in the udp interceptor
#   DEBUG_DAEMON	debug xinetd when not invoked with -d option
#   DEBUG_RETRY		debug the server retry code
#

DEFS	= -DDEBUG -DNO_RPC

DEBUG	= -g			# either -g or -O
LDFLAGS	= -L$(LIBDIR)$(DEBUG)

LIBS	= -lsio -lmisc -lstr -lpset -lxlog -ltimer -lpq

# FreeBSD, NetBSD, BSDI need this
#OSLIBS	= -lcompat

HDRS	= access.h addr.h attr.h builtin.h \
	  conf.h config.h connection.h \
	  defs.h flags.h int.h log.h mask.h parse.h \
	  sconst.h sconf.h server.h service.h state.h

SRCS	= access.c addr.c builtins.c \
	  child.c conf.c confparse.c connection.c \
	  env.c flags.c ident.c init.c int.c intcommon.c internals.c \
	  log.c logctl.c main.c msg.c nvlists.c \
	  parse.c parsesup.c parsers.c reconfig.c retry.c \
	  sconf.c server.c service.c shutdown.c \
	  signals.c special.c tcpint.c time.c udpint.c util.c

OBJS	= access.o addr.o builtins.o \
	  child.o conf.o confparse.o connection.o \
	  env.o flags.o ident.o init.o int.o intcommon.o internals.o \
	  log.o logctl.o main.o msg.o nvlists.o \
	  parse.o parsesup.o parsers.o reconfig.o retry.o \
	  sconf.o server.o service.o shutdown.o \
	  signals.o special.o tcpint.o time.o udpint.o util.o


OPT=options.opt

OPT_SOURCE=options.c
OPT_HEADER=options.h
OPT_OBJECT=options.o

SOURCES		= $(SRCS) $(OPT_SOURCE)
HEADERS		= $(HDRS) $(OPT_HEADER)
OBJECTS		= $(OBJS) $(OPT_OBJECT)

INCLUDEDIR	= -I$(HOME)/.links/includes
#MANPATHDIR	= -I$(HOME)/.links/manpages	# path up to man{1,2,etc}
MANPATHDIR	= /usr/local/man
INSTALLDIR	= /usr/local/sbin


#
# You may modify the following variables but you probably don't need to.
#

PROGRAM		= $(NAME)
MANPROGSECTION	= 1
MANSUBSECTION	=				# like V,X,l
MANPROGFILE	= $(PROGRAM).man
MANPROGPAGE	= $(PROGRAM).$(MANPROGSECTION)$(MANSUBSECTION)
MANPROGDIR	= $(MANPATHDIR)/man$(MANPROGSECTION)
MANDATASECTION	= 5
MANDATANAMES	= conf log
MANDATADIR		= $(MANPATHDIR)/man$(MANDATASECTION)

MANFILES	= $(MANPROGFILE) $(PROGRAM).conf.man $(PROGRAM).log.man

CC		= cc			# used for compiler-specific options
CC_FLAGS	= $(DEBUG)		# used for generic options

XMODE		= -m 700		# mode for executables
FMODE		= -m 640		# mode for anything but executables
INSTALL		= install -c

LINT_FLAGS	= -hbux
PAGER		= less

CPP_DEFS	= $(VERSION_DEF) $(DEFS)

#
# The following variables do not need to be changed
#

VERSION_DEF	= -DVERSION=\"$(PROGRAM)\ Version\ $(VERSION)\"
CPP_FLAGS	= $(CPP_DEFS) $(INCLUDEDIR)
CFLAGS		= $(CPP_FLAGS) $(CC_FLAGS)

all: $(PROGRAM) itox

itox: itox.c
	$(CC) $(DEBUG) $(INCLUDEDIR) itox.c -o $@ $(LDFLAGS) -lsio -lmisc \
		-lstr $(OSLIBS)

$(PROGRAM): $(OBJECTS)
	$(CC) $(DEBUG) -o $@ $(OBJECTS) $(LDFLAGS) $(LIBS) $(OSLIBS) || rm -f $@

tags: $(HEADERS) $(SOURCES)
	ctags -w $(HEADERS) $(SOURCES)

checkout:

lint:
	lint $(LINT_FLAGS) $(CPP_FLAGS) $(MODULE) 2>&1 | $(PAGER)

lintall: $(OPT_HEADER)
	lint $(LINT_FLAGS) $(CPP_FLAGS) $(SOURCES) 2>&1 | $(PAGER)

LINT_IGNORE=RCSid|warning: possible pointer alignment problem|warning: argument op unused|warning: struct/union iovec never defined|warning: null effect|(sigprocmask|sigaction) multiply declared|argument code unused

lintq: $(OPT_HEADER)
	lint $(LINT_FLAGS) $(CPP_FLAGS) $(SOURCES) 2>&1 | egrep -v '$(LINT_IGNORE)' | $(PAGER)

clean:
	rm -f $(OBJECTS) $(PROGRAM) itox core

xclean: clean
	rm -f $(OPT_SOURCE) $(OPT_HEADER)

install: $(PROGRAM)
	$(INSTALL) $(XMODE) $(PROGRAM) $(INSTALLDIR)

install.man:
	if test "$(MANPROGDIR)" ; then \
		$(INSTALL) $(FMODE) $(MANPROGFILE) $(MANPROGDIR)/$(MANPROGPAGE) ;\
	fi
	if test "$(MANDATADIR)" ; then \
		for i in $(MANDATANAMES) ; do \
			name=$(PROGRAM).$$i ; \
			$(INSTALL) $(FMODE) $$name.man $(MANDATADIR)/$$name.$(MANDATASECTION);\
		done ;\
	fi

uninstall:
	a=`pwd` ; cd $(INSTALLDIR) ;\
	if test $$a != `pwd` ; then rm -f $(PROGRAM) ; fi
	a=`pwd` ; cd $(MANPROGDIR) ;\
	if test $$a != `pwd` ; then rm -f $(MANPROGPAGE) ; fi
	a=`pwd` ; cd $(MANDATADIR) ;\
	if test $$a != `pwd` ; then \
		for i in $(MANDATANAMES) ; do \
			rm -f $(PROGRAM).$$i.$(MANDATASECTION) ;\
		done ;\
	fi

#
# Distribution section
# This section contains the 2 targets for distribution support: dist, dirs
# "dist" checks out all files to be distributed
# "dirs" prints a list of directories to be included in the distribution.
# These directories should have a Makefile with a "dist" target
#
SUPPORT_FILES			= sample.conf itox.c BUG-REPORTS
DISTRIBUTION_FILES	= $(HDRS) $(SRCS) $(MANFILES) $(SUPPORT_FILES)
DIRS						=

dist1:

dist: dist1 $(OPT_SOURCE) $(OPT_HEADER)
	-co -q $(DISTRIBUTION_FILES)

dirs:
	@echo $(DIRS)

#
# This part of the file shows how to make $(OBJECTS) 
#



#
# Header file dependencies
#
addr.h: defs.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

builtin.h: defs.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

conf.h: service.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

int.h: server.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

parse.h: defs.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

sconf.h: defs.h log.h mask.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

server.h: defs.h service.h connection.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

service.h: defs.h sconf.h builtin.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

state.h: mask.h sconf.h conf.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

connection.h: mask.h service.h
	@if test -f $@ ; then touch $@ ; else echo $@ is missing ; exit 1 ; fi

#
# Object file dependencies
#
access.o: 		access.h addr.h connection.h service.h state.h
addr.o: 			addr.h defs.h
builtins.o: 	builtin.h config.h defs.h sconf.h server.h
child.o: 		attr.h config.h sconst.h server.h state.h $(OPT_HEADER)
conf.o: 			attr.h conf.h config.h defs.h service.h state.h 
confparse.o:	attr.h config.h conf.h defs.h parse.h sconst.h sconf.h state.h
connection.o:	connection.h service.h state.h
sconf.o:			addr.h attr.h defs.h sconf.h state.h
env.o:			attr.h defs.h sconf.h 
flags.o:			defs.h flags.h state.h
ident.o:			defs.h sconst.h server.h
init.o:			defs.h conf.h config.h state.h $(OPT_HEADER)
int.o:			config.h connection.h defs.h int.h server.h service.h
intcommon.o:	config.h defs.h int.h server.h service.h state.h 
internals.o:	config.h flags.h server.h service.h state.h
log.o:			access.h defs.h connection.h sconst.h server.h service.h
logctl.o:		config.h defs.h log.h service.h state.h
main.o:			service.h state.h $(OPT_HEADER)
msg.o:			config.h defs.h state.h $(OPT_HEADER)
nvlists.o:		defs.h sconf.h
parse.o:			addr.h attr.h conf.h defs.h parse.h service.h
parsesup.o:		defs.h parse.h
parsers.o:		addr.h config.h defs.h parse.h sconf.h
reconfig.o:		access.h conf.h config.h defs.h server.h service.h state.h
retry.o:			access.h config.h connection.h flags.h server.h state.h
server.o:		access.h config.h connection.h server.h state.h
service.o:		access.h attr.h config.h connection.h defs.h \
						server.h service.h state.h $(OPT_HEADER)
shutdown.o:		defs.h
signals.o:		config.h defs.h flags.h state.h
special.o:		builtin.h conf.h config.h connection.h \
						server.h sconst.h state.h $(OPT_HEADER)
tcpint.o:		access.h config.h defs.h int.h 
time.o:			defs.h
udpint.o:		access.h defs.h int.h
util.o:			config.h defs.h

