# Makefile for gpfsperf.  Compiles one version of the source for both
# combinations of with/without MPI.

INCL = -I/usr/lpp/mmfs/include
LIBS = -lpthread -lrt -lgpfs

CFLAGS = -O -DGPFS_LINUX
CC = cc
MPCC = mpicc
MPLIBS = -lmpich

PROGS = gpfsperf
OBJECTS = irreg.o gpfsperf.o

all: $(PROGS) $(MPIPROGS)

clean:
	rm -f $(PROGS) $(MPIPROGS) $(OBJECTS) $(MPIOBJECTS)

irreg.o: irreg.h irreg.c
	$(CC) -c $(CFLAGS) $(OTHERINCL) $(INCL) irreg.c


# Single node versions of gpfsperf.
gpfsperf.o: irreg.h gpfsperf.c
	$(CC) -c $(CFLAGS) $(OTHERINCL) $(INCL) gpfsperf.c -o $@

gpfsperf: irreg.o gpfsperf.o
	$(CC) $(CFLAGS) gpfsperf.o irreg.o $(OTHERLIB) $(LIBS) -o $@


# Multi-node versions of gpfsperf.  Requires MPI to build or run.
gpfsperf-mpi.o: irreg.h gpfsperf.c
	@if which $(MPCC) > /dev/null 2>&1; then \
          cmd="$(MPCC) -c $(CFLAGS) $(OTHERINCL) $(INCL) -DMULTI_NODE gpfsperf.c -o $@" ; \
          echo "$$cmd" ; \
          $$cmd ; \
        else \
          echo "MPI compiler ($(MPCC)) not found; cannot build $@"; \
        fi

gpfsperf-mpi: irreg.o gpfsperf-mpi.o
	@if which $(MPCC) > /dev/null 2>&1; then \
          cmd="$(MPCC) gpfsperf-mpi.o irreg.o $(CFLAGS) $(OTHERPOELIB) $(MPLIBS) $(LIBS) -o $@" ; \
          echo "$$cmd" ; \
          $$cmd ; \
        else \
          echo "MPI compiler ($(MPCC)) not found; cannot build $@"; \
        fi
