# Makefile for GNU Awk.
#
# Copyright (C) 1986, 1988-1995 the Free Software Foundation, Inc.
# 
# This file is part of GAWK, the GNU implementation of the
# AWK Progamming Language.
# 
# GAWK 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 of the License, or
# (at your option) any later version.
# 
# GAWK 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 GAWK; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# User tunable macros -- CHANGE THESE IN Makefile.in RATHER THAN IN 
# Makefile, OR configure WILL OVERWRITE YOUR CHANGES

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

VPATH = @srcdir@
srcdir = @srcdir@

# Common prefix for machine-independent installed files.
prefix = /ade
# Common prefix for machine-dependent installed files.
exec_prefix = $(prefix)

# Directory to install executables in.
bindir = $(exec_prefix)/bin
# Directory to install libraries in.
libdir = $(exec_prefix)/lib
# Directory to install the Info files in.
infodir = $(prefix)/info
# Directory to install the man page in.
mandir = $(prefix)/man/man$(manext)
# Number to put on the man page filename.
manext = 1

# Program to install executables.
INSTALL_PROGRAM = @INSTALL_PROGRAM@
# Program to install data like man pages.
INSTALL_DATA = @INSTALL_DATA@
# Generic install program.
INSTALL = @INSTALL@

CC = @CC@
DEFS = @DEFS@
CFLAGS = @CFLAGS@

LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

YACC = @YACC@

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

# "-I." is needed to find config.h in the build directory.
.c.o:
	$(CC) -c -I. -I$(srcdir) $(DEFS) $(CFLAGS) $<

# object files
AWKOBJS = main.o eval.o builtin.o msg.o iop.o io.o field.o array.o \
	node.o version.o missing.o re.o getopt.o getopt1.o

ALLOBJS = $(AWKOBJS) awktab.o

# GNUOBJS
#	GNU stuff that gawk uses as library routines.
GNUOBJS= regex.o dfa.o $(ALLOCA)

# source and documentation files
SRC =	main.c eval.c builtin.c msg.c version.c \
	iop.c io.c field.c array.c node.c missing.c re.c getopt.c getopt1.c

ALLSRC= $(SRC) awktab.c

AWKSRC= awk.h awk.y $(ALLSRC) patchlevel.h protos.h config.in getopt.h

GNUSRC = alloca.c alloca.s dfa.c dfa.h regex.c regex.h

COPIES = missing/system.c missing/tzset.c \
	missing/memcmp.c missing/memcpy.c missing/memset.c \
	missing/random.c missing/strncasecmp.c missing/strchr.c \
	missing/strerror.c missing/strtod.c \
	missing/strftime.c missing/strftime.3 

SUPPORT = support/texindex.c support/texinfo.tex

DOCS= gawk.1 gawk.texi

TEXFILES= gawk.aux gawk.cp gawk.cps gawk.fn gawk.fns gawk.ky gawk.kys \
	   gawk.pg gawk.pgs gawk.toc gawk.tp gawk.tps gawk.vr gawk.vrs

MISC =	NEWS COPYING FUTURES Makefile.* PROBLEMS README* PORTS POSIX \
	mungeconf configure ACKNOWLEDGMENT LIMITATIONS INSTALL

