# @(#) Makefile 1.20 93/08/18 00:08:53

##############################################################################
#
# Site-specific customizations - please edit accordingly.
#

SHELL = /bin/sh
CC = cc
OPTIM = -O
#DEBUG = -g -DDEBUG

#
# Specify any system specific "cc" flags here.
#	WARNING - For HPUX see the rules section for building "fsinfo.o".
#
CDEFS =		# For most systems.
#CDEFS = -I.	# If your system does not have a <stdlib.h> header file.

#
# Specify any system specific libraries here.
#
#LIBS = -lmalloc		# Use this for systems with a good malloc library.
#LIBS =			# Use this if no special libraries needed.
#LIBS = -lmalloc -ldir	# Recent SCO XENIX - define USE_DIR_DIRENT in config.h.
#LIBS = -lmalloc -lx	# Old SCO XENIX - define USE_DIR_SYSNDIR in config.h.

#
# If you want "make install" to work, you must do one of two things:
# (1) create a script called "Install" in the current directory with
# the installation instructions, or (2) customize the following definitions:
#
# CP - Define as the command to install things in their place.
#
# BINDIR - Define as the pathname of the directory where the executables
#	and scripts go.
#
#	==> If you want to suppress the installation of executables
#	    and scripts then comment out the BINDIR definition.
#
# STRIP, CHOWNEXE, CHGRPEXE, CHMODEXE - Various commands that can be
#	performed on the executables and scripts after they are
#	installed in place.  (STRIP is not done for scripts, just
#	executables.)  If you do not want the associated command run,
#	then either stick a ":" at the front of it or define it to
#	something innocuous such as "true".
#
#
# MANDIR - Define as the pathname of the directory where manual page
#	source files go.
#
#	==> If you want to suppress the installation of manual
#	    page source files then comment out the MANDIR definition.
#
# MANSUF - Define as the suffix to put at the end of manual page source
#	files.
#
# CHOWNMAN, CHGRPMAN, CHMODMAN - Various commands that can be performed
#	on the man page sources after they are installed in place.  If
#	you do not want the associated command run, then either stick
#	a ":" at the front of it or define it to something innocuous
#	such as "true".
#
CP = cp
BINDIR = /usr/local/bin
STRIP = : strip
CHOWNEXE = chown bin
CHGRPEXE = chgrp bin
CHMODEXE = chmod 555
MANDIR = /usr/local/man/man1
MANSUF = 1
CHOWNMAN = chown bin
CHGRPMAN = chgrp bin
CHMODMAN = chmod 444

#
# End of site-specific customizations.
#
##############################################################################

CFLAGS = $(OPTIM) $(CDEFS) $(DEBUG)
LDFLAGS = $(DEBUG)
LINTFLAGS = $(CDEFS) -DNO_PROTOTYPE -DPTRTYPE=char

FILES = README du.c duentry.c fsinfo.c dusort.c \
	patchlevel.h config.h du.h stdlib.h \
	Makefile ngsizes du.1 dusort.1 ngsizes.1

all : du dusort ngsizes du.1 dusort.1 ngsizes.1

du : du.o duentry.o fsinfo.o
	$(CC) $(LDFLAGS) -o $@ du.o duentry.o fsinfo.o $(LIBS)

du.o : du.c config.h du.h patchlevel.h
duentry.o : duentry.c config.h du.h
fsinfo.o : fsinfo.c config.h du.h

#
# I've been told "fsinfo.c" breaks under HPUX with -D_POSIX_SOURCE and
# you need to use -D_HPUX_SOURCE instead.  If this applies to you, you
# might need to comment out the above rule for "fsinfo.o" and enable
# the following.
#
#fsinfo.o : fsinfo.c config.h du.h
#	$(CC) -D_HPUX_SOURCE $(OPTIM) $(DEBUG) fsinfo.c
#

dusort : dusort.o
	$(CC) $(LDFLAGS) -o $@ dusort.o $(LIBS)

dusort.o : dusort.c

clean :
	rm -f du dusort *.o a.out core *.lint
	-if test -d SCCS ; then sccs clean && sccs get Makefile ; fi

lint : du dusort
	lint $(LINTFLAGS) du.c duentry.c fsinfo.c $(LIBS) >du.lint
	lint $(LINTFLAGS) dusort.c $(LIBS) >dusort.lint

install : all
	-test ! -f Install -a -f SCCS/s.Install && sccs get Install
	-if test -f Install ; then \
		( set -x ; sh Install -$(MAKEFLAGS) ) ; \
	else \
		if test "X$(BINDIR)" != X -a -d "$(BINDIR)" ; then \
			( set -x ; $(MAKE) -$(MAKEFLAGS) install_bin ) ; \
		fi ; \
		if test "X$(MANDIR)" != X -a -d "$(MANDIR)" ; then \
			( set -x ; $(MAKE) -$(MAKEFLAGS) install_man ) ; \
		fi ; \
	fi

install_bin : $(BINDIR)/du $(BINDIR)/dusort $(BINDIR)/ngsizes

install_man : $(MANDIR)/du.$(MANSUF) $(MANDIR)/dusort.$(MANSUF) \
		$(MANDIR)/ngsizes.$(MANSUF)

$(BINDIR)/du : du
	rm -f $@
	$(CP) $? $@
	$(STRIP) $@
	$(CHMODEXE) $@ ; $(CHGRPEXE) $@ ; $(CHOWNEXE) $@

$(BINDIR)/dusort : dusort
	rm -f $@
	$(CP) $? $@
	$(STRIP) $@
	$(CHMODEXE) $@ ; $(CHGRPEXE) $@ ; $(CHOWNEXE) $@

$(BINDIR)/ngsizes : ngsizes
	rm -f $@
	$(CP) $? $@
	$(STRIP) $@
	$(CHMODEXE) $@ ; $(CHGRPEXE) $@ ; $(CHOWNEXE) $@

$(MANDIR)/du.$(MANSUF) : du.1
	rm -f $@
	$(CP) $? $@
	$(CHMODMAN) $@ ; $(CHGRPMAN) $@ ; $(CHOWNMAN) $@

$(MANDIR)/dusort.$(MANSUF) : dusort.1
	rm -f $@
	$(CP) $? $@
	$(CHMODMAN) $@ ; $(CHGRPMAN) $@ ; $(CHOWNMAN) $@

$(MANDIR)/ngsizes.$(MANSUF) : ngsizes.1
	rm -f $@
	$(CP) $? $@
	$(CHMODMAN) $@ ; $(CHGRPMAN) $@ ; $(CHOWNMAN) $@


shar : du.shar

du.shar : $(FILES)
	shar $(FILES) > $@


#
# yeah - go ahead and comment this out if it's creating problems
#
$(FILES) Install :
	sccs get $@

sccs : $(FILES) Install

