#*****************************************************************
#**                                                             **
#**             (C) Copyright 1992 the Regents of the           **
#**        University of California.  All Rights Reserved.      **
#**                                                             **
#**        This work was produced under the sponsorship of      **
#**         the U.S. Department of Energy.  The Government      **
#**                retains certain rights therein.              **
#**                                                             **
#**                         Written by                          **
#**         Distributed Programming Environments Project        **
#**           Computer Software and Networking Division,        **
#**                   Livermore Computer Center,                **
#**            Lawrence Livermore National Laboratory           **
#**                                                             **
#*****************************************************************

# 	sccsid:		"@(#)Makefile	1.36 12/4/92 08:27:59 LLNL "

#
#	Make ELROS preprocessor
#

# The following macros need to be defined appropriately:
#
#   RO_RUNTIME_DIR - ELROS runtime directory
#   RO_SWITCHES - C compilation flags and options

include ../Make.Defaults


#
# Local macros
#
YACC=	/Gondor/usd/branstet/bin/yacctree -dvl

LEX=	/usr/CC/sun3/lex++

CFLAGS=	$(RO_SWITCHES) -I$(INCLPATH)

#
# Paths and files
#
INCLPATH=	$(RO_RUNTIME_DIR)/include
I	=	$(INCLPATH)/elros/

IDHDR	= 	symtab.h keytab.h
PNHDR	=	pnode.h
OBJHDR	=	gen_code.h abs.h argument.h list.h $(I)typeinfo.h $(I)typetags.h
STDHDR	=	$(OBJHDR) decls.h misc.h 

YFILES	=	header.y params.y ispec.y ansi.y elros.y tail.y 

SCANFILES=	scan.l y.tab.hh abs.h decls.h   \
		pnode.h misc.h list.h keytab.h symtab.h \
		$(I)typeinfo.h

OFILES	=	symtab.$(OSUFFIX) keytab.$(OSUFFIX) actions.$(OSUFFIX)

OTHERS	=	gen_code.$(OSUFFIX) gen_stype.$(OSUFFIX) gen_gtype.$(OSUFFIX) \
		argument.$(OSUFFIX)

FRONTEND=	abs.$(OSUFFIX) list.$(OSUFFIX)            

ALL_FILES=	parser.$(OSUFFIX) scan.$(OSUFFIX) $(OFILES) $(FRONTEND) $(OTHERS)

DISTFILES=	README Makefile \
		yaccdone \
		epp.l scan.l \
		epp.y ansi.y elros.y header.y ispec.y params.y tail.y \
		y.tab.h y.tab.hh \
		abs.h argument.h c_varieties.h decls.h gen_code.h \
		keytab.h list.h misc.h pnode.h symtab.h \
		abs.C actions.C argument.C gen_code.C gen_gtype.C gen_stype.C \
		keytab.C list.C parser.C scan.C symtab.C

#
#                           -- R U L E S --
#
# This file makes a new version of epp.  LLNL uses a C++ compatible version
# of yacc.  A "tree" version of the parser is built if the yacc output is 
# compiled with "-DELROS_DEBUG".  Use "setenv YYDEBUG 6" to see a 
# pretty-print version of this tree if desired for debugging.
# 
# The target yaccdone is built first because we need the y.tab.h file for 
# lots of other compiles.  Also, for the sake of simplicity, everything 
# depends on the $(OBJHDR) set of files.
#
#                    ! !    C A U T I O N    ! !
#
# If you ever touch the y.tab.h file directly, this Makefile will not
# notice that you've done so, and you may get different token sets in
# your different .o files. touching y.tab.h is DISCOURAGED.
#
# The same is true for scan.l and yaccdone - touching them will 
# confuse this makefile, and you must "make clean" and start over
#
# When porting these files to a new site, you should not need to rerun the
# yacc and lex parts of this Makefile, and we try to touch the files when
# building a distribution tape to guarantee this.
#

#
# Targets
#
all:	showenv newepp
	@$(ECHOTEXT) $(BORDER)
	@$(ECHOTEXT) "Preprocessor is up to date"
	@$(ECHOTEXT) $(BORDER)

showenv:
	@$(ECHOTEXT)
	@$(ECHOTEXT) $(BORDER)
	@$(ECHOTEXT) "Building new preprocessor"
	@$(ECHOTEXT)
	@$(ECHOTEXT) "RO_RUNTIME_DIR=$(RO_RUNTIME_DIR)"
	@$(ECHOTEXT) "RO_SWITCHES=$(RO_SWITCHES)"
	@$(ECHOTEXT) $(BORDER)
	@$(ECHOTEXT)

libback: 
	cd $(RO_RUNTIME_DIR); make newlibback
	@$(ECHOTEXT)

newepp:	libback epp

epp:	yaccdone $(ALL_FILES) $(LIBBACK)
	$(CPLUSPLUSLD) -o epp $(ALL_FILES) $(LDLIBBACK) $(CPLUSPLUSLIBS)

#
#  These are the rules that run the appropriate yacc.  This needs to happen
#  before any of the builds that use the y.tab.h file containing the
#  token defs and the union for the yacc lval stack.
#
#  Note: running yacc will produce 6 shift-reduce warnings, which are
#  normal and can be ignored.

yaccdone: $(YFILES)
	$(RM) epp.y
	$(CAT) $(YFILES) > epp.y
	@$(ECHOTEXT) "Ignore 6 shift-reduce warnings from yacc"
	$(YACC) epp.y
	$(MV) y.tab.c parser.C
	-$(IFCMP) y.tab.h y.tab.hh $(IFSTATUS); \
		$(THEN) $(ECHOTEXT) "y.tab.hh not updated"; \
		$(ELSE) $(CP) y.tab.h y.tab.hh;$(ECHOTEXT) "y.tab.hh updated"; \
	$(FI)
	$(TOUCH) yaccdone

#
#  These rules make the scanner, depending upon the presence of 
#  yaccdone, from the rules above.
#
#  We need to define SILENT_SCAN in the epp.l file so that
#  the lexer will not interfere with the tree-drawing when yaccdone
#  exists.
#

scan.l:	epp.l
	$(RM) scan.l
	@$(ECHOTEXT) "The scanner will be silent"
	$(SED) "s.SEDGROKSTHISLINEDURINGMAKE.#define SILENT_SCAN." epp.l > scan.l

scan.C:	$(SCANFILES)
	$(LEX) scan.l
	$(MV) lex.yy.c scan.C

scan.$(OSUFFIX):	scan.C $(STDHDR) $(IDHDR) $(PNHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) scan.C

#
# Everything else
#

parser.$(OSUFFIX):	parser.C $(STDHDR) $(IDHDR) $(PNHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) parser.C

abs.$(OSUFFIX):	abs.C $(STDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) abs.C

list.$(OSUFFIX):	list.C $(STDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) list.C

gen_code.$(OSUFFIX):gen_code.C $(STDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) gen_code.C

gen_stype.$(OSUFFIX):	gen_stype.C $(STDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) gen_stype.C

gen_gtype.$(OSUFFIX):	gen_gtype.C $(STDHDR) $(I)typetags.h
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) gen_gtype.C

argument.$(OSUFFIX):	argument.C $(STDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) argument.C

misc.$(OSUFFIX):	misc.C $(STDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) misc.C

symtab.$(OSUFFIX):	symtab.C $(STDHDR) $(PNHDR) $(IDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) symtab.C

keytab.$(OSUFFIX):	keytab.C $(STDHDR) keytab.h y.tab.hh
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) keytab.C

actions.$(OSUFFIX):	actions.C $(STDHDR) $(PNHDR) $(IDHDR)
	$(CPLUSPLUS) $(COPTS) $(CFLAGS) actions.C

#
#  Housekeeping targets
#
new:	clean
	$(RM) epp

clean:
	$(RM) *.$(OSUFFIX)

#
# For the "package" target, the following macro must be defined as a command
# line argument.
#
#   RO_DIST_DIR - directory where distribution files should be copied
#
package: $(DISTFILES)
	$(CP) -p $(DISTFILES) $(RO_DIST_DIR)

#
# For the "install" target, the following macro must be appropriately
# defined.
#
#   RO_INSTALL_DIR - directory where installed files should be copied
#
MY_INSTALL_DIR=	$(RO_INSTALL_DIR)/preprocessor

install: $(DISTFILES) $(MY_INSTALL_DIR)
	-$(MV) -f $(RO_INSTALL_DIR)/archive/preprocessor.tar \
		$(RO_INSTALL_DIR)/archive/old.preprocessor.tar
	$(TAR) -cf $(RO_INSTALL_DIR)/archive/preprocessor.tar \
		$(MY_INSTALL_DIR)/*
	$(RM) $(MY_INSTALL_DIR)/*
	$(FOR) i in $(DISTFILES); $(DO) ( \
		$(CP) -p $$i $(MY_INSTALL_DIR); \
		$(CHMOD) 444 $(MY_INSTALL_DIR)/$$i; \
	); $(DONE) 
	$(CD) $(MY_INSTALL_DIR); make

