
MESA_DIR = ../..

#################################################################

# STEP 1: set up the standard info

include $(MESA_DIR)/utils/makefile_header

# #################################################################

ifeq ($(USE_GYRE),NO)

# STEP 2: build a stub library

LIB = libgyre.a
LIB_OBJS = gyre_lib_stub.o

$(LIB) : $(LIB_OBJS)
	$(LIB_TOOL) $(LIB) $(LIB_OBJS)

#################################################################

COMPILE = $(COMPILE_TO_DEPLOY) $(FCfree)
#COMPILE = $(COMPILE_TO_TEST) $(FCfree)

gyre_lib_stub.o: $(MOD_PUBLIC_DIR)/gyre_lib_stub.f
	$(COMPILE) $<         

clean:
	-@rm -f *.o *.mod *.modmic *genmod.f90 *.a

else

#################################################################

# STEP 2: build the library

GYRE_DIRS = $(subst $(eval) ,:,$(shell test -d ../gyre && find ../gyre/src -type d))

FPX3FLAGS = -DOMP -DDOUBLE_PRECISION -I${GYRE_DIRS}:../gyre/src/mesa

LIB = libgyre.a

libgyre.a : gyre_lib.o
	@echo ${DIRS_LIST}
	@echo ${GYRE_DIRS}
	@echo AR libgyre.a
	@rm -f libgyre.a
	@ar crs libgyre.a *.o

#################################################################

# Vars

COMPILE = $(COMPILE_TO_DEPLOY) $(FCfree) -Wno-uninitialized
#COMPILE = $(COMPILE_TO_TEST) $(FCfree) -Wno-uninitialized

# Rules

vpath %.fpp ${GYRE_DIRS}
vpath %.inc ${GYRE_DIRS}
vpath %.f ${GYRE_DIRS}

.PRECIOUS : %.f90

%.o : %.mod

%.f90 : %.fpp
	@fpx3 ${FPX3FLAGS} < $< > $@

%.o %.mod : %.f90
	@echo FC $<
	@${COMPILE} -c $<
	@if [ -e $(basename $@).mod ]; then touch $(basename $@).mod; fi

clean:
	-@rm -f *.o *.f90 *.fpp *.mod *.modmic .depend *.a

# Dependencies

#gyre_lib.fpp : ../gyre/src/mesa/gyre_lib.fpp
#	@cp $< $@

ifneq ($(MAKECMDGOALS),clean)
$(shell fpx3_deps ${FPX3FLAGS} gyre_lib > .depend )
-include .depend
endif

endif
