#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the Common Development
# and Distribution License Version 1.0 (the "License").
#
# You can obtain a copy of the license at
# http://www.opensource.org/licenses/CDDL-1.0.  See the License for the
# specific language governing permissions and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each file and
# include the License file in a prominent location with the name LICENSE.CDDL.
# If applicable, add the following below this CDDL HEADER, with the fields
# enclosed by brackets "[]" replaced with your own identifying information:
#
# Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
#
# CDDL HEADER END
#

#
# Copyright (c) 2013--2018, Regents of the University of Minnesota.
# All rights reserved.
#
# Contributors:
#    Ryan S. Elliott
#


# load all basic KIM make configuration
ifneq (clean,$(MAKECMDGOALS))
  ifeq ($(wildcard ../Makefile.KIM_Config_Helper),)
    KIM_API_BUILD_HELPER = kim-api-v1-build-config
  else
    include ../Makefile.KIM_Config_Helper
  endif
  ifeq ($(shell $(KIM_API_BUILD_HELPER) --version 2> /dev/null),)
    $(error $(KIM_API_BUILD_HELPER) utility is not available.  Something is wrong with your KIM API package setup)
  endif
endif

CC           = $(shell $(KIM_API_BUILD_HELPER) --cc)
CXX          = $(shell $(KIM_API_BUILD_HELPER) --cxx)
FC           = $(shell $(KIM_API_BUILD_HELPER) --fc)
LD           = $(shell $(KIM_API_BUILD_HELPER) --ld)
INCLUDES     = $(shell $(KIM_API_BUILD_HELPER) --includes)
CFLAGS       = $(shell $(KIM_API_BUILD_HELPER) --cflags)
CXXFLAGS     = $(shell $(KIM_API_BUILD_HELPER) --cxxflags)
FFLAGS       = $(shell $(KIM_API_BUILD_HELPER) --fflags)
LDFLAGS      = $(shell $(KIM_API_BUILD_HELPER) --ldflags)
LDLIBS       = $(shell $(KIM_API_BUILD_HELPER) --ldlibs)
XLANGLDLIBS  = $(shell $(KIM_API_BUILD_HELPER) --xlangldlibs)
FNOMAINFLAG  = $(shell $(KIM_API_BUILD_HELPER) --fnomainflag)
OBJONLYFLAG  = $(shell $(KIM_API_BUILD_HELPER) --objonlyflag)
OUTPUTINFLAG = $(shell $(KIM_API_BUILD_HELPER) --outputinflag)

.PHONY: all clean

TEST_NAME := ex_test_Ar_fcc_cluster_fortran

all: $(TEST_NAME)

$(TEST_NAME).o: $(TEST_NAME).F90 Makefile
	$(FC) $(INCLUDES) $(FFLAGS) $(OBJONLYFLAG) $<

$(TEST_NAME): $(TEST_NAME).o
	$(LD) $(FNOMAINFLAG) $(LDFLAGS) $< $(LDLIBS) $(XLANGLDLIBS) $(OUTPUTINFLAG) $@

clean:
	rm -f $(TEST_NAME) $(TEST_NAME).o kim.log *.mod
