.IGNORE:

SHELL = /bin/sh

# PATHS
prefix = @prefix@
srcdir = @srcdir@
bindir = $(prefix)/bin
includedir = $(prefix)/include
libdir = $(prefix)/lib

# Libraries
LIBS =  @BBH_RNPLBLD_CLIBS@

# Programs
CTOF = mfi
LEX = @LEX@
YACC = @YACC@
PERL = @PERL@
RANLIB = @RANLIB@
AR = @AR@
CC = @CC@
F77 = @F77@

# Compiler Options
LDFLAGS = -L../lib @LDFLAGS@ @BBH_RNPLAPP_LPATHS@
CFLAGS = -c @CFLAGS@ -DRNPL_F77_INCLUDE='"@RNPL_F77_INCLUDE@"'
CPPFLAGS = -I../include @BBH_RNPLAPP_CINC@ @CPPFLAGS@ @DEFS@ @BBH_DEFS@

F77FLAGS = @F77FLAGS@

# System type for mfi
BBH_SYSTEM=@BBH_SYSTEM@

# Compiler Commands
CC_CMP = $(CC) $(CFLAGS) $(CPPFLAGS)
CC_LNK = $(CC) $(LDFLAGS) 
CC_PRE = $(CC) -E $(CPPFLAGS) 

F77_CMP = $(F77) -c $(F77FLAGS)


install: all
	if test ! -d $(prefix); then\
		mkdir $(prefix);\
	fi
	if test ! -d $(bindir); then\
		mkdir $(bindir);\
	fi
	if test ! -d $(includedir); then\
		mkdir $(includedir);\
	fi
	if test ! -d $(libdir); then\
		mkdir $(libdir);\
	fi
	cp ../bin/rnpl $(bindir)
	cp ../lib/librnpl.a $(libdir)
	cp ../lib/libbbhutil.a $(libdir)
	cp ../include/* $(includedir)
	if test ! -d $(libdir)/rnpl; then\
		mkdir $(libdir)/rnpl;\
	fi
	cp ../lib/rnpl/* $(libdir)/rnpl

all: librnpl.a libbbhutil.a rnpl

clean:
	rm *.o *.i y.tab.c lex.yy.c y.tab.h librnpl_f.c bbhutil_f.c > /dev/null 2>&1
	rm ../lib/librnpl.a > /dev/null 2>&1
	rm ../lib/libbbhutil.a > /dev/null 2>&1
	rm ../bin/rnpl > /dev/null 2>&1
	rm Makefile config.cache config.log config.status > /dev/null 2>&1
	
rnpl: y.tab.o lex.yy.o rnpl_sup.o
	$(CC_LNK) -o rnpl y.tab.o lex.yy.o rnpl_sup.o $(LIBS)
	mv rnpl ../bin 

y.tab.o: y.tab.c
	$(CC_CMP) y.tab.c

lex.yy.o: lex.yy.c
	$(CC_CMP) lex.yy.c

rnpl_sup.o: rnpl_sup.c rnpl.h
	$(CC_CMP) rnpl_sup.c

y.tab.c : rnpl.y rnpl.h
	$(YACC) -d rnpl.y

lex.yy.c: rnpl.l rnpl.h
	$(LEX) rnpl.l

bbhutil.o: bbhutil.c
	$(CC_CMP) bbhutil.c
	
bbhutil_f.i: bbhutil_f.h
	$(CC_PRE) bbhutil_f.h > bbhutil_f.i
	
bbhutil_f.c: bbhutil_f.i
	$(PERL) $(CTOF) bbhutil_f.i bbhutil_f.c $(BBH_SYSTEM) bbhutil
	
bbhutil_f.o: bbhutil_f.c
	$(CC_CMP) bbhutil_f.c

libbbhutil.a: bbhutil.o bbhutil_f.o
	$(AR) r libbbhutil.a bbhutil.o bbhutil_f.o
	$(RANLIB) libbbhutil.a
	mv libbbhutil.a ../lib

librnpl.o: librnpl.c
	$(CC_CMP) librnpl.c

librnpl_f.i: librnpl_f.h
	$(CC_PRE) librnpl_f.h > librnpl_f.i
	
librnpl_f.c: librnpl_f.i
	$(PERL) $(CTOF) librnpl_f.i librnpl_f.c $(BBH_SYSTEM) rnpl
	
librnpl_f.o: librnpl_f.c
	$(CC_CMP) librnpl_f.c
	
librnplf77.o: librnplf77.f
	$(F77_CMP) librnplf77.f

librnpl.a: bbhutil.o bbhutil_f.o librnpl.o librnpl_f.o librnplf77.o
	$(AR) r librnpl.a bbhutil.o bbhutil_f.o librnpl.o librnpl_f.o librnplf77.o
	$(RANLIB) librnpl.a
	mv librnpl.a ../lib

