# Build the land_lad library

set lib_name = "lib_land_lad"

# land_model.F90 must be compiled without vectorization!
# ifort 15.0.3.187 apparently has a bug.
# With ifort 17.0.1.132 land_model.F90 can be compiled with vectorization.
set pathnames = $executable:h:h/$lib_name/land_model_command-$$

set srcList = ( land_param land_lad/vegetation land_lad/soil land_lad/numerics.F90 land_lad/land_types.F90 $pathnames )

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

if ( "`ifort --version`" =~ 15.0.3 ) then
    echo 'compiling land_model.F90 without vectorization because of compiler bug (ifort 15.0.3)'
#	$(FC) $(CPPDEFS) $(CPPFLAGS) $(FPPFLAGS) $(FFLAGS) $(OTHERFLAGS) -c -I/p/projects/climber3/petri/POEM/src/shared/include	/p/projects/climber3/petri/POEM/src/land_lad/land_model.F90
    echo '$(FC) -no-vec $(CPPDEFS) $(CPPFLAGS) $(FPPFLAGS) $(FFLAGS) $(OTHERFLAGS) -no-vec -c land_lad/land_model.F90' > $pathnames
else
    echo land_lad/land_model.F90 > $pathnames
endif

cd $executable:h:h/$lib_name
$mkmf_lib -p $lib_name.a -c "$cppDefs"  -o "-I$executable:h:h/lib_FMS" $srcList $lib_include_dirs
rm -f $pathnames
make

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