OSTYPE = $(shell uname)
ifeq ($(OSTYPE),Darwin)
HRTIMEFLAGS = -DHAVE_MACH_ABSOLUTE_TIME
endif
ifeq ($(OSTYPE),Linux)
HRTIMEFLAGS = -DHAVE_CLOCK_GETTIME -lrt
endif

all: clean norm mpi

norm:
	gcc  -g $(HRTIMEFLAGS) -I.. -c sctplikeapi.c
	gcc -g -o exampleapp2 sctplikeapi.o exampleapp2.c $(HRTIMEFLAGS) -I..
	gcc -g -o exampleappN sctplikeapi.o exampleappN.c $(HRTIMEFLAGS) -I..
	gcc -g -o exampleappNlong sctplikeapi.o exampleappNlong.c $(HRTIMEFLAGS) -I..
	gcc -g -o ringN sctplikeapi.o ringN.c $(HRTIMEFLAGS) -I..
	gcc -g -o starN sctplikeapi.o starN.c $(HRTIMEFLAGS) -I..
	gcc -g -o testdrivernew testdrivernew.c $(HRTIMEFLAGS) -I..
#
# these make configuring MPICH2 easier. 
#   Will pass the directory containing this Makefile to --with-sctp=
#
	ar -r libsctplike.a sctplikeapi.o
	mkdir lib
	mkdir include
	cd include && ln -s ../../sctplikeapi.h
	cd lib && ln -s ../libsctplike.a

mpi:
#
# This is an example MPI program that is exactly like the exampleapp2
#  above.  It must be built down here because mpicc requires libsctplike.a
#  to exist in the location MPICH2 was configured with (and the "clean" 
#  target before "all" removes this).
#
#	mpicc -g -o exampleapp2mpi exampleapp2mpi.c
#	mpicc -g -o exampleappNmpi exampleappNmpi.c
#	mpicc -g -o osu_latency osu_latency.c
#	mpicc -g -o osu_bw osu_bw.c
#	mpicc -g -o mywaitall mywaitall.c
#	mpicc -g -o starNmpi starNmpi.c

mpilog:
#	mpicc -g -mpe=mpilog -o exampleapp2mpi exampleapp2mpi.c
#	mpicc -g -mpe=mpilog -o exampleappNmpi exampleappNmpi.c
#	mpicc -g -mpe=mpilog -o osu_latency osu_latency.c
#	mpicc -g -mpe=mpilog -o mywaitall mywaitall.c

old:
	gcc -g -I.. -o exampleapp sctplikeapi.o exampleapp.c
	gcc -g -I.. -o testdriver testdriver.c

clean:
# if you ever see an mpd error when you run mpiexec, make sure you run
#   make clean to delete these /tmp/sctplike* files as their presence
#   seems to be problematic.  a TODO is to ensure these are deleted
#   automatically, but this is just a heads up.
	rm -f /tmp/sctplike*
	rm -rf sctplikeapi.o exampleapp exampleapp2 testdriver testdrivernew libsctplike.a include lib exampleapp2mpi exampleappN exampleappNmpi twoconsecutive ringN starN exampleappNlong varyunexpect mywaitall osu_latency varyunexpectnonblock starNmpi ipcbw gtodloop ipcbwhr hrloop
