# Makefile template for GNU indent
# $Id: makefile.in,v 1.35 2020/10/04 16:24:05 tom Exp $
# Copyright 1999-2019,2020 Thomas E. Dickey
# Copyright (C) 1994, Joseph Arceneaux.  All rights reserved
# Copyright (C) 1992, Free Software Foundation, Inc.
#
# This file is part of GNU indent.
#
# GNU indent is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU indent is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU indent; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

SHELL =   /bin/sh

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

THIS		= indent

x		= @EXEEXT@
o		= .@OBJEXT@
transform	= @program_transform_name@
PROG		= $(THIS)$x
actual_PROG	= `echo $(THIS)| sed '$(transform)'`$x

srcdir		= @srcdir@
VPATH		= @srcdir@

prefix		= @prefix@
exec_prefix	= @exec_prefix@
datarootdir	= @datarootdir@

CC		= @CC@

INSTALL		= @INSTALL@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@
INSTALL_SCRIPT	= @INSTALL_SCRIPT@
INSTALL_DATA	= @INSTALL_DATA@

AWK		= @AWK@
MAKEINFO	= makeinfo

# Used in making distributions.  GNU now uses the utility `gzip'
# form compaction.
TAR		= tar
ZIP		= gzip

DVITOGHOSTSCRIPT = dvi2ps indent.dvi > indent.ps
CTAGS		= @CTAGS@
ETAGS		= @ETAGS@
LINT		= @LINT@
LINT_OPTS	= @LINT_OPTS@

CPPFLAGS	= @CPPFLAGS@
CFLAGS		= @CFLAGS@
LDFLAGS		= @LDFLAGS@

# C compiler -D options.
DEFS		= @DEFS@

# Where to install indent and its documentation.
manext		= 1
bindir		= @bindir@
datadir		= @datadir@/tdindent
infodir		= @infodir@
mandir		= @mandir@/man$(manext)

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

BINDIR		= $(DESTDIR)$(bindir)
DATADIR		= $(DESTDIR)$(datadir)
INFODIR		= $(DESTDIR)$(infodir)
MANDIR		= $(DESTDIR)$(mandir)

SRC =	  indent.c io.c lexi.c parse.c comments.c args.c globs.c \
	  backup.c memcpy.c memmove.c
OBJ =	  indent$o io$o lexi$o parse$o comments$o args$o globs$o \
	  backup$o @LIBOBJS@
HEADERS = indent.h sys.h version.h backup.h
MAN =	  indent.texinfo texinfo.tex
NOTES =   ChangeLog OChangeLog Projects COPYING
VMSFILES= VMS-README gnuc-make.com vaxc-make.com
NTFILES= indent.mak

CONFIG = configure.in configure CONF-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 makefile.in ${MAN} ${HEADERS} \
           indent.info indent.html indent_foot.html  indent_toc.html \
           ${NOTES} indent.gperf ${CONFIG} ${VMSFILES} ${NTFILES} \
           NEWS README


# Make the program and documentation
#
all: $(PROG) indent.info

$(PROG): ${OBJ}
	@ECHO_LD@${CC} -o $(PROG) $(CFLAGS) ${LDFLAGS} ${OBJ}

.c$o:
	@RULE_CC@
	@ECHO_CC@$(CC) -c ${DEFS} ${CPPFLAGS} ${CFLAGS} $<

backup.o: backup.c backup.h sys.h indent.h makefile
globs.o: globs.c sys.h indent.h makefile

indent.o: indent.c indent.h sys.h makefile
args.o: args.c version.h indent.h sys.h makefile
io.o: io.c indent.h sys.h makefile
lexi.o: lexi.c indent.h sys.h makefile
parse.o: parse.c indent.h sys.h makefile
comments.o: comments.c indent.h sys.h makefile
memcpy.o: memcpy.c indent.h sys.h makefile

# Build source files which rely on tools not necessarily on target
gperf.c : indent.gperf
	echo "/* *INDENT-OFF* */" >$@
	gperf -LANSI-C -C -c -p -t -T -g -j1 -o -K rwd -N is_reserved indent.gperf |\
	sed \
		-e 's/{""}/{"", rw_none}/g' \
		-e 's/int hval = /unsigned hval =/' \
		-e 's/key = hash/key = (int)hash/' >>$@
	echo "/* *INDENT-ON* */" >>$@

indent.1 : indent.info
	perl make-man.pl indent.info >$@

# Build tag tables
tags: $(SRC) $(HEADERS)
	${CTAGS} ${SRC} ${HEADERS}
TAGS: $(SRC) $(HEADERS)
	${ETAGS} ${SRC} ${HEADERS}

