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

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

top_srcdir           = /proj/tpfimos/larour/Libraries/linux/mpich2-1.0.2p1/src/mpe2/src/logging

CC                   = gcc
CC_SHL               = @CC_SHL@
CLINKER              = gcc
MPI_CC               = /proj/tpfimos/larour/Libraries/linux/mpich2-1.0.2p1/bin/mpicc
MPI_CLINKER          = $(MPI_CC)
AR                   = ar
ARFLAGS              = cr
RANLIB               = ranlib
MAKE                 = make --no-print-directory
MPI_INC              = 
MPI_LIBS             = 
INCLUDE_DIR          = -I.. -I${top_srcdir}/include \
                       -I../../.. -I${top_srcdir}/../../include \
                       $(MPI_INC)
PROF_LIBNAME         = mpe
CFLAGS               = 
MPE_LIBDIR           = /proj/tpfimos/larour/Libraries/linux/mpich2-1.0.2p1/src/mpe2/lib
LIB_PATH             = $(MPI_LIBS)
PROF_LIBS            = -L$(MPE_LIBDIR) @PROF_LIBS@ $(MPI_LIBS)
LDFLAGS              = 
MPE_BUILD_FORTRAN2C  = yes

### End User configurable options ###
SHELL = /bin/sh
RM    = rm

VPATH=.:$(srcdir)

# Installation directories
prefix           = /proj/tpfimos/larour/Libraries/linux/mpich2-gnu/
exec_prefix      = ${prefix}
bindir           = ${exec_prefix}/bin
includedir       = ${prefix}/include
libdir           = ${exec_prefix}/lib
# Build directories
libbuild_dir     = /proj/tpfimos/larour/Libraries/linux/mpich2-1.0.2p1/src/mpe2/lib
binbuild_dir     = /proj/tpfimos/larour/Libraries/linux/mpich2-1.0.2p1/src/mpe2/bin
srcdir           = /proj/tpfimos/larour/Libraries/linux/mpich2-1.0.2p1/src/mpe2/src/logging/src

# EXECS            = ${binbuild_dir}/clog2_print testlog
EXECS            = ${binbuild_dir}/clog2_print

# GETNAME_DEFS are needed by mpehname.c
CC_FLAGS         = $(CFLAGS) $(INCLUDE_DIR) $(MPE_COPTS)
CC_LDFLAGS       = $(LDFLAGS) $(CFLAGS) $(MPE_LDOPTS)

MPE_CSOURCES     = clog_util.c clog_timer.c \
                   clog_preamble.c clog_block.c clog_buffer.c clog_record.c \
                   clog_sync.c clog_merger.c clog.c mpe_log.c
MPE_COBJECTS     = $(MPE_CSOURCES:.c=.o)

MPE_WSOURCES     = mpe_logf.c
MPE_WOBJECTS     = $(MPE_WSOURCES:.c=.o)

MPE_SHLCOBJECTS  = $(MPE_COBJECTS:.o=.lo)
MPE_SHLWOBJECTS  = $(MPE_WOBJECTS:.o=.lo)

.SUFFIXES: .c .o .lo .a 

.c.o:
	$(MPE_ICC) $(MPE_ICFLAGS) -c $<

.c.a:
	$(MPE_ICC) $(MPE_ICFLAGS) -c $<

# Allow compilers that do not allow -o for renaming object files
.c.lo:
	$(CC_SHL) $(CC_FLAGS) -c $< $(INC_DIR)
	@mv $*.o $*.lo

# 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: clean
	$(MAKE) ${libbuild_dir}/lib$(PROF_LIBNAME)_nompi.a
	$(MAKE) ${libbuild_dir}/lib$(PROF_LIBNAME)_null.a
	$(MAKE) ${libbuild_dir}/lib$(PROF_LIBNAME).a
	$(MAKE) $(EXECS)

#
# 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
#
# We've also had trouble with this.  Sometimes, under Solaris, the 
# first file in the dependency is built but not included with $? 
# This is clearly a bug in the make, since the determination of dependencies
# is done once (e.g., a blip in the filesystem time can't be 
# responsible if make works as Sun documents it).  To fix this, we
# add all the objects to the library, not just the "recent" ones.
${libbuild_dir}/lib$(PROF_LIBNAME).a: clean
	@$(MAKE) $(MPE_COBJECTS) \
	 "MPE_ICC=${MPI_CC}" "MPE_ICFLAGS=${CC_FLAGS}"
	@if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	     $(MAKE) $(MPE_WOBJECTS) \
	     "MPE_ICC=${MPI_CC}" "MPE_ICFLAGS=${CC_FLAGS}" ; \
	 fi
	$(AR) $(ARFLAGS) $@ *.o
	$(RANLIB) $@

${libbuild_dir}/lib$(PROF_LIBNAME)_nompi.a: clean
	@$(MAKE) $(MPE_COBJECTS) \
	 "MPE_ICC=${CC}" "MPE_ICFLAGS=${CC_FLAGS} -DCLOG_NOMPI"
	@if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	     $(MAKE) $(MPE_WOBJECTS) \
	     "MPE_ICC=${CC}" "MPE_ICFLAGS=${CC_FLAGS} -DCLOG_NOMPI" ; \
	 fi
	$(AR) $(ARFLAGS) $@ *.o
	$(RANLIB) $@

# -DCLOG_NOMPI can be used when creating lib$(PROF_LIBNAME)_null.a
${libbuild_dir}/lib$(PROF_LIBNAME)_null.a: clean
	@$(MAKE) mpe_log_null.o \
	 "MPE_ICC=${CC}" "MPE_ICFLAGS=${CC_FLAGS} "
	@if [ "$(MPE_BUILD_FORTRAN2C)" = "yes" ] ; then \
	     $(MAKE) $(MPE_WOBJECTS) \
	     "MPE_ICC=${CC}" "MPE_ICFLAGS=${CC_FLAGS}" ; \
	 fi
	$(AR) $(ARFLAGS) $@ *.o
	$(RANLIB) $@

${binbuild_dir}/clog2_print: clean
	@$(MAKE) clog_print.o \
	 "MPE_ICC=${CC}" "MPE_ICFLAGS=${CC_FLAGS} -DCLOG_NOMPI"
	$(CLINKER) $(CC_LDFLAGS) -o $@ clog_print.o \
                   -L${libbuild_dir} -l$(PROF_LIBNAME)_nompi

#
# Remove the old libraries before rebuilding (in case they came from another
# architecture or are otherwise damaged)
rmlib:
	@-$(RM) -f ${libbuild_dir}/lib$(PROF_LIBNAME).a 
	@-$(RM) -f ${libbuild_dir}/lib$(PROF_LIBNAME)_nompi.a 

rmprog:
	@-$(RM) -f $(EXECS)

clean: rmprog
	@-$(RM) -f *.o ${srcdir}/*.o *~ $(EXECS) PI*

distclean: clean rmlib
	@-$(RM) -f Makefile
