#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
# Compile coupler and related programs
#
# Larry Solheim  ...Mar,2014
#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#

# Set a default value for LIBS
# This may be overwritten by defining LIBS in the invoking environment
ifeq ($(strip $(LIBS)),)
  LIBS := system
endif

# Export variables found in export_list if they are defined and non-null in this environment
export_list := LIBS FC FFLAGS CPPFLAGS LDFLAGS ADD2VPATH modver
export_list += COUPLER_COMMIT_ID COUPLER_REPO_PATH
define export_template
  ifneq ($(strip $($(1))),)
    export $(1)
    $$(info CPL top level make: export $(1) = $($(1)))
  endif
endef
$(foreach var,$(export_list),$(eval $(call export_template,$(var))))

SUBDIRS = comm drivers
.PHONY: all $(SUBDIRS)

all: $(SUBDIRS)

$(SUBDIRS):
	@$(MAKE) -C $@

drivers: comm

data: comm
	@$(MAKE) -C drivers data

install:
	@$(MAKE) -C comm     install
	@$(MAKE) -C drivers  $@

regrid:
	@$(MAKE) -C drivers regrid install

.PHONY: clean veryclean
clean:
	@for subd in $(SUBDIRS); do $(MAKE) -C $$subd clean; done

veryclean:
	@for subd in $(SUBDIRS); do $(MAKE) -C $$subd veryclean; done
