File: lib-dir

package info (click to toggle)
openfoam 1912.200626-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 238,956 kB
  • sloc: cpp: 1,159,641; sh: 15,902; ansic: 5,195; lex: 660; xml: 387; python: 282; awk: 212; makefile: 103; sed: 88; csh: 3
file content (193 lines) | stat: -rwxr-xr-x 4,890 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | www.openfoam.com
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
#     Copyright (C) 2018-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# 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
  -sh-verbose       As per -sh,  with additional verbosity
  -csh-verbose      As per -csh, with additional verbosity
  -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
unset verboseOutput

# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
    -h | -help*)
        printHelp
        ;;
    -csh | -sh | -make)
        optSyntax="${1#-}"
        unset verboseOutput
        ;;
    -csh-verbose | -sh-verbose)
        optSyntax="${1#-}"
        verboseOutput="source "         # Report: "export/setenv ..."
        ;;
    --)
        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" ] && [ -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"
        if [ -n "$verboseOutput" ]
        then
            echo "setenv DYLD_LIBRARY_PATH $resolved:$DYLD_LIBRARY_PATH" 1>&2
        fi
        ;;
    csh*)
        echo "setenv LD_LIBRARY_PATH $resolved:$LD_LIBRARY_PATH"
        if [ -n "$verboseOutput" ]
        then
            echo "setenv LD_LIBRARY_PATH $resolved:$LD_LIBRARY_PATH" 1>&2
        fi
        ;;
    sh-Darwin*)
        echo "DYLD_LIBRARY_PATH=$resolved:$DYLD_LIBRARY_PATH"
        if [ -n "$verboseOutput" ]
        then
            echo "DYLD_LIBRARY_PATH=$resolved:$DYLD_LIBRARY_PATH" 1>&2
        fi
        ;;
    *)
        echo "LD_LIBRARY_PATH=$resolved:$LD_LIBRARY_PATH"
        if [ -n "$verboseOutput" ]
        then
            echo "LD_LIBRARY_PATH=$resolved:$LD_LIBRARY_PATH" 1>&2
        fi
        ;;
    esac
    exit 0      # Good
else
    exit 1      # Error
fi


#------------------------------------------------------------------------------