#
# CaSU Makefile
#
# Version: 3.3.3, 940421
# Author:  Luke Mewburn <lm@rmit.edu.au>
#


#### Start of system configuration section. ####

srcdir = @srcdir@
VPATH = @srcdir@

# Compiler related directives. If necessary, change to suit.

CC = @CC@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
LN = @LN_S@

#
# Defines currently available. Add to DEFS if necessary (if configure
# doesn't get it right)
#
# STDC_HEADERS=1	if the system's got full ANSI headers.
# HAVE_STDLIB_H=1	if <stdlib.h> exists.
# HAVE_PATHS_H=1	if <paths.h> exists.
# HAVE_UNISTD_H=1	if <unistd.h> exists.
# uid_t=int		if <sys/types.h> doesn't have uid_t.
# gid_t=int		if <sys/types.h> doesn't have gid_t.
# mode_t=int		if <sys/types.h> doesn't have mode_t.
# size_t=int		if <sys/types.h> doesn't have size_t.
# const=		if the compiler doesn't grok `const'.
# NEED_NETDB_H=1	if MAXHOSTNAMELEN is defined in <netdb.h>.
# TTY_RESTRICTED=1	if there are no world write permissions to ttys,
#			so `to' must be setgid, and mask is 020 not 022.
# USE_GETPWENT=1	flon has 2 ways of getting passwd information:
#			a) use getpwent(), or b) use custom code.
#			The former is faster when /etc/passwd has some
#			form of database caching, otherwise the custom
#			code is usually faster.
# HAVE_UTMPX_H=1	if <utmpx.h> & related getutx*() funcs exist
#			(SVR4 & Solaris 2.)
# HAVE_UT_TYPE=1	struct utmp has ut_type (usually a SysV system.)
# HAVE_UT_HOST=1	struct utmp has ut_host (usually a BSD system.)
#			Note that SVR4/Solaris 2 does, but in struct utmpx.
# HAVE_STRERROR=1	if strerror() exists.
# MALLOC_DECL=1		if malloc() is declared in <stdlib.h>.
# OPEN_DECL=1		if open() is declared in <fcntl.h>.
# READ_DECL=1		if read() is declared in <unistd.h>.
# HAVE_GETHOSTNAME=1	if gethostname() exists (check -lnsl & -lsocket.)
# HAVE_SYS_UTSNAME_H=1	if <sys/utsname.h> exists, and using uname().
# HAVE_UNAME=1		if uname() exists, but NOT gethostname().
# GETHOSTNAME_DECL=1	if gethostname() is declared in <unistd.h>.
#

DEFS = @DEFS@
LIBS = @LIBS@

CFLAGS = -O
#CFLAGS = -pipe -Wall -O		# gcc <2.0
#CFLAGS = -pipe -Wall -O2		# gcc 2.0+

LDFLAGS =


# Manual formatting directives - if necessary, change to suit.
ROFF = @ROFF@
TBL = @TBL@


# Destination directories & files

prefix = /usr/local
exec_prefix = $(prefix)
binprefix =
manprefix =
catprefix =

bindir = $(exec_prefix)/bin
libdir = /etc
mandir = $(prefix)/man/man1
manext = 1
catdir = $(prefix)/cat/cat1
catext = 0

# Set who_prog to empty if you don't want flon linked to who
#who_prog = who
who_prog =

# Group to install `to' setgid to - if empty, don't setgid.
to_group = @TO_GRP@


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


SHELL = /bin/sh

LSRCS =	various.c getutent.c
FSRCS =	fileio.c main.c init.c print.c qsort.c bsearch.c
TSRCS =	to.c
LOBJS =	various.o @LIBOBJS@
FOBJS =	fileio.o main.o init.o print.o qsort.o bsearch.o $(LOBJS)
TOBJS =	to.o $(LOBJS)
SRCS =	$(FSRCS) $(TSRCS) $(LSRCS)
OBJS =	$(FOBJS) $(TOBJS) $(LOBJS)

HDRS = casu.h patchlevel.h

DISTFILES = $(SRCS) $(HDRS) COPYING ChangeLog Makefile.in \
	    INSTALL README __TODO__ TO.rof FLON.rof \
	    eg.friends eg.torc tags configure.in configure NEWS


all: @PROGS@

$(OBJS):	$(HDRS)

.c.o:
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(DEFS) -I$(srcdir) $<

install: all
	$(INSTALL_PROGRAM) flon $(bindir)/$(binprefix)flon
	if test -n "$(who_prog)"; then \
	    rm -f $(bindir)/$(binprefix)$(who_prog); \
	    $(LN) $(bindir)/$(binprefix)flon $(bindir)/$(binprefix)$(who_prog);\
	fi
	$(INSTALL_PROGRAM) to $(bindir)/$(binprefix)to
	if test -n "$(to_group)"; then \
	    echo "Installing _to_ setgid to group $(to_group)"; \
	    chgrp $(to_group) $(bindir)/$(binprefix)to; \
	    chmod g+s $(bindir)/$(binprefix)to; \
	fi

install.man:
	$(INSTALL_DATA) $(srcdir)/FLON.rof $(mandir)/$(manprefix)flon.$(manext)
	$(INSTALL_DATA) $(srcdir)/TO.rof $(mandir)/$(manprefix)to.$(manext)

install.catman:	catman
	$(INSTALL_DATA) $(srcdir)/flon.0 $(catdir)/$(catprefix)flon.$(catext)
	$(INSTALL_DATA) $(srcdir)/to.0 $(catdir)/$(catprefix)to.$(catext)


flon: $(FOBJS)
	$(CC) $(LDFLAGS) $(FOBJS) $(LIBS) -o $@
	if test -n "$(who_prog)"; then \
	    rm -f $(who_prog); \
	    $(LN) $@ $(who_prog); \
	fi

to: $(TOBJS)
	$(CC) $(LDFLAGS) $(TOBJS) $(LIBS) -o $@


catman:	flon.0 to.0

flon.0: FLON.rof
	if test -n "$(ROFF)"; then \
	    $(TBL) FLON.rof | $(ROFF) > $@; \
	else \
	    cp FLON.rof $@; \
	fi

to.0: TO.rof
	if test -n "$(ROFF)"; then \
	    $(TBL) TO.rof | $(ROFF) > $@; \
	else \
	    cp TO.rof $@; \
	fi

inctree:
	inctree $(DEFS) $(SRCS)

tags: $(SRCS)
	ctags $(SRCS)

clean:
	rm -f $(TOBJS) $(FOBJS) core* mon.out gmon.out

mostlyclean: clean

distclean: clean
	rm -f Makefile config.status @PROGS@ $(who_prog)

realclean: distclean
	rm -f tags flon.0 to.0

dist:	$(DISTFILES)
	echo `pwd` | sed 's|.*/||' > .fname
	rm -rf `cat .fname`
	mkdir `cat .fname`
	ln $(DISTFILES) `cat .fname`
	tar -zcf `cat .fname`.tar.gz `cat .fname`
	rm -rf `cat .fname` .fname

distshar: $(DISTFILES)
	echo `pwd` | sed 's|.*/||' > .fname
	rm -rf `cat .fname`
	mkdir `cat .fname`
	ln $(DISTFILES) `cat .fname`
	shar -a -n `cat .fname` -s 'lm@rmit.edu.au (Luke Mewburn)' -c \
		-L 64 -o `cat .fname`.sha `cat .fname`
	rm -rf `cat .fname` .fname


# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:
