# Makefile for GNU Awk.
#
# Copyright (C) 1986, 1988-1993 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

prefix = Programmer:other
exec_prefix = $(prefix)
binprefix =
manprefix =

bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
mandir = $(prefix)/man/man1
manext = .1
infodir = $(prefix)/info

#	The provided "configure" is used to turn a config file (samples in
#	the "config" directory into commands to edit config.in into
#	a suitable config.h and to edit Makefile.in into Makefile.
#	To port GAWK, create an appropriate config file using the ones in
#	the config directory as examples and using the comments in config.in
#	as a guide.

CC = sc
SED = sed
WMERGE = wmerge
##MAKE_CC## CC = cc

PROFILE=	#-pg
DEBUG=		#-DMALLOCDEBUG #-DDEBUG #-DFUNC_TRACE #-DMPROF
LINKSTATIC=	#-Bstatic
WARN=		#-W -Wunused -Wimplicit -Wreturn-type -Wcomment	# for gcc only

# Parser to use on grammar - any one of the following will work
PARSER = bison -y
#PARSER = yacc
#PARSER = byacc

# Set LIBS to any libraries that are machine specific
LIBS = math=standard

# Cray 2 running Unicos 5.0.7
##MAKE_LIBNET## LIBS = -lnet


# Systems with alloca in /lib/libPW.a
##MAKE_ALLOCA_PW## LIBS = -lPW

# ALLOCA - only needed if you use bison
#	Set equal to alloca.o if your system is S5 and you don't have
#	alloca. Uncomment one of the rules below to make alloca.o from
#	either alloca.s or alloca.c.
#	This should have already been done automatically by configure.
#
#	Some systems have alloca in libPW.a, so LIBS=-lPW may work, too.
ALLOCA= ansialloca.o
##MAKE_ALLOCA_S## ALLOCA= alloca.o

VFLAGS=

# VMS POSIX, VAXC V3.2
##MAKE_VMS-Posix## VFLAGS = -UVMS -D__STDC__=0

# HP/Apollo running cc version 6.7 or earlier
##MAKE_Apollo## VFLAGS = -U__STDC__ -A run,sys5.3
##MAKE_Apollo## LIBS = -A sys,any

# SGI IRIX 4.0.5 cc flags
##MAKE_SGI## VFLAGS = -cckr

##MAKE_NeXT## VFLAGS = -DGFMT_WORKAROUND

CFLAGS = UNSIGNEDCHAR OPTIMIZE STACKEXTEND NOICONS
FLAGS = define=_STRICT_ANSI define=GAWK define=HAVE_CONFIG_H $(VFLAGS) $(DEBUG) $(PROFILE) $(WARN)
LDFLAGS = $(LINKSTATIC) $(PROFILE) NOICONS

.c.o:
	$(CC) $(CFLAGS) $(FLAGS) $<

# object files
AWKOBJS = ansimain.o ansieval.o ansibuiltin.o ansimsg.o ansiiop.o ansiio.o \
	ansifield.o ansiarray.o ansinode.o version.o ansimissing.o ansire.o \
	ansigetopt.o getopt1.o

ALLOBJS = $(AWKOBJS) ansiawktab.o

# GNUOBJS
#	GNU stuff that gawk uses as library routines.
GNUOBJS= ansiregex.o ansidfa.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

# rules to build gawk
gawk:	$(ALLOBJS) $(GNUOBJS) $(REOBJS)
	$(CC) link to gawk $(LDFLAGS) $(ALLOBJS) $(GNUOBJS) $(REOBJS) $(LIBS)

$(AWKOBJS) ansiregex.o ansidfa.o:	ansiawk.h dfa.h regex.h

ansigetopt.o:	getopt.h

getopt1.o:	getopt.h

ansimain.o: ansimain.c
ansimain.c: main.c main.ch patchlevel.h
	$(WMERGE) main.c main.ch ansimain.c

ansiawktab.o: ansiawktab.c
ansiawktab.c:	ansiawk.y
	$(PARSER) -v ansiawk.y
