####################################################################
#   Copyright (c)
#
#   You may copy, distribute, and modify it freely as long as you  #
#   preserve this copyright and permission notice.                 #
#                                                                  #
#
####################################################################

#
#  Makefile for Adlib/src/pcrcFortran
#

SHELL       = @CONFIGSHELL@


srcdir      = @srcdir@
top_srcdir  = @top_srcdir@

prefix      = @prefix@
exec_prefix = @exec_prefix@

bindir      = @bindir@
includedir  = @includedir@
libdir      = @libdir@

config_dir = ../include

VPATH       = .:${srcdir}

MPI_INC  = @MPI_INC@
MPIO_INC  = @MPIO_INC@

CC= @CC@
CFLAGS = @DEFS@ @CFLAGS@ @OPTIMIZE@ -I${top_srcdir}/src/include $(MPI_INC) $(MPIO_INC)
# profile tools
PCFLAGS = $(CFLAGS) @PROFILE@

CPP= @CPP@
CPPFLAGS= @CPPFLAGS@

FCL         = @FCL@
FC_OPT      = @FC_OPT@

OPT         = @OPTIMIZE@

PLATFORM    = @IO_PLATFORM@

AR          = ar rcu
RANLIB      = @RANLIB@

INSTALL     = cp

RM = /bin/rm -f

LIB     = libio.a
#profile lib
PROFILE_IO_LIB = @PROFILE_IO_LIB@

OBJECTS =  open.o create.o close.o val_sect.o	\
		read_cur.o seek.o seek_read.o 	\
		prefetch.o pread_cur.o seek_pread.o pwait.o	\
		rd_us_1d.o rd_us_2d.o rd_us_3d.o \
		rd_sbs_1d.o rd_sbs_2d.o rd_sbs_3d.o 	\
		prd_us_1d.o prd_us_2d.o prd_us_3d.o \
		prd_sbs_1d.o prd_sbs_2d.o prd_sbs_3d.o 	\
		seek_write.o write_cur.o 	\
		wr_us_1d.o wr_us_2d.o wr_us_3d.o	\
		wr_sbs_1d.o wr_sbs_2d.o wr_sbs_3d.o

POBJECTS =  open.o create.o close.o val_sect.o	\
		prof_read_cur.o seek.o seek_read.o 	\
		prefetch.o pread_cur.o seek_pread.o pwait.o	\
		rd_us_1d.o rd_us_2d.o rd_us_3d.o \
		rd_sbs_1d.o rd_sbs_2d.o rd_sbs_3d.o 	\
		prd_us_1d.o prd_us_2d.o prd_us_3d.o \
		prd_sbs_1d.o prd_sbs_2d.o prd_sbs_3d.o 	\
		seek_write.o prof_write_cur.o 	\
		wr_us_1d.o wr_us_2d.o wr_us_3d.o	\
		prof_wr_sbs_1d.o wr_sbs_2d.o wr_sbs_3d.o

.SUFFIXES:
.SUFFIXES: .c .o

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

all: $(LIB) $(PROFILE_IO_LIB)

$(LIB) : $(OBJECTS)
	rm -f $@
	$(AR) $@ $(OBJECTS)
	$(RANLIB) $@

libPio.a : $(POBJECTS)
	rm -f $@
	$(AR) $@ $(POBJECTS)
	$(RANLIB) $@

open.o :  open.c pfile.h
create.o :  create.c pfile.h
close.o :  close.c pfile.h
read_cur.o :  read_cur.c pfile.h
prefetch.o :  prefetch.c passion_base.h prefetch.h
pread_cur.o :  pread_cur.c passion_base.h
write_cur.o :  write_cur.c pfile.h
seek_pread.o: seek_pread.c passion_base.h
rd_us_1d.o: rd_us_1d.c  passion_base.h
rd_us_2d.o: rd_us_2d.c  passion_base.h
rd_us_3d.o: rd_us_3d.c  passion_base.h
rd_sbs_1d.o: rd_sbs_1d.c  passion_base.h
rd_sbs_2d.o: rd_sbs_2d.c  passion_base.h
rd_sbs_3d.o: rd_sbs_3d.c  passion_base.h
prd_us_1d.o: prd_us_1d.c  passion_base.h
prd_us_2d.o: prd_us_2d.c  passion_base.h
prd_us_3d.o: prd_us_3d.c  passion_base.h
prd_sbs_1d.o: prd_sbs_1d.c  passion_base.h
prd_sbs_2d.o: prd_sbs_2d.c  passion_base.h
prd_sbs_3d.o: prd_sbs_3d.c  passion_base.h
wr_us_1d.o: wr_us_1d.c  passion_base.h
wr_us_2d.o: wr_us_2d.c  passion_base.h
wr_us_3d.o: wr_us_3d.c  passion_base.h
wr_sbs_1d.o: wr_sbs_1d.c  passion_base.h
wr_sbs_2d.o: wr_sbs_2d.c  passion_base.h
wr_sbs_3d.o: wr_sbs_3d.c  passion_base.h

#for profiling
prof_read_cur.o :  prof_read_cur.c pfile.h
	$(CC) -c $(PCFLAGS) -D$(PLATFORM) $<

prof_write_cur.o :  prof_write_cur.c pfile.h
	$(CC) -c $(PCFLAGS) -D$(PLATFORM) $<

prof_wr_sbs_1d.o :  prof_wr_sbs_1d.c pfile.h
	$(CC) -c $(PCFLAGS) -D$(PLATFORM) $<

clean:
	/bin/rm -f *.o core  $(LIB) $(TEST) $(PROFILE_IO_LIB)

distclean:
	/bin/rm -f *.o core $(LIB) $(PROFILE_IO_LIB)
	/bin/rm -f Makefile

install: $(LIB) 
	if [ ! -d ${libdir} ] ; then mkdir ${libdir} ; fi
	$(INSTALL) $(LIB) ${libdir}

uninstall:
	rm -f ${libdir}/$(LIB)	

