# $Id: Makefile.in,v 1.25 2000/12/22 02:49:56 m-hirano Exp $
# $RWC_Release: Omni-1.6 $
# $RWC_Copyright:
#  Omni Compiler Software Version 1.5-1.6
#  Copyright (C) 2002 PC Cluster Consortium
#  
#  This software is free software; you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License version
#  2.1 published by the Free Software Foundation.
#  
#  Omni Compiler Software Version 1.0-1.4
#  Copyright (C) 1999, 2000, 2001.
#   Tsukuba Research Center, Real World Computing Partnership, Japan.
#  
#  Please check the Copyright and License information in the files named
#  COPYRIGHT and LICENSE under the top  directory of the Omni Compiler
#  Software release kit.
#  
#  
#  $
#
#	Makefile for a Fortran 90/77 compiler front-end
#	using the second pass of the exc back-end as code generator.
#

TOPDIR		=	..
prefix		=	@prefix@
exec_prefix	=	@exec_prefix@

INSTALLDIR	=	$(prefix)/lib/openmp/libexec
INSTALL		=	@INSTALLCOM@
MKDIR		=	@MKDIRCOM@

GCCINC		=	-I`case "$(CC)" in *gcc) echo \`$(CC) -v 2>&1 | grep specs | sed 's/specs$$/include/' | awk '{ print $$NF }'\`;; esac`


CC_OPT_SWITCH	=	@CFLAGS@
CPPFLAGS	=	-I. -I$(TOPDIR)/include @gmpIncOpt@ @DEFS@ @CPPFLAGS@ -DBUGFIX -DYYDEBUG \
			-D__OMNI_FRONTEND_INCORE__
CFLAGS		=	$(CC_OPT_SWITCH) $(CPPFLAGS)

CC		=	@CC@

YACC		=	@YACCCOM@

DEPEND_SWITCH	=	$(CPPFLAGS)

#
# f77 Frontend for exc
#

SRCS	= F-main.c C-expr-mem.c C-exprcode.c C-expr-misc.c \
	F-parser.c F-mem.c F-compile.c F-compile-decl.c F-compile-expr.c \
	F-opt-expv.c F-output.c F-machine-dep.c F-io.c F-OMP.c F-TEA.c \
	F-intrinsic.c F-data.c F-datasub.c F-iosub.c F-equiv.c F-varutil.c \
	F-qreal.c

OBJS	=  F-main.o C-expr-mem.o C-exprcode.o C-expr-misc.o \
	F-parser.o F-mem.o F-compile.o F-compile-decl.o F-compile-expr.o \
	F-opt-expv.o F-output.o F-machine-dep.o F-io.o F-OMP.o F-TEA.o \
	F-intrinsic.o F-data.o F-datasub.o F-iosub.o F-equiv.o F-varutil.o \
	F-qreal.o

TARGET	= F-front fpp

all:	$(TARGET)

F-front : C-exprcode.h C-exprcode.c F-parser.c $(OBJS)
	$(CC) $(CC_OPT_SWITCH) -o F-front $(OBJS) @gmpLibOpt@ -lm

fpp:	fpp.o
	$(CC) $(CC_OPT_SWITCH) fpp.o -o fpp

fpp.o:	fpp.c
	$(CC) $(CFLAGS) -DDEFAULT_CC="\"$(CC)\"" -c fpp.c -o fpp.o

F-parser.c: F-parser.y F-lex.c
	$(YACC) -v F-parser.y
	@echo "(expect 5 shift/reduce, 1 reduce/reduce)"
	mv y.tab.c F-parser.c

C-exprcode.h: C-exprcode.def C-exprcode.h.awk
	awk -f C-exprcode.h.awk < C-exprcode.def > C-exprcode.h

C-exprcode.c: C-exprcode.def C-exprcode.c.awk
	awk -f C-exprcode.c.awk < C-exprcode.def > C-exprcode.c

clean:
	rm -f F-parser.c y.tab.c y.output *.o *~ $(OBJS) $(TARGET) C-exprcode.[ch] \
		core *.core *.exe \
		tags TAGS ./.exp_funcs ./.tags funcrefs

distclean:	clean
	rm -f config.* Makefile .depend*

depend: C-exprcode.h C-exprcode.c $(SRCS)
	touch .depend.tmp
	makedepend -f ./.depend.tmp -a -- $(GCCINC) $(DEPEND_SWITCH) -- $(SRCS)
	sed 's:^$(PLATFORMDIR)/:./:' ./.depend.tmp > ./.depend
	cat Makefile ./.depend > ./Makefile.tmp
	mv Makefile.tmp Makefile
	rm -f ./.depend ./.depend.tmp .depend.tmp.bak

install:	$(TARGET)
	@if [ ! -d $(INSTALLDIR) ] ; then \
		(echo "Making directory $(INSTALLDIR)" ; \
		$(MKDIR) $(INSTALLDIR) ; \
		chmod 775 $(INSTALLDIR)); \
	else \
		true ; \
	fi
	for i in $(TARGET) ; do \
		$(INSTALL) -m 755 $$i $(INSTALLDIR); \
	done

funcref:	./F-front.h
	@rm -f ./.exp_funcs tags ./funcrefs
	@$(CC) -E $(CFLAGS) -D__FUNCTION_REF__ ./F-front.h | grep '^extern' | \
	sed -e 's:[	 ]*([	 ]*:(:g' -e 's:[	 ]*):):g' -e 's:[ ]*,:,:g' > ./.exp_funcs
	@ctags -v $(SRCS) F-lex.c > ./.tags
	@mv ./.tags ./tags
	@for i in `awk -F\( '{ print $$1 }' < ./.exp_funcs | awk '{ print $$NF }' | sed 's:^\*::'`; do \
		(REF=`grep -w $${i} ./tags || true`; \
		PROTO=`egrep "[	 ][ 	]*$${i}\(" ./.exp_funcs || true`; \
		if test ! -z "$${REF}"; then \
			REF=`echo $$REF | awk '{ print $$2 }'`; \
			echo "$$PROTO @ $$REF"; \
		else \
			echo "$$PROTO @ ???"; \
		fi); \
	done | sed -e 's:;::' -e 's:^extern[ 	]*::' | sort -t @ -k 2 > ./funcrefs 2>/dev/null

Makefile::
	(cd ..; sh ./config.status)
