# Descrip.MMS -- Makefile for building GNU Awk on VMS with VAXC and MMS.
#
#	18-FEB-1994 06:58
#
#	This version was written by Hunter Goatley <goathunter@WKU.EDU>.
#	It was taken from GAWK's DESCRIP.MMS and modified to work with
#	Matt Madison's MMK and MMS under OpenVMS AXP.  Additional automatic
#	selection of qualifiers, etc., was added.
#
#
# usage:
#  $ MMS /Description=[.vms]Descrip.MMS gawk
#
# gawk.exe :
#	You'll need to modify this Makefile to use gcc or vaxc v2.x rather
#	than vaxc v3.x.  Change the CFLAGS macro definition (move '#' from
#	beginning of 2nd alternative to beginning of 1st), and also perhaps
#	enable the following ".first" rule and its associated action.  For
#	GNU C, change the LIBS macro definition.
#
# awktab.c :
#	If you don't have bison but do have VMS POSIX or DEC/Shell,
#	change the PARSER and PASERINIT macros to use yacc.  If you don't
#	have either yacc or bison, you'll have to make sure that the
#	distributed version of "awktab.c" has its modification date later
#	than the date of "awk.y", so that MMS won't try to build that
#	target.  If you use bison and it is already defined system-wide,
#	comment out the PARSERINIT definition.
#
# install.help :
#	You can make the target 'install.help' to load the VMS help text
#	into a help library.  Modify the HELPLIB macro if you don't want
#	to put entry into the regular VMS library.  (If you use an alternate
#	help library, it must already exist; this target won't create it.)
#
# gawk.dvi :
#	If you have TeX, you can make the target 'gawk.dvi' to process
#	_The_GAWK_Manual_ from gawk.texi.  You'll need to use a device
#	specific post-processor on gawk.dvi in order to get printable data.
#

.IFDEF EXE			#If EXE is not defined, then supply defaults.
.ELSE
EXE = .EXE
OBJ = .OBJ
OPT = .OPT
OLB = .OLB
.ENDIF

# location of the VMS-specific files, relative to the 'main' directory
VMSDIR	= [.vms]
MAKEFILE = $(VMSDIR)HUNTER.MMS

# debugging &c		!'ccflags' is an escape to allow external compile flags
#CCFLAGS = /noOpt/Debug

# work within the main directory, even when handling files in [.vms]
#	note: use 2nd variant for either VAX C V2.x or for GNU C
CFLAGS	= /Include=[]/Object=[]$(MMS$TARGET)/Opt=noInline/Define=("GAWK","HAVE_CONFIG_H") $(CCFLAGS)
#CFLAGS	= /Include=([],$(VMSDIR))/Object=[]/Define=("GAWK","HAVE_CONFIG_H") $(CCFLAGS)

# uncomment this for GNU C
#CC	= gcc
# beta VAX/VMS -> Alpha/VMS cross-compiler
#CC	= gemcc/Standard=VAXC/G_Float
# Alpha/VMS
.IFDEF __ALPHA__
CC	= cc/Standard=VAXC/G_Float
.ENDIF

# uncomment these two lines for GNU C _if_ it's not installed system-wide
#.first		!compiler init, needed if there's no system-wide setup
#	set command gnu_cc:[000000]gcc

# uncomment these three lines for VAX C V2.x
#.first		!compiler init, find all #include files
#	define/nolog vaxc$library sys$library:,sys$disk:$(VMSDIR)
#	define/nolog c$library [],$(VMSDIR)
#!(it appears that if vaxc$library is defined, then the /Include
#! qualifier is ignored, making a c$library definition essential)

# run-time libraries; use the 2nd one for GNU C
#LIBS	= sys$share:vaxcrtl.exe/Shareable
#LIBS	= gnu_cc:[000000]gcclib.olb/Library,sys$library:vaxcrtl.olb/Library
LIBS	=	# DECC$SHR instead of VAXCRTL; for Alpha/VMS (or VMS V6.x?)