##MAKE_VMS-Posix## 	mv ytab.c awktab.c
##MAKE_VMS-Posix## dummy.awk_tab.target:
	$(SED) "/^extern char .malloc(), .realloc();$$/d" y.tab.c >ansiawktab.c
	delete y.tab.c y.output

ansiawk.y: awk.y awk.ych
	$(WMERGE) awk.y awk.ych ansiawk.y

ansiawktab.o:	ansiawk.h

config.h:	config.in config.hch
	$(WMERGE) config.in config.hch config.h
#	@echo You must provide a config.h!
#	@echo Run \"./configure\" to build it for known systems
#	@echo or copy config.in to config.h and edit it.; exit 1

install:	gawk
	copy gawk $(bindir)

# 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.


##MAKE_ALLOCA_S## alloca.o:	alloca.s
##MAKE_ALLOCA_S## 	/lib/cpp < alloca.s | $(SED) '/^#/d' > t.s
##MAKE_ALLOCA_S## 	as t.s -o alloca.o
##MAKE_ALLOCA_S## 	rm t.s

alloca.o:	alloca.c

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

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

clean:
	-delete \#?.(bak|o|lnk) ansi\#?

veryclean: clean
	-delete gawk

gawk.dvi:	gawk.texi
	copy support/texinfo.tex .
	tex gawk.texi; texindex gawk.??
	tex gawk.texi; texindex gawk.??
	tex gawk.texi
	rm -f texinfo.tex

gawk.info:	gawk.texi
	makeinfo gawk.texi

test:	gawk
	cd test; make -k

check:	test

ansiawk.h: awk.h awk.hch
	$(WMERGE) awk.h awk.hch ansiawk.h

ansimsg.o: ansimsg.c ansiawk.h
ansimsg.c: msg.c msg.ch
	$(WMERGE) msg.c msg.ch ansimsg.c

ansieval.o: ansieval.c ansiawk.h
ansieval.c: eval.c eval.ch
	$(WMERGE) eval.c eval.ch ansieval.c

ansibuiltin.o: ansibuiltin.c ansiawk.h
ansibuiltin.c: builtin.c builtin.ch
	$(WMERGE) builtin.c builtin.ch ansibuiltin.c

ansiiop.o: ansiiop.c ansiawk.h
ansiiop.c: iop.c iop.ch
	$(WMERGE) iop.c iop.ch ansiiop.c

ansiio.o: ansiio.c ansiawk.h
ansiio.c: io.c io.ch
	$(WMERGE) io.c io.ch ansiio.c

ansifield.o: ansifield.c ansiawk.h
ansifield.c: field.c field.ch
	$(WMERGE) field.c field.ch ansifield.c

ansiarray.o: ansiarray.c ansiawk.h
ansiarray.c: array.c array.ch
	$(WMERGE) array.c array.ch ansiarray.c

ansinode.o: ansinode.c ansiawk.h
ansinode.c: node.c node.ch
	$(WMERGE) node.c node.ch ansinode.c

ansimissing.o: ansimissing.c ansiawk.h
ansimissing.c: missing.c missing.ch
	$(WMERGE) missing.c missing.ch ansimissing.c

ansire.o: ansire.c ansiawk.h
ansire.c: re.c re.ch
	$(WMERGE) re.c re.ch ansire.c

ansigetopt.o: ansigetopt.c
ansigetopt.c: getopt.c getopt.ch
	$(WMERGE) getopt.c getopt.ch ansigetopt.c

ansiregex.o: ansiregex.c
ansiregex.c: regex.c regex.ch
	$(WMERGE) regex.c regex.ch ansiregex.c

ansidfa.o: ansidfa.c
ansidfa.c: dfa.c dfa.ch
	$(WMERGE) dfa.c dfa.ch ansidfa.c

ansialloca.o: ansialloca.c
ansialloca.c: alloca.c alloca.ch
	$(WMERGE) alloca.c alloca.ch ansialloca.c
