# This is the makefile for the mesa const package

MESA_DIR = ../..

#################################################################
#
# PREAMBLE

include $(MESA_DIR)/utils/makefile_header

ifeq ($(CONST_OFFLOAD),YES)
# compile all files for MIC
CC += $(MIC_OFFLOAD)
FC += $(MIC_OFFLOAD)
endif

#################################################################
#
# SOURCES

SRCS = \
   const_def.f90 \
   const_lib.f90

#################################################################
#
# TARGETS

LIB = libconst.a
LIB_OBJS = $(patsubst %.f,%.o,$(patsubst %.f90,%.o,$(SRCS)))
$(LIB) : $(LIB_OBJS)
	$(LIB_TOOL) $(LIB) $(LIB_OBJS)

#################################################################
#
# COMPILATION RULES

COMPILE = $(COMPILE_TO_DEPLOY) $(FCfree)

COMPILE_CMD = $(COMPILE)

%.o : %.f
	$(COMPILE_CMD) $<
%.o : %.f90
	$(COMPILE_CMD) $<
%.mod : %.o
	@true

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

#################################################################
#
# DEPENDENCIES

# Paths to search for source & include files

VPATH = $(MOD_PUBLIC_DIR):$(MOD_PRIVATE_DIR)

# Automatic dependency generation using makedepf90

nodeps : $(.DEFAULT_GOAL)

NODEPS = $(or $(filter nodeps,$(MAKECMDGOALS)),$(filter clean,$(MAKECMDGOALS)))

ifeq ($(NODEPS),)

  DEPEND_DIRS = $(MOD_PUBLIC_DIR):$(MOD_PRIVATE_DIR)

  .depend :
	makedepf90 -m %m.mod -I$(DEPEND_DIRS) $(SRCS) > .depend
  -include .depend

endif