.IFDEF __ALPHA__
LIBS	=
.ELSE
.IFDEF GCC
LIBS	= gnu_cc:[000000]gcclib.olb/Library,sys$library:vaxcrtl.olb/Library
.ELSE
LIBS	= sys$share:vaxcrtl.exe/Shareable
.ENDIF
.ENDIF

LINKFLAGS = $(LINKFLAGS)/NOTRACE

PARSER	= bison
PARSERINIT = set command gnu_bison:[000000]bison
#PARSER	= yacc
#PARSERINIT = yacc := posix/run/path=posix """/bin/yacc"
#PARSERINIT = yacc := $shell$exe:yacc

# this is used for optional target 'install.help'
HELPLIB = sys$help:helplib.hlb
#HELPLIB = sys$help:local.hlb

#
########  nothing below this line should need to be changed  ########
#

# ALLOCA
ALLOCA	= alloca$(OBJ)

# object files
AWKOBJS = main$(OBJ),eval$(OBJ),builtin$(OBJ),msg$(OBJ),iop$(OBJ),io$(OBJ),\
	field$(OBJ),array$(OBJ),node$(OBJ),version$(OBJ),missing$(OBJ),re$(OBJ),\
	getopt$(OBJ),getopt1$(OBJ)

ALLOBJS = $(AWKOBJS),awktab$(OBJ)

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

# VMSOBJS
#	VMS specific stuff
VMSCODE = vms_misc$(OBJ),vms_popen$(OBJ),vms_fwrite$(OBJ),vms_args$(OBJ),\
	vms_gawk$(OBJ),vms_cli$(OBJ)
VMSCMD	= gawk_cmd$(OBJ)			# built from .cld file
VMSOBJS = $(VMSCODE),$(VMSCMD)

VMSSRCS = $(VMSDIR)vms_misc.c,$(VMSDIR)vms_popen.c,$(VMSDIR)vms_fwrite.c,\
	$(VMSDIR)vms_args.c,$(VMSDIR)vms_gawk.c,$(VMSDIR)vms_cli.c
VMSHDRS = $(VMSDIR)vms.h,$(VMSDIR)fcntl.h,$(VMSDIR)varargs.h,$(VMSDIR)unixlib.h
VMSOTHR = $(VMSDIR)Descrip.MMS,$(VMSDIR)vmsbuild.com,$(VMSDIR)version.com,\
	$(VMSDIR)gawk.hlp

# Release of gawk
REL=2.15
PATCHLVL=4

# dummy target to allow building "gawk" in addition to explicit "gawk$(EXE)"
gawk : gawk$(EXE)
	write sys$output " GAWK "

# rules to build gawk
gawk$(EXE) : GAWK$(OLB)($(ALLOBJS),$(GNUOBJS),$(VMSOBJS)),gawk$(OPT)
	$(LINK) $(LINKFLAGS) gawk$(OPT)/options

gawk$(OPT) : $(MAKEFILE)			# create linker options file
	open/write opt gawk$(OPT)		! ~ 'cat <<close >gawk$(OPT)'
	write opt "! GAWK -- Gnu AWK"
      @ write opt "GAWK$(OLB)/INCLUDE=main/LIBRARY"
      @ write opt "$(LIBS)"
      @ write opt "psect_attr=environ,noshr        !extern [noshare] char **"
      @ write opt "stack=48        !preallocate more pages (default is 20)"
      @ write opt "iosegment=128   !ditto (default is 32)"
	write opt "identification=""V$(REL).$(PATCHLVL)"""
	close opt

