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

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

ARCH        = @ARCH@
COMM        = @COMM@
BOPT        = @BOPT@
MPIR_HOME   = @MPIR_HOME@
CC          = @CC@
F77         = @F77@
AR          = @AR@
RANLIB      = @RANLIB@
INCLUDE_DIR = @INCLUDE_PATH@ -I../../mpid/@DEVICE@ -I../../include
DEVICE      = @DEVICE@
OPTFLAGS    = @OPTFLAGS@

### End User configurable options ###

SHELL = /bin/sh

DEVICE_INCLUDE = ../../mpid/$(DEVICE)/dmch.h

MPI_INCLUDE    = ../../include/mpi.h ../../include/mpi_bc.h \
                 ../../include/mpir.h ../../include/mpi_ad.h \
		 ../../include/mpisys.h
DEVICE_LIB = 
CFLAGS = @CFLAGS@ $(OPTFLAGS) @OPTFLAGSC@ $(INCLUDE_DIR) \
	-DMPI_$(ARCH) $(MPIPROFILE)

LIBS = ../../lib/$(ARCH)/$(COMM)/lib@MPILIBNAME@.a $(DEVICE_LIB)

MPI_CSOURCES = topo_test.c graphdimsget.c graph_get.c cartdim_get.c \
              cart_get.c dims_create.c cart_map.c graph_map.c cart_create.c \
              graphcreate.c cart_rank.c cart_coords.c graphnbrcnt.c \
              graph_nbr.c cart_shift.c cart_sub.c topo_util.c

# wrappers for routines with Fortran LOGICAL type being made by hand
MPI_TSOURCES =  

MPI_COBJECTS = topo_test.o graphdimsget.o graph_get.o cartdim_get.o \
              cart_get.o dims_create.o cart_map.o graph_map.o cart_create.o \
              graphcreate.o cart_rank.o cart_coords.o graphnbrcnt.o \
              graph_nbr.o cart_shift.o cart_sub.o topo_util.o

MPI_WSOURCES = topo_testf.c graphdimsgtf.c graph_getf.c cartdim_getf.c \
              cart_getf.c dims_createf.c cart_mapf.c graph_mapf.c cart_createf.c \
              graphcreatef.c cart_rankf.c cart_coordsf.c graphnbrcntf.c \
              graph_nbrf.c cart_shiftf.c cart_subf.c

MPI_WOBJECTS = topo_testf.o graphdimsgtf.o graph_getf.o cartdim_getf.o \
              cart_getf.o dims_createf.o cart_mapf.o graph_mapf.o cart_createf.o \
              graphcreatef.o cart_rankf.o cart_coordsf.o graphnbrcntf.o \
              graph_nbrf.o cart_shiftf.o cart_subf.o

default: ../../lib/$(ARCH)/$(COMM)/lib@MPILIBNAME@.a

profile: ../../lib/$(ARCH)/$(COMM)/libp@MPILIBNAME@.a

MPI_SOURCES = $(MPI_CSOURCES) $(MPI_WSOURCES)
MPI_OBJECTS = $(MPI_COBJECTS) $(MPI_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
default_all: $(MPI_OBJECTS)
	$(AR) ../../lib/$(ARCH)/$(COMM)/lib@MPILIBNAME@.a $?
profile_all: $(MPI_OBJECTS)
	$(AR) ../../lib/$(ARCH)/$(COMM)/libp@MPILIBNAME@.a $?
wrapperlib: $(MPI_WOBJECTS)
	$(AR) ../../lib/$(ARCH)/$(COMM)/libf@MPILIBNAME@.a $?	

# Move longname-wrappers to shorter names
wrappers:
	../../util/bfort -ferr -mpi -mnative -mapptr -ptrprefix MPIR_ \
		-anyname -I pubinc $(MPI_TSOURCES)	
	if [ -s graphdimsgetf.c ] ; then \
	    /bin/mv graphdimsgetf.c graphdimsgtf.c ; fi
manpages:
	../../util/doctext -mpath ../../man/man3 -ext 3 -I pubinc \
	   -index ../../www.index -jumpfile ../../jumpfile.list \
	   -indexdir "http:/www.mcs.anl.gov/mpi/www/www3" -heading MPI \
		-quotefmt ../../util/fortnotes ../../util/errnotes \
		$(MPI_CSOURCES)
	../../util/doc2lt $(MPI_CSOURCES) >> ../../rsum.tmp

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

source_names:
	@echo $(MPI_CSOURCES)

$(MPI_OBJECTS) :  $(MPI_INCLUDE)

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

../../lib/$(ARCH)/$(COMM)/lib@MPILIBNAME@.a: $(MPI_OBJECTS) 
	-$(AR) $@ $?
	$(RANLIB) $@

../../lib/$(ARCH)/$(COMM)/libp@MPILIBNAME@.a: $(MPI_OBJECTS) 
	-$(AR) $@ $?
	$(RANLIB) $@

clean:
	/bin/rm -f *.o *~ 