lint: $(SRC) $(HEADERS)
	$(LINT) ${DEFS} $(CPPFLAGS) $(LINT_OPTS) $(OBJ:$o=.c)

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

indent.dvi: indent.toc
	tex ${srcdir}/indent.texinfo

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

indent.info: indent.texinfo
	${MAKEINFO} --no-split --no-number-footnotes --no-number-sections ${srcdir}/indent.texinfo

indent.html: indent.texinfo
	texi2html ${srcdir}/indent.texinfo

# Installation of indent
#
install \
install-bin :: $(BINDIR) $(PROG)
	${INSTALL_PROGRAM} $(PROG) $(BINDIR)/$(actual_PROG)

install \
install-info :: $(INFODIR)
	${INSTALL_DATA} ${srcdir}/indent.info $(INFODIR)/$(actual_PROG).info

install \
install-man :: $(MANDIR)
	${INSTALL_DATA} ${srcdir}/indent.1 $(MANDIR)/$(actual_PROG).1
	${INSTALL_DATA} ${srcdir}/tdindent.1 $(MANDIR)/tdindent.1
	$(SHELL) -c 'aliases=`cd $(srcdir)/scripts;echo *-indent *-compare`; cd $(MANDIR); for name in $$aliases; do echo ".so tdindent.1" >$$name.1;done'

install \
install-scripts :: $(BINDIR) $(DATADIR)
	sed -e s",=indent},=$(actual_PROG)}," -e s",=\.},=$(datadir)}," $(srcdir)/scripts/tdindent >tdindent.tmp
	$(INSTALL_SCRIPT) tdindent.tmp $(BINDIR)/tdindent
	rm -f tdindent.tmp
	$(INSTALL_SCRIPT) $(srcdir)/scripts/*-indent $(BINDIR)
	$(INSTALL_SCRIPT) $(srcdir)/scripts/*-compare $(BINDIR)
	$(INSTALL_DATA) $(srcdir)/scripts/*profile $(DATADIR)

$(BINDIR) \
$(DATADIR) \
$(INFODIR) \
$(MANDIR) :
	mkdir -p $@

uninstall \
uninstall-bin ::
	rm -f $(BINDIR)/$(actual_PROG)

uninstall \
uninstall-info ::
	rm -f $(INFODIR)/$(actual_PROG).info

uninstall \
uninstall-man ::
	rm -f $(MANDIR)/$(actual_PROG).1

uninstall \
uninstall-scripts ::
	rm -f $(BINDIR)/tdindent
	$(SHELL) -c 'for name in $(srcdir)/scripts/*-indent; do rm -f $(BINDIR)/`basename $$name`; done'
	$(SHELL) -c 'for name in $(srcdir)/scripts/*-compare; do rm -f $(BINDIR)/`basename $$name`; done'
	$(SHELL) -c 'for name in $(srcdir)/scripts/*-profile; do rm -f $(DATADIR)/`basename $$name`; done'

# Cleaning up
#

# Delete all files generated by building indent or making the manual
clean: mostlyclean
	-rm -f core*
	-rm -f ${MANJUNK}
	-rm -f case0*.[chyl] case0*.err

# Delete all files created by configuring or building indent
distclean: clean
	-rm -f TAGS tags
	-rm -f makefile indent-*.tar* config.status config.cache config.log
	-rm -rf indent-*

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

# Clean up tar files, indent-generated backup files, and indent
# subdirectories
realclean: distclean
	rm -f indent.info indent*.html

check:	$(PROG)
	$(SHELL) -c "INDENT_PROG=`pwd`/$(PROG) $(SHELL) $(srcdir)/testing/run_test.sh"

# Create a distribution file
#
DISTDIR = $(THIS)-${VERSION}
TARFILE = $(THIS)-${VERSION}.tar
DISTFILE = ${TARFILE}.gz
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, which used to be used below.
# However, GNU is now using `gzip' as its compaction utility, and this
# function has not yet been integrated into GNU `tar'.
#	tar -c -h -f ${TARFILE} ${DISTDIR}
#	compress ${TARFILE}
tarfile:
	@echo Making compressed tar file, $(THIS) ${VERSION}
	@echo
	@rm -rf ${DISTDIR}
	@rm -f ${DISTFILE}
	@mkdir ${DISTDIR}
	@cd ${DISTDIR} ; for i in ${TARFILES}  ; do ln -s ../$$i . ; done
	@${TAR} -c -v -h -f ${TARFILE} ${DISTDIR}
	${ZIP} --verbose --best ${TARFILE}
	@rm -rf ${DISTDIR}
