#---- Inclusion options for RTL
#OPT +=-DGADGET2
#OPT +=-DSUPPORTHDF5	# ignored if gadget2 is switched off
COMPILER = mpicc
ARG= $(OPT) -g -Iheaders -I.. -Iplatform/linux/include
CFLAGS = $(OPTIONS)
CCFLAGS = -c $(CFLAGS)
OUT=libmesham.a
CP=cp
AR=ar
RANLIB=ranlib
GADGETLINK=
OPTIONS = $(OPT)
ifeq (SUPPORTHDF5,$(findstring SUPPORTHDF5,$(OPT)))
GADGETLINK=-lhdf5 -lz
endif
ifneq (GADGET2,$(findstring GADGET2,$(OPT)))
GADGETLINK=
endif
all: static shared clean

static: cpit 

shared: compiledyn
	${CP} libmesham.so ../libmesham.so

compiledyn:
	gcc -shared -o libmesham.so *.o -lm ${GADGETLINK}
	
cpit: ran
	${CP} libmesham.a ../libmesham.a
	
ran:out.o
	${RANLIB} ${OUT}

out.o: maths other io errors string system gadget
	${AR} rc ${OUT} *.o
	
errors:
	${COMPILER} -c -fPIC Errors/*.c ${ARG}
maths:  
	${COMPILER} -c -fPIC Maths/*.c ${ARG}
	
other:  
	${COMPILER} -c -fPIC Other/*.c ${ARG}
	
io:  
	${COMPILER} -c -fPIC io/*.c ${ARG}

string:  
	${COMPILER} -c -fPIC String/*.c ${ARG}
	
system:  
	${COMPILER} -c -fPIC System/*.c ${ARG}

ifeq (GADGET2,$(findstring GADGET2,$(OPT)))
ifneq (SUPPORTHDF5,$(findstring SUPPORTHDF5,$(OPT)))
gadget: ignorehdf docmp reverthdf
	
ignorehdf: 
	mv  Gadget/src/snapshotHDF.c  Gadget/src/snapshotHDF.ignorec
reverthdf: 
	mv  Gadget/src/snapshotHDF.ignorec  Gadget/src/snapshotHDF.c	
docmp:
	${COMPILER} -c -fPIC Gadget/src/*.c ${ARG} -IGadget/headers -I/home/nick/mesham/Gadget/Gadget2
else 
gadget:
	${COMPILER} -c -fPIC Gadget/src/*.c ${ARG} -IGadget/headers -I/home/nick/mesham/Gadget/Gadget2
endif 
else
gadget:
	
endif

clean: 
	rm -rf *.o *.a *.so
