# 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
OBJ =	  indent.o io.o lexi.o parse.o pr_comment.o args.o globs.o
HEADERS = indent_globs.h version.h
MAN =	  indent.texinfo texinfo.tex
NOTES =   ChangeLog OChangeLog Projects RELEASE-NOTES README

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



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

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

${OBJ}: indent_globs.h Makefile
args.o: version.h

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} TAGS .depend

# Clean up distribution and old indented files as well
realclean: clean
	rm -f *.BAK
	rm -f indent-[0-9.]*.tar*
	rm -rf indent-[0-9.]*

# 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:
	@echo Making tar distribution, indent ${VERSION}...
	rm -rf ${DISTDIR}
	rm -f ${DISTFILE}
	mkdir ${DISTDIR}
	cd ${DISTDIR} ; for i in ${TARFILES} ; do ln -s ../$$i . ; done
	${TAR} -c -h -z -f ${DISTFILE} ${DISTDIR}
	rm -rf ${DISTDIR}

