openfoam/bin/tools/lib-dir
Mark Olesen b4d38ab468 ENH: improve handling of ThirdParty packages
- generalize some of the library extensions (.so vs .dylib).
  Provide as wmake 'sysFunctions'

- added note about unsupported/incomplete system support

- centralize detection of ThirdParty packages into wmake/ subdirectory
  by providing a series of scripts in the spirit of GNU autoconfig.
  For example,

      have_boost, have_readline, have_scotch, ...

  Each of the `have_<package>` scripts will generally provide the
  following type of functions:

      have_<package>          # detection
      no_<package>            # reset
      echo_<package>          # echoing

  and the following type of variables:

      HAVE_<package>          # unset or 'true'
      <package>_ARCH_PATH     # root for <package>
      <package>_INC_DIR       # include directory for <package>
      <package>_LIB_DIR       # library directory for <package>

  This simplifies the calling scripts:

      if have_metis
      then
          wmake metisDecomp
      fi

  As well as reducing clutter in the corresponding Make/options:

      EXE_INC = \
          -I$(METIS_INC_DIR) \
          -I../decompositionMethods/lnInclude

      LIB_LIBS = \
          -L$(METIS_LIB_DIR) -lmetis

  Any additional modifications (platform-specific or for an external build
  system) can now be made centrally.
2018-04-24 14:51:19 +02:00

169 lines
3.9 KiB
Bash
Executable File

#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# tools/lib-dir [OPTION] DIR [LIBEXT]
#
# Description
# Since csh/tcsh doesn't have functions, this script can be used to manage
# slightly more complex logic.
#
# Resolves for the existence of DIR/lib64 and DIR/lib, or uses the fallback
# LIBEXT if these failed. A DIR ending in "-none" or "-system" is skipped.
#
# output -csh: setenv LD_LIBRARY_PATH dir/lib:$LD_LIBRARY_PATH
# output -make: -Ldir/lib
# output -sh: LD_LIBRARY_PATH=dir/lib:$LD_LIBRARY_PATH
#
#------------------------------------------------------------------------------
printHelp() {
cat<<USAGE
Usage: ${0##*/} [OPTION] DIR [LIBEXT]
options:
-sh Emit POSIX shell syntax (default)
-csh Emit C-shell shell syntax
-make Emit content for a makefile
-help Print the usage
Resolves for the existence of DIR/lib64 and DIR/lib, or uses the fallback
LIBEXT if these failed. A DIR ending in "-none" or "-system" is skipped.
With -sh LD_LIBRARY_PATH=dir/lib:$LD_LIBRARY_PATH
With -csh setenv LD_LIBRARY_PATH dir/lib:$LD_LIBRARY_PATH
With -make -Ldir/lib
Exit status is zero (success) or non-zero (failure)
USAGE
exit 0 # A clean exit
}
# Report error and exit
die()
{
exec 1>&2
echo
echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
echo
echo "See '${Script##*/} -help' for usage"
echo
exit 1
}
#------------------------------------------------------------------------------
optSyntax=sh
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
printHelp
;;
-csh | -sh | -make)
optSyntax="${1#-}"
;;
--)
shift
break
;;
-*)
die "unknown option: '$1'"
;;
*)
break
;;
esac
shift
done
#------------------------------------------------------------------------------
dir="$1" # $1 = base directory for 'lib' or 'lib64'
alt="$2" # $2 = fallback libname ('lib' or 'lib64')
unset resolved
# 0)
# Skip entirely if directory ends in "-none" or "-system".
# These special cases (disabled, system directories) should not require
# adjustment of LD_LIBRARY_PATH
case "$dir" in
none | system | *-none | *-system)
unset dir
;;
esac
if [ -z "$dir" ]
then
exit 1
elif [ -d "$dir" ]
then
# 1) Check for dir/lib64 and dir/lib
for end in lib$WM_COMPILER_LIB_ARCH lib
do
if [ -d "$dir/$end" ]
then
resolved=$dir/$end
break
fi
done
fi
# 2) Use fallback if the previous failed
if [ -z "$resolved" -a -n "$alt" ]
then
# Fallback
case "$alt" in
/*)
resolved=$alt
;;
(*)
resolved=$dir/$alt
;;
esac
exit 0
fi
if [ -n "$resolved" ]
then
case "$optSyntax-$(uname -s 2>/dev/null)" in
make*)
printf "%s\n" "-L$resolved"
;;
csh-Darwin*)
echo "setenv DYLD_LIBRARY_PATH $resolved:$DYLD_LIBRARY_PATH"
;;
csh*)
echo "setenv LD_LIBRARY_PATH $resolved:$LD_LIBRARY_PATH"
;;
sh-Darwin*)
echo "DYLD_LIBRARY_PATH=$resolved:$DYLD_LIBRARY_PATH"
;;
*)
echo "LD_LIBRARY_PATH=$resolved:$LD_LIBRARY_PATH"
;;
esac
exit 0 # Good
else
exit 1 # Error
fi
#------------------------------------------------------------------------------