####################################################################
#   Copyright (c) 1996 NPACT Working Group. You may copy,          #
#   distribute, and modify it freely as long as you preserve this  #
#   copyright and permission notice.                               #
#                                                                  #
#   NPACT Working Group is a joint force of                        #
#      NPAC at Syracuse University,                                #
#      PACT at Harbin Institute of Technology, and                 #
#      PACT at Peking University                                   #   
####################################################################

#
#  Makefile for HPF parser 
#

SHELL       = @CONFIGSHELL@

VERSION     = @VERSION@

srcdir      = @srcdir@
top_srcdir  = @top_srcdir@

prefix      = @prefix@
exec_prefix = @exec_prefix@
bindir      = @bindir@
libdir      = @libdir@

INCLUDEDIR= @top_srcdir@/src/include
config_dir = ../include 

VPATH = .:${srcdir}

LIBDIR = ../basicop

ULIBS = -lbasic 

SLIBS = @LEXLIB_L@ @YYLIB_L@


LEX     = @LEX@
LEX_OUT = @LEX_OUTPUT_ROOT@
LLFLAGS = @LLFLAG@

YACC = @YACC@
YYFLAGS = @YYFLAG_L@
YACC_OUT = y@YACC_ROOT@

CC =  @CC@
CFLAGS= @CFLAGS@ @DEFS@ -D_${LEX}_ -I. -I${srcdir} -I$(config_dir) -I$(INCLUDEDIR)

PROGRAM = hpf2dep

OBJS = hpf2dep.o hpfparser.o hpflexer.o makespec.o \
	 exec_part.o fdmakebfnd.o fdmakellnd.o use.o io.o

DEPENDENCES =   $(INCLUDEDIR)/defnodes.h \
		$(INCLUDEDIR)/tags.h \
		$(INCLUDEDIR)/bif.h  \
		$(INCLUDEDIR)/ll.h \
		$(INCLUDEDIR)/symb.h \
		$(INCLUDEDIR)/typedef.h \
		$(INCLUDEDIR)/makenodes.h


.SUFFIXES:
.SUFFIXES: .l .y .c .o

.l.o:
	$(LEX) $(LLFLAGS) $<
	mv $(LEX_OUT).c $*.c
	$(CC) -c $(CFLAGS) $*.c

.y.o:
	$(YACC) $(YYFLAGS) $<
	mv $(YACC_OUT).c $*.c
	mv $(YACC_OUT).h $*_tab.h
#
# begin	error report file generation
	@echo "+++ generating error.def from" $*_tab.h
	grep '^#[ |\t]*define' $*_tab.h | \
	sed 's/^#[ |\t]*define[ |\t]*/"/' | sed 's/$$/",/'> error.def
	grep '^#' $*_tab.h | \
	sed 's/^#[ |\t]*define[ |\t]*//' | sed 's/$$//'> error.file
# end	
	$(CC) -c $(CFLAGS) $*.c

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


all: Makefile $(PROGRAM)

Makefile: ${srcdir}/Makefile.in
	@echo 
	@echo Please configure the package to generate new makefile ...
	@exit 1

$(PROGRAM) : $(OBJS) $(LIBDIR)/libbasic.a
	$(CC) -g -o $@ $(OBJS) -L$(LIBDIR) $(SLIBS) $(ULIBS) 

fpp: ${srcdir}/fpp.in
	@echo 
	@echo Please configure the package to generate new fpp file ...
	@exit 1

hpfparser.y : f90.y  fD.y f20.y  err.deal 
	cat ${srcdir}/f90.y ${srcdir}/fD.y ${srcdir}/f20.y ${srcdir}/err.deal > hpfparser.y

clean:
	rm -f *.o hpfparser_tab.h
	rm -f y.output hpfparser.y hpfparser.c hpflexer.c $(YACC_OUT).* error.def error.file
	rm -f $(PROGRAM) 
	rm -f core

install: $(PROGRAM)
	if [ ! -d ${bindir} ] ; then mkdir ${bindir} ; fi
	cp $(PROGRAM) ${bindir}
	cp fpp error.file       ${libdir}

uninstall:
	rm -f ${bindir}/$(PROGRAM)
	rm -f ${libdir}/fpp ${libdir}/error.file

#       
# file dependence information
#

hpf2dep.o : hpf2dep.c $(DEPENDENCES) $(INCLUDEDIR)/config.h
	$(CC) -c $(CFLAGS) -DSHELL="\"$(SHELL)\"" $<

hpflexer.o : hpflexer.l keywords.h $(INCLUDEDIR)/defnodes.h  hpfparser_tab.h

hpfparser.o : hpfparser.y err_token.h $(DEPENDENCES)

makespec.o : makespec.c extern.h $(DEPENDENCES)

exec_part.o: exec_part.c extern.h $(DEPENDENCES)

io.o: io.c extern.h $(DEPENDENCES)

fdmakebfnd.o : fdmakebfnd.c extern.h $(DEPENDENCES)

fdmakellnd.o : fdmakellnd.c extern.h  $(DEPENDENCES)

use.o :  use.c extern.h $(DEPENDENCES)




