ARCH        = @ARCH@
RANLIB      = @RANLIB@
FILE_SYSTEM = @FILE_SYSTEM@
MAKE        = @MAKE@
AR          = @AR@
LIBNAME     = @LIBNAME@
NOF77       = @NOF77@
NOPROFILE   = @NOPROFILE@
MPI         = @MPI@
PREFIX      = @PREFIX@
FROM_MPICH  = @FROM_MPICH@
BUILD_MPI_INFO = @BUILD_MPI_INFO@
BUILD_MPI_ARRAY = @BUILD_MPI_ARRAY@
DIRS        = mpi-io adio/common
MPIO_DIRS   = mpi-io
ALL_DIRS    = mpi-io mpi-io/fortran mpi2-other/info mpi2-other/info/fortran mpi2-other/array mpi2-other/array/fortran adio/common adio/ad_pfs adio/ad_piofs adio/ad_nfs adio/ad_ufs adio/ad_xfs adio/ad_hfs adio/ad_sfs test
SHELL       = /bin/sh

@VPATH@

all: mpio

mpio:
	$(MAKE) clean
	$(MAKE) mpiolib
	$(MAKE) clean
	@if test "$(NOPROFILE)" = 0 ; then\
            $(MAKE) profile; \
        fi;\
	$(MAKE) clean
	$(RANLIB) $(LIBNAME)
	@if test "$(FROM_MPICH)" = 0 ; then \
           echo " "; \
           echo "Completed build of ROMIO. Check the output for errors."; \
           echo " " ;\
           echo "To compile the example programs, cd to the test directory"; \
           echo "and type make."; \
           echo "Run the examples the way you would run any MPI program."; \
           echo "Each program takes the filename as a command-line argument"; \
           echo "'-fname filename'." ; \
           echo " " ;\
        fi

clean:
	@dirs=`echo "$(DIRS)"`; \
        for x in $(FILE_SYSTEM) ;\
         do \
             dirs=`echo "$$dirs" adio/ad_$$x` ;\
         done ; \
        if test "$(BUILD_MPI_INFO)" = 1 ; then \
            dirs=`echo "$$dirs" mpi2-other/info` ;\
            if test "$(NOF77)" = 0 ; then\
                dirs=`echo "$$dirs" mpi2-other/info/fortran` ;\
            fi;\
        fi; \
        if test "$(BUILD_MPI_ARRAY)" = 1 ; then \
            dirs=`echo "$$dirs" mpi2-other/array` ;\
            if test "$(NOF77)" = 0 ; then\
                dirs=`echo "$$dirs" mpi2-other/array/fortran` ;\
            fi;\
        fi; \
        if test "$(NOF77)" = 0 ; then\
            dirs=`echo "$$dirs" mpi-io/fortran` ;\
        fi;\
        for dir in $$dirs ;\
         do \
            echo " " ;\
            echo cleaning directory $$dir ;\
            (cd $$dir; rm -f *.o) ;\
         done; \
         echo " " ;\
         echo cleaning directory test ;\
         (cd test; $(MAKE) clean);\
         echo " ";

mpiolib:
	@if test "$(FROM_MPICH)" = 0 ; then \
            echo " " ;\
            echo "deleting previously built library if it exists" ;\
            rm -f $(LIBNAME) ;\
        fi; \
        dirs=`echo "$(DIRS)"`; \
        for x in $(FILE_SYSTEM) ;\
         do \
             dirs=`echo "$$dirs" adio/ad_$$x` ;\
         done ; \
        if test "$(BUILD_MPI_INFO)" = 1 ; then \
            dirs=`echo "$$dirs" mpi2-other/info` ;\
            if test "$(NOF77)" = 0 ; then \
                dirs=`echo "$$dirs" mpi2-other/info/fortran` ;\
            fi; \
        fi; \
        if test "$(BUILD_MPI_ARRAY)" = 1 ; then \
            dirs=`echo "$$dirs" mpi2-other/array` ;\
            if test "$(NOF77)" = 0 ; then \
                dirs=`echo "$$dirs" mpi2-other/array/fortran` ;\
            fi; \
        fi; \
        if test "$(NOF77)" = 0 ; then \
            dirs=`echo "$$dirs" mpi-io/fortran` ;\
        fi; \
        for dir in $$dirs ;\
         do \
            echo " " ;\
            echo compiling ROMIO in directory $$dir ;\
            (cd $$dir; $(MAKE) ;) ;\
            if [ $$? != 0 ] ; then \
                echo "Make failed in directory $$dir" ; exit 1 ;\
            fi ;\
         done

profile: 
	@if [ "@HAVE_WEAK_SYMBOLS@" = 0 ] ; then \
           dirs=`echo "$(MPIO_DIRS)"`; \
           if test "$(BUILD_MPI_INFO)" = 1 ; then \
               dirs=`echo "$$dirs" mpi2-other/info` ;\
               if test "$(NOF77)" = 0 ; then\
                   dirs=`echo "$$dirs" mpi2-other/info/fortran` ;\
               fi;\
           fi; \
           if test "$(BUILD_MPI_ARRAY)" = 1 ; then \
               dirs=`echo "$$dirs" mpi2-other/array` ;\
               if test "$(NOF77)" = 0 ; then\
                   dirs=`echo "$$dirs" mpi2-other/array/fortran` ;\
               fi;\
           fi; \
           if test "$(NOF77)" = 0 ; then\
               dirs=`echo "$$dirs" mpi-io/fortran` ;\
           fi;\
           for dir in $$dirs ;\
            do \
               echo " " ;\
               echo building profiling interface in directory $$dir ;\
               (cd $$dir; \
                $(MAKE) profile MPIOPROFILE="-DMPIO_BUILD_PROFILING";) ;\
                if [ $$? != 0 ] ; then \
                    echo "Make failed in directory $$dir" ; exit 1 ;\
                fi ;\
            done \
	fi

cleanall:
	@dirs=`echo "$(ALL_DIRS)"`; \
	echo "cleaning test directory" ;\
	(cd test ; ${MAKE} cleanall ) ;\
        echo cleaning current directory ;\
        (rm -f config.status Makefile *~ *.log romio.tar*) ;\
        for dir in $$dirs ;\
         do \
            echo " " ;\
	    if [ ! -d $$dir ] ; then continue ; fi ; \
            echo cleaning directory $$dir ;\
            (cd $$dir; rm -f *.o Makefile *~) ;\
         done; \
         echo " " ;\
         echo "cleaning directory include" ;\
         (cd include; rm -f *.h);\
         echo " " ;\
         echo "cleaning directory util" ;\
         (cd util; rm -f romioinstall *~)

install:
	$(MAKE) clean
	@./util/romioinstall -prefix=$(PREFIX)

romio_lflags:
	@echo '@ROMIO_LFLAGS@'

romio_liblist:
	@echo '@ROMIO_LIBLIST@'

romio_tcflags:
	@echo '@ROMIO_TCFLAGS@'

romio_tcppflags:
	@echo '@ROMIO_TCPPFLAGS@'

romio_tfflags:
	@echo '@ROMIO_TFFLAGS@'
