####################################################################
#   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       = /bin/sh

VERSION     = @VERSION@

srcdir      = @srcdir@
top_srcdir  = @top_srcdir@

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

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

VPATH = .:${srcdir}

LIBDIR = ../basicop

ULIBS = -lbasic 

SLIBS = -ll @YYLIB_L@

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

CC =  @CC@

YACC = @YACC@

YYFLAGS = @YYFLAG_L@

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

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.yy.c $*.c
	$(CC) $(CFLAGS) -c $*.c

.y.o:
	$(YACC) $(YYFLAGS) $<
	mv y.tab.c $*.c
	mv y.tab.h $*.tab.h
	$(CC) $(CFLAGS) -c $*.c

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


all: Makefile $(PROGRAM) error.file

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) 

error.file:  hpfparser.tab.h
	@echo "+++ generating error.file from hpfparser.tab.h"
	sed <  hpfparser.tab.h                   \
	'/define/s/#[ 	]*define[ 	]*\([A-Z,_]*\)[ 	]*\([0-9]*\)/\1 \2/'   | sed '/^[^A-Z]/d' | sed '/^$$/d' > ${srcdir}/error.file

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

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

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

uninstall:
	rm -f ${bindir}/$(PROGRAM)

#       
# file dependence information
#

hpf2dep.o : hpf2dep.c $(DEPENDENCES)

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

hpfparser.o : hpfparser.y $(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)




