# Copyright (c) 1985 Sun Microsystems, Inc.
# Copyright (c) 1980 The Regents of the University of California.
# Copyright (c) 1976 Board of Trustees of the University of Illinois.
# All rights reserved.

# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by the University of California, Berkeley, the University of Illinois,
# Urbana, and Sun Microsystems, Inc.  The name of either University
# or Sun Microsystems may not be used to endorse or promote products
# derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.



# Configurable things
#
AWK = awk
MAKEINFO = makeinfo
# CFLAGS = -O -g -W -DDEBUG
CFLAGS = -O -g
CC = gcc

# Used only for making distributions.  If you don't have GNU tar,
# you must change the make command below in the `tarfile:' section.
TAR = tar

DVITOGHOSTSCRIPT = dvi2ps indent.dvi > indent.ps
CTAGS = etags
INSTALL = install

# Where to install things
prefix = /usr/local
bindir = $(prefix)/bin
infodir = $(prefix)/info


# Non-configurable -- do not change
#
SHELL =   /bin/sh
SRC =	  indent.c io.c lexi.c parse.c pr_comment.c args.c globs.c backup.c
OBJ =	  indent.o io.o lexi.o parse.o pr_comment.o args.o globs.o backup.o
HEADERS = indent.h sys.h version.h backup.h
MAN =	  indent.texinfo texinfo.tex
NOTES =   ChangeLog OChangeLog Projects

CONFIG = config.sh
CONFIG_OUTPUT = dirent_def.h

MANJUNK = indent.dvi indent.cp indent.cps indent.aux indent.dlog \
indent.fn indent.fns indent.ky indent.kys indent.log indent.pg   \
indent.pgs indent.toc indent.tp indent.tps indent.vr indent.vrs indent.ps 

# What to put in a distribution
TARFILES = ${SRC} Makefile ${MAN} indent.info ${HEADERS} ${NOTES} \
indent.gperf ${CONFIG}
RELEASEFILES =  RELEASE-NOTES README


# Make the program and documentation
#
all: indent indent.info

indent: ${OBJ}
	${CC} -o $@ ${CFLAGS} ${OBJ}

${OBJ}: indent.h sys.h Makefile
args.o: version.h Makefile
backup.o: backup.h sys.h ${CONFIG_OUTPUT}

${CONFIG_OUTPUT}: config.sh
	${SHELL} config.sh

tags: ${SRC}
	${CTAGS} -t ${SRC} ${HEADERS}
TAGS: tags


# Documents
#
indent.ps: indent.dvi
	${DVITOGHOSTSCRIPT}

indent.dvi: indent.toc
	tex indent.texinfo

indent.toc: ${MAN}
	tex indent.texinfo

indent.info: ${MAN}
	${MAKEINFO} indent.texinfo



# Installation of indent
#
install: all
	${INSTALL} -c indent ${bindir}/indent
	${INSTALL} -c -m 644 indent.info ${infodir}/indent


# Cleaning up
#
clean: mostlyclean
	rm -f ${MANJUNK} ${CONFIG_OUTPUT} TAGS .depend

# Clean up distribution and info file
realclean: clean
	rm -f *.BAK indent.info
	rm -f indent-*.tar*
	rm -rf indent-*

# Clean up the .o files, leaving the man stuff
mostlyclean:
	rm -f ${OBJ} core indent



# Create a distribution file
#
DISTDIR = indent-${VERSION}
TARFILE = indent-${VERSION}.tar
DISTFILE = ${TARFILE}.Z
AWKVERSION = ${AWK} '/define VERSION_STRING/ {printf "%s", \
                     substr($$NF, 1, length($$NF) - 1)}' version.h


dist: ${TARFILES}
	@export VERSION ; VERSION=`${AWKVERSION}` ; ${MAKE} tarfile
#	@unset VERSION

tar: dist

# NOTE: GNU tar has a compress option, -z, used below.  If you
# do not have GNU tar, replace the tar line below with the following
# two lines:
#	tar -c -h -f ${TARFILE} ${DISTDIR}
#	compress ${TARFILE}
tarfile:
	@test -f README-${VERSION} || (echo Missing file README-${VERSION}; exit 1)
	@test -f RELEASE-NOTES-${VERSION} || (echo Missing file RELEASE-NOTES-${VERSION}; exit 1)
	@echo Making compressed tar file, indent ${VERSION}
	@echo
	@rm -f README
	@ln -s README-${VERSION} README
	@rm -f RELEASE-NOTES
	@ln -s RELEASE-NOTES-${VERSION} RELEASE-NOTES
	@rm -rf ${DISTDIR}
	@rm -f ${DISTFILE}
	@mkdir ${DISTDIR}
	@cd ${DISTDIR} ; for i in ${TARFILES} ${RELEASEFILES} ; do ln -s ../$$i . ; done
	@${TAR} -c -v -h -z -f ${DISTFILE} ${DISTDIR}
	@rm -rf ${DISTDIR}

