# Build the shared FMS component library
# The list of source files that should be compiled for this component.

set pathnames_shared  = $code_dir/path_names_shared        # path to file containing list of source paths

$root/bin/list_paths $root/src/shared
mv path_names $pathnames_shared

#set srcList = ( shared/tridiagonal shared/tracer_manager shared/topography shared/time_manager shared/time_interp shared/station_data shared/sat_vapor_pres shared/random_numbers shared/platform shared/oda_tools shared/diag_manager shared/data_override shared/constants shared/column_diagnostics shared/axis_utils shared/astronomy shared/amip_interp shared/fft shared/field_manager shared/horiz_interp shared/include shared/memutils shared/mosaic shared/coupler shared/test )
set srcList = ( shared/tridiagonal shared/tracer_manager shared/topography shared/time_manager shared/time_interp shared/station_data shared/sat_vapor_pres shared/random_numbers shared/platform shared/oda_tools shared/diag_manager shared/data_override shared/constants shared/column_diagnostics shared/axis_utils                  shared/amip_interp shared/fft shared/field_manager shared/horiz_interp shared/include shared/memutils shared/mosaic shared/coupler shared/test )

set lib_name = "lib_FMS"

mkdir -p $executable:h:h/$lib_name

# astronomy.F90 must be compiled with stricter floating point semantics to prevent buggy vectorization
set pathnames_astro = $executable:h:h/$lib_name/astronomy_command-$$
if ( `ifort --version | head -1` =~ "ifort*17.0.4*" & "$vec" == "-vec" ) then
    echo 'compiling astronomy.F90 with fp-model consistent to prevent buggy vectorization'
    echo '$(FC) -fp-model consistent $(CPPDEFS) $(CPPFLAGS) $(FPPFLAGS) $(FFLAGS) $(OTHERFLAGS) -fp-model consistent -c	'$code_dir'/src/shared/astronomy/astronomy.F90' > $pathnames_astro
else
    echo "Fine. not using ifort 17.0.4"
    echo >  $pathnames_astro
    set srcList = ( $srcList shared/astronomy )
endif

cd $executable:h:h/$lib_name
$mkmf_lib -p $lib_name.a -c "$cppDefs" $srcList $pathnames_astro $pathnames_shared $lib_include_dirs
make

if( $status ) then
    echo "Make failed to create $lib_name.a"
    exit 1
endif