OTHERS= pc/* atari/* vms/*

ALLDOC= gawk.dvi $(TEXFILES) gawk.info*

# Release of gawk.  There can be no leading or trailing white space here!
REL=2.15

all:	gawk

# rules to build gawk
gawk:	$(ALLOBJS) $(GNUOBJS) $(REOBJS)
	$(CC) -o gawk $(LDFLAGS) $(ALLOBJS) $(GNUOBJS) $(REOBJS) -lm $(LIBS)

$(AWKOBJS) regex.o dfa.o:	awk.h dfa.h regex.h

getopt.o:	getopt.h

getopt1.o:	getopt.h

main.o:	patchlevel.h

awktab.c:	awk.y
	@echo "expect 40 shift/reduce conflicts"
	$(YACC) -v $(srcdir)/awk.y
	@sed '/extern char.*malloc/d' <y.tab.c >awktab.c
	@rm y.tab.c

awktab.o:	awk.h

# On AmigaOS, there is no "native awk", so install gawk as both
# /bin/gawk and /bin/awk.

install:	gawk gawk.info
	$(INSTALL_PROGRAM) gawk $(bindir)/awk
	$(INSTALL_PROGRAM) gawk $(bindir)/gawk
	$(INSTALL_DATA) $(srcdir)/gawk.1 $(mandir)/gawk.$(manext)
	cd $(srcdir); for f in gawk.info*; \
	do $(INSTALL_DATA) $$f $(infodir)/$$f; done

uninstall:
	rm -f $(bindir)/gawk $(mandir)/gawk.$(manext) $(infodir)/gawk.info*

# ALLOCA: uncomment this if your system (notably System V boxen)
# does not have alloca in /lib/libc.a or /lib/libPW.a
#
# If your machine is not supported by the assembly version of alloca.s,
# use the C version which follows instead.  It uses the default rules to
# make alloca.o.
#
# One of these rules should have already been selected by running configure.


# auxiliary rules for release maintenance
lint:	$(ALLSRC)
	lint -hcbax $(FLAGS) $(ALLSRC)

xref:
	cxref -c $(FLAGS) $(ALLSRC) | grep -v '	/' >xref

clean:
	rm -rf gawk *.o core
	cd test && make clean

distclean:	clean
	rm -f Makefile *.orig *.rej */*.orig */*.rej awk.output gmon.out \
		make.out y.output config.h

mostlyclean:	clean

realclean:	distclean
	rm -f awktab.c $(ALLDOC)

cleaner:	clean
	rm -f gawk awktab.c Makefile config.h

clobber:	clean
	rm -f $(ALLDOC) gawk.log config.h

gawk.dvi:	gawk.texi
	cp $(srcdir)/support/texinfo.tex .
	tex $(srcdir)/gawk.texi; texindex gawk.??
	tex $(srcdir)/gawk.texi; texindex gawk.??
	tex $(srcdir)/gawk.texi
	rm -f texinfo.tex

gawk.info:	gawk.texi
	makeinfo -I$(srcdir) $(srcdir)/gawk.texi -o gawk.info

dist:	$(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $(COPIES) $(SUPPORT) distclean
	-rm -rf gawk-$(REL)*
	dir=gawk-$(REL).`gawk '{print $$3}' patchlevel.h` && \
	mkdir $$dir && \
	cp -p $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $$dir && \
	mkdir $$dir/missing && cp -p $(COPIES) $$dir/missing && \
	mkdir $$dir/atari && cp -p  atari/* $$dir/atari && \
	mkdir $$dir/pc && cp -p pc/* $$dir/pc && \
	mkdir $$dir/vms && cp -p vms/* $$dir/vms && \
	mkdir $$dir/config && cp -p config/* $$dir/config && \
	mkdir $$dir/support && cp -p support/* $$dir/support && \
	cp -pr test $$dir && \
	chmod -R a+r $$dir && \
	chmod -R a-w $$dir && \
	find $$dir -type d -exec chmod 755 {} ';' && \
	find $$dir -print | doschk && \
	tar -cf - $$dir | gzip > $$dir.tar.gz && \
	rm -fr $$dir

gawk-doc-$(REL).tar.gz:	gawk.info gawk.dvi gawk.1
	-rm -rf gawk-doc-$(REL) gawk-doc-$(REL).tar.gz
	-mkdir gawk-doc-$(REL)
	cp -p $(ALLDOC) gawk-doc-$(REL)
	groff -Tascii -man gawk.1 > gawk-doc-$(REL)/gawk.1.pr
	tar -cf - gawk-doc-$(REL) | gzip > gawk-doc-$(REL).tar.gz

gawk-ps-$(REL).tar.gz:	gawk.dvi gawk.1
	-rm -rf gawk-ps-$(REL) gawk-ps-$(REL).tar.gz
	-mkdir gawk-ps-$(REL)
	dvips -o gawk-ps-$(REL)/gawk.postscript gawk.dvi
	groff -man gawk.1 > gawk-ps-$(REL)/gawk.1.ps
	tar -cf - gawk-ps-$(REL) | gzip > gawk-ps-$(REL).tar.gz

release:	dist gawk-doc-$(REL).tar.gz gawk-ps-$(REL).tar.gz

test:	gawk
	cd test; make -k

check:	test

Makefile:	config.status $(srcdir)/Makefile.in
		$(SHELL) config.status

config.h:	stamp-config ;

stamp-config:	config.status $(srcdir)/config.h.in
		$(SHELL) config.status
		touch stamp-config

configure:	configure.in
		autoconf $(ACFLAGS)

config.h.in:	configure.in
		autoheader $(ACFLAGS)
