#############################################################################
# 
#  Copyright 2021 IRD
#   
#  This file is part of NCSTAT.
#   
#  NCSTAT is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as 
#  published by the Free Software Foundation, either version 3 of 
#  the License, or (at your option) any later version.
#   
#  NCSTAT is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#   
#  You can find a copy of the GNU Lesser General Public License
#  in the NCSTAT/doc directory.
# 
#############################################################################
#
#############################################################################
# Top makefile for NCSTAT software
#
# Targets are the suffixes of the system-specific include makefiles in the
# ./makeincs subdirectory. For example, to build "GNU" version, give first
# the command
#
#   make GNU
#
# Without argument you'll get the list of available targets.
#
# Once you have made the choice of the system, you must customize (eventually)
# the resulting ./make.inc include makefile with your choice for the name/path
# of the Fortran compiler and name/path for your STATPACK, NETCDF and BLAS libraries.
#
# The following variables must be defined in your ../make.inc file :
#
#  EXECDIR : Absolute path to the directory for the NCSTAT executables
#  FC      : Fortran compiler
#  FFLAGS  : Fortran options for compiling the executables
#  FFLAGS2 : Fortran options for compiling the module NCSTAT_Utilities
#  LDFLAGS : Linker load options for the STATPACK, NETCDF and any other
#            external (e.g. BLAS) libraries on your machine.
#
# Alternatively, if you don't want to use a ./make.inc include makefile,
# You can create a dummy ./make.inc (e.g. an empty file) and define directly
# the previous variables as Shell environment variables before using this
# makefile.
#
# To create, update or add executables, once you have created your own 
#  ./make.inc include makefile (or define the EXECDIR, FC, FFLAGS, FFLAGS2
# and LDFLAGS Shell environment variables), enter the command
#
#   make all
#
# This will compile the NCSTAT code with your specific configuration. The executables
# are created in the directory $(EXECDIR), where the variable EXECDIR is specified
# normally in ./make.inc (e.g. in your machine specific include makefile ) or is a Shell
# environment variable.
#
# On some systems, you can force all the source files to be recompiled by
# entering the command
#
#   make all FRC=FRC
#
# To create just one specific executable, enter the command
#
#   make executable_name
#
# where executable_name is any operator available in NCSTAT.
#
# To list all the executables available in this version of NCSTAT,
# enter the command
#
#   make list
#
# To list all the sources of the executables available in this version
# of NCSTAT, enter the command
#
#   make list_sources
#
# To clean the ./sources directory, enter the command
#
#   make clean
#
# or the command
#
#   make clean_all
#
#  Version 2.1
#  February, 2021
#
#############################################################################

SHELL=/bin/sh

targets:
	@echo "Please specify one of these targets:"
	@- (cd makeincs ; ls -C make.inc.* | sed -e 's/make.inc.//g')

.DEFAULT:
	@- (if [ -f makeincs/make.inc.$@ ] ; then cp -f makeincs/make.inc.$@  make.inc ; fi)
	@- (if [ -f sources/$@.F90 ] ; then cd sources; $(MAKE) $@ ; fi)

all clean clean_all list list_sources:
	(if [ -f ./make.inc ] ; then cd sources; $(MAKE) $@ ; fi)
