#  (C) 1993 by Argonne National Laboratory and Mississipi State University.
#      All rights reserved.  See COPYRIGHT in top-level directory.
#

##### User configurable options #####

ARCH        = @ARCH@
MAKE        = @MAKE@
COMM        = @COMM@
MPIR_HOME   = @MPIR_HOME@
CC          = @MPIR_HOME@/lib/@ARCH@/@COMM@/mpicc
CLINKER     = $(CC)
F77         = @MPIR_HOME@/lib/@ARCH@/@COMM@/mpif77
FLINKER     = $(F77)
AR          = @AR@
RANLIB      = @RANLIB@
INCLUDE_DIR = @X_INC@
OPTFLAGS    = 
MPE_GRAPH   = @MPE_GRAPHICS@
LIB_PATH    = @X_LIB@
LIB_LIST    = 

MPEGRAPHICS_SOURCE = @MPEGRAPHICS_SOURCE@
MPEGRAPHICS_OBJS   = @MPEGRAPHICS_OBJS@
MPEGRAPHICS_FSOURCE = @MPEGRAPHICS_FSOURCE@
MPEGRAPHICS_FOBJS   = @MPEGRAPHICS_FOBJS@
### End User configurable options ###
SHELL = /bin/sh

EXECS = dbxtest dbxtest2

# GETNAME_DEFS are needed by mpehname.c
CFLAGS = @MPE_CFLAGS@ @GETNAME_DEFS@ \
	$(OPTFLAGS) $(INCLUDE_DIR) $(MPIPROFILE) \
	-DMPI_$(ARCH) $(MPE_GRAPH)

MPE_CSOURCES = timers.c  $(MPEGRAPHICS_SOURCE) mpe_log.c decomp.c \
	       mpe_seq.c examine.c privtags.c getgrank.c mpehname.c mpe_io.c
MPE_TSOURCES = decomp.c mpe_seq.c dbxerr.c getgrank.c
MPE_COBJECTS = timers.o  $(MPEGRAPHICS_OBJS) mpe_log.o decomp.o mpe_seq.o \
		dbxerr.o examine.o privtags.o getgrank.o mpehname.o mpe_io.o
MPE_WSOURCES = $(MPEGRAPHICS_FSOURCE) mpe_logf.c decompf.c mpe_seqf.c \
	       getgrankf.c
MPE_WOBJECTS = timersf.o $(MPEGRAPHICS_FOBJS) mpe_logf.o decompf.o mpe_seqf.o \
		getgrankf.o

MPE_SOURCES = $(MPE_CSOURCES) $(MPE_WSOURCES)
MPE_OBJECTS = $(MPE_COBJECTS) $(MPE_WOBJECTS)

# default_all is the same as default, but without the RANLIB.  This
# can speed up the build (ranlibs can take a LONG time).  profile_all 
# is the same, but for the profile library
# **** Currently the same as default for simplicity ****
default_all: default
profile_all: 


default: $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe.a \
	 $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe_nompi.a \
	 $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/mpe_prof.o \
	 $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/mpe_proff.o \
	 $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libtmpi.a \
	 $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/liblmpi.a \
	 $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libampi.a 

profile:
wrappers:
	$(MPIR_HOME)/util/bfort -ferr -mpi -mnative -mapptr -ptrprefix MPIR_ \
		-anyname -I pubinc $(MPE_TSOURCES)

#
# It is tempting here to use ... libmpe.a($(MPE_OBJECTS)) as the dependency,
# but this would require that all makes properly handle library dependencies.
# Since makes that DO are the exception rather than the rule, we don't
# use this form
$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe.a: $(MPE_OBJECTS)
	$(AR) $@ $?
	$(RANLIB) $@
#	-/bin/rm -f $?

$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe_nompi.a:  $(MPEGRAPHICS_SOURCE)
	@if [ "$(MPEGRAPHICS_SOURCE)" != "" ] ; then \
	    $(MAKE) clean ; \
	    $(MAKE) -f Makefile_nompi $@ ; \
	fi
manpages:
	$(MPIR_HOME)/util/doctext -mpath $(MPIR_HOME)/man/man4 \
	 -ext 4 -I pubinc -index $(MPIR_HOME)/www.mpe.index \
	 -jumpfile $(MPIR_HOME)/jumpfile.list \
	   -indexdir "http:/www.mcs.anl.gov/mpi/man" -heading MPE \
		$(MPE_CSOURCES)
	$(MPIR_HOME)/util/doc2lt $(MPE_CSOURCES) >> $(MPIR_HOME)/rsummpe.tmp

wwwpages:
	../util/doctext -html -mpath ../www/www4 -ext html -I pubinc \
	   -index ../www.index -jumpfile ../jumpfile.list \
	   -mapref $(MPIR_HOME)/util/mpis.cit \
	   -indexdir "http:/www.mcs.anl.gov/mpi/man" -heading MPE \
		-quotefmt ../util/fortnotes ../util/errnotes \
	$(MPE_CSOURCES)


mpe_log.o: mpe_log.h mpe_log.c mpe_log_genproc.c mpe_log_genproc.h \
	  mpe_log_merge.c mpe_log_adjusttime.c
mpe_plog.o: mpe_log.h mpe_log.c mpe_log_genproc.c mpe_log_genproc.h \
	  mpe_log_merge.c mpe_log_adjusttime.c
	$(CC) $(CFLAGS) -c -DUSE_PMPI mpe_log.c
	/bin/mv mpe_log.o mpe_plog.o

$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libtmpi.a: trc_wrappers.o
	$(AR) $@ $?
	$(RANLIB) $@
#	-/bin/rm -f $?

$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/liblmpi.a: log_wrap.o mpe_plog.o
	$(AR) $@ $?
	$(RANLIB) $@
#	-/bin/rm -f $?

#
# Some compilers (particularly on Suns) can't seem to handle this 
#log1_wrappers.o: log_wrap.c
#	$(CC) $(CFLAGS) -c -DFIRST_HALF log_wrap.c
#	/bin/mv log_wrap.o log1_wrap.o

$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libampi.a: visual_mess.c
	if [ -n "@MPE_GRAPHICS@" ] ; then \
	$(CC) $(CFLAGS) -c visual_mess.c ; \
	$(AR) $@ visual_mess.o ; \
	$(RANLIB) $@ ; fi
#	-/bin/rm -f $?

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

.c.a:
	$(CC) $(CFLAGS) -c $*.c

$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/mpe_prof.o: mpe_prof.c
	$(CC) $(CFLAGS) -c mpe_prof.c
	/bin/cp mpe_prof.o $(MPIR_HOME)/lib/$(ARCH)/$(COMM)

$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/mpe_proff.o: mpe_proff.c
	$(CC) $(CFLAGS) -c mpe_proff.c
	/bin/cp mpe_proff.o $(MPIR_HOME)/lib/$(ARCH)/$(COMM)


dbxtest: dbxtest.o $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe.a
	$(CLINKER) -o dbxtest dbxtest.o \
		$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe.a \
		$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpi.a \
	$(LIB_PATH) $(LIB_LIST)
dbxtest2: dbxtest2.o $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe.a
	$(CLINKER) -o dbxtest2 dbxtest2.o \
		$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpe.a \
		$(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpi.a \
	$(LIB_PATH) $(LIB_LIST)
clean:
	-/bin/rm -f *.o *~ $(EXECS)
	-(cd contrib/mandel ; $(MAKE) clean)
	-(cd contrib/mastermind ; $(MAKE) clean)
	-(cd contrib/life ; $(MAKE) clean)
	-(cd test ; $(MAKE) clean)