vms_misc$(OBJ)	: $(VMSDIR)vms_misc.c
vms_popen$(OBJ)	: $(VMSDIR)vms_popen.c
vms_fwrite$(OBJ)	: $(VMSDIR)vms_fwrite.c
vms_args$(OBJ)	: $(VMSDIR)vms_args.c
vms_gawk$(OBJ)	: $(VMSDIR)vms_gawk.c
vms_cli$(OBJ)	: $(VMSDIR)vms_cli.c
dfa$(OBJ)		: awk.h config.h dfa.h
regex$(OBJ)	: awk.h config.h regex.h
getopt$(OBJ)	: getopt.h
main$(OBJ)	: patchlevel.h
awktab$(OBJ)	: awktab.c awk.h

$(VMSCODE)	: awk.h config.h $(VMSDIR)vms.h
$(AWKOBJS)	: awk.h config.h

# bison or yacc required
awktab.c	: awk.y		# foo.y :: yacc => y[_]tab.c, bison => foo_tab.c
     @- if f$search("ytab.c")	.nes."" then  delete ytab.c;*	 !POSIX yacc
     @- if f$search("y_tab.c")	.nes."" then  delete y_tab.c;*	 !DEC/Shell yacc
     @- if f$search("awk_tab.c").nes."" then  delete awk_tab.c;* !bison
      - $(PARSERINIT)
	$(PARSER) $(YFLAGS) $<
     @- if f$search("ytab.c")	.nes."" then  rename/new_vers ytab.c  $@
     @- if f$search("y_tab.c")	.nes."" then  rename/new_vers y_tab.c $@
     @- if f$search("awk_tab.c").nes."" then  rename/new_vers awk_tab.c $@

config.h	: [.config]vms-conf.h
	copy $< $@

# Alloca - C simulation
alloca$(OBJ)	: alloca.c
	$(CC) $(CFLAGS) /define=("STACK_DIRECTION=(-1)","exit=vms_exit") $<

$(VMSCMD)	: $(VMSDIR)gawk.cld
	set command $(CLDFLAGS)/object=$@ $<

# special target for loading the help text into a VMS help library
install.help	: $(VMS)gawk.hlp
	library/help $(HELPLIB) $< /log

# miscellaneous other targets
tidy :
      - if f$search("*.*;-1").nes."" then  purge
      - if f$search("[.*]*.*;-1").nes."" then  purge [.*]

clean :
      - delete *$(OBJ);*,gawk$(OPT);*

spotless : clean tidy
      - delete gawk.dvi;*,gawk$(EXE);*,[.support]texindex$(EXE);*

#
# build gawk.dvi from within the 'support' subdirectory
#
gawk.dvi : [.support]texindex$(EXE) gawk.texi
      @ set default [.support]
      @ copy/nolog [-]gawk.texi []
      @ write sys$output " Warnings from TeX are expected during the first pass"
	TeX gawk.texi
	mcr []texindex gawk.cp gawk.fn gawk.ky gawk.pg gawk.tp gawk.vr
      @ write sys$output " Second pass"
	TeX gawk.texi
	mcr []texindex gawk.cp gawk.fn gawk.ky gawk.pg gawk.tp gawk.vr
      @ write sys$output " Third (final) pass"
	TeX gawk.texi
      @ purge
      @ delete/nolog gawk.texi,gawk.lis;,.aux;,gawk.%%;,.cps;,.fns;,.kys;,.pgs;,.toc;,.tps;,.vrs;
      @ rename/new_vers gawk.dvi [-]*.*
      @ set default [-]

[.support]texindex$(EXE) : [.support]texindex.c,[.support]texindex$(OPT)
      @ set default [.support]
	$(CC)/OBJECT=texindex$(OBJ)/noOpt/noList/Define=("lines=tlines") texindex.c
	$(LINK)/EXEC=texindex$(EXE)/noTrace/noMap texindex$(OPT)/OPTIONS
      @ delete/nolog texindex$(OBJ);*
      @ set default [-]

[.support]texindex$(OPT) :
	@ open/write opt $(MMS$TARGET)
	@ write opt "TEXINDEX$(OBJ)"
	@ write opt "$(LIBS)"
	@ close opt

#eof
