DEBUG =   -O3 						  # to debug use -g

#Note:
# These programs need at least 30 MB in stack size.
# This is because the model is passed over the stack
# to the subroutines
# 
# To increase the stack size to 100 MB do (bash shell)
# ulimit -s 100000
#
# To increase the OpenMP stack to 100 MB do (bash shell)
# declare -x KMP_STACKSIZE=100m


# Intel compilers
#CC =   icc  $(DEBUG) 
CC_OPENMP = icc  $(DEBUG) -openmp

# GNU compilers
CC =   gcc -lm $(DEBUG) 
#CC_OPENMP = gcc -lm  $(DEBUG) -openmp  # Need gcc version 4.2 for OpenMP support (not testet)

OBJ = ./obj/
EXE = ./exe/

# Subroutines

$(OBJ)magfdz.o: magfdz.c Makefile
	$(CC) -c magfdz.c  -o $(OBJ)magfdz.o

$(OBJ)plmbar.o: plmbar.c Makefile
	$(CC) -c plmbar.c  -o $(OBJ)plmbar.o

$(OBJ)mainfield_mp.o: mainfield_mp.c modeldef.h Makefile
	${CC} -c mainfield_mp.c -o $(OBJ)mainfield_mp.o 

$(OBJ)sm2geo.o: sm2geo.c Makefile
	${CC} -c sm2geo.c -o $(OBJ)sm2geo.o

$(OBJ)gsm2geo.o: gsm2geo.c Makefile
	${CC} -c gsm2geo.c -o $(OBJ)gsm2geo.o

$(OBJ)geod2geoc.o: geod2geoc.c Makefile
	${CC} -c geod2geoc.c -o $(OBJ)geod2geoc.o

#EMM_calc

$(OBJ)EMM_calc.o: EMM_calc.c  modeldef.h  Makefile
	$(CC) -c EMM_calc.c  -o $(OBJ)EMM_calc.o

EMM_calc_obj = $(OBJ)EMM_calc.o $(OBJ)mainfield_mp.o $(OBJ)geod2geoc.o $(OBJ)gsm2geo.o $(OBJ)sm2geo.o\
				   $(OBJ)plmbar.o $(OBJ)magfdz.o

EMM_calc: $(EMM_calc_obj) Makefile
	$(CC) $(EMM_calc_obj)  -o $(EXE)EMM_calc

# EMM_smp_demo

$(OBJ)EMM_smp_demo.o: EMM_smp_demo.c  modeldef.h  Makefile
	$(CC_OPENMP) -c EMM_smp_demo.c  -o $(OBJ)EMM_smp_demo.o

EMM_smp_demo_obj = $(OBJ)EMM_smp_demo.o $(OBJ)mainfield_mp.o $(OBJ)geod2geoc.o $(OBJ)gsm2geo.o $(OBJ)sm2geo.o\
						 $(OBJ)plmbar.o $(OBJ)magfdz.o

EMM_smp_demo: $(EMM_smp_demo_obj) Makefile
	$(CC_OPENMP) $(EMM_smp_demo_obj)  -o $(EXE)EMM_smp_demo

