summaryrefslogtreecommitdiffstats
path: root/bin/locate_sw
blob: 1cf84e270c2b016a758e330badb241201868c364 (plain)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5.  The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#

# Try to locate the software as named in argument.
# This is a sequential search of all possible locations of the software.
# Usage: locate_sw <SW-Name>
# It prints a string showing the paths leading to the include, lib and bin
# directory of the software, separated by colons.  E.g., if the software is
# located in /usr/sdt/*, it prints
# /usr/sdt/include:/usr/sdt/lib:/usr/sdt/bin
# Any component that is not found will be returned as an empty string. E.g.,
# if somehow the header files of the software are not found, it prints
# :/usr/sdt/lib;/usr/sdt/bin

# Function definitions
USAGE()
{
    echo "Usage: locate_sw <SW-Name>"
    echo "    where <SW-Name> can be hdf4, hdf5, zlib"
    echo "    It prints the paths leading the header files (include),"
    echo "    library (lib), and tools (bin).   E.g.,"
    echo "    /usr/sdt/include:/usr/sdt/lib:/usr/sdt/bin"
    echo "    Any component that is not found will be returned as an empty string. E.g.,"
    echo "    if somehow the header files of the software are not found, it prints"
    echo "    :/usr/sdt/lib;/usr/sdt/bin"
    echo "Exit code: 0 if software located; otherwise non-zero"
}

# locate hdf4 software
locate_hdf4()
{
# this default is the best guess of locating hdf4 software
swpaths_defaults="/usr/ncsa /usr/sdt /usr/local"
swpaths=

case "$OSname" in
    SunOS)
        case "$OSrelease" in
            5.7)
               swpaths="/afs/ncsa/packages/hdf/SunOS_5.7"
               ;;
	    *)
            # use default
	       ;;
        esac
        ;;
    HP-UX)
        case "$OSrelease" in
	   B.11.00)
	        swpaths="/afs/ncsa/packages/hdf/HPUX_11.00"
               ;;
           *)
           # use default
              ;;
        esac
	;;
    Linux)
	swpaths="/afs/ncsa/packages/hdf/Linux"
	;;
    OSF1)
	swpaths="/afs/ncsa/packages/hdf/OSF1_V4.0"
	;;
    *)
	# just use the defaults
	;;
esac

# Check if the hdf4 software is actually available.
# Accept the directory only if needed .h, .a and tools are found
# in the same place.  That way, they are more likely to be of the
# same version.
# 
swpaths="$swpaths $swpaths_defaults"
for sw in $swpaths; do
    if [ -r $sw/include/hdf.h -a -r $sw/lib/libdf.a -a -r $sw/bin/hdp ]; then
	SW_inc=$sw/include
	SW_lib=$sw/lib
	SW_bin=$sw/bin
	SW_Location=$sw
	break
    fi
done
}

# locate hdf5 software
locate_hdf5()
{
# this default is the best guess of locating hdf5 software
swpaths_defaults="/usr/ncsa /usr/sdt /usr/local"
swpaths=

case "$OSname" in
    SunOS)
        case "$OSrelease" in
            5.7)
               swpaths="/afs/ncsa/packages/hdf5/SunOS_5.7"
               ;;
	    *)
            # use default
	       ;;
        esac
        ;;
    HP-UX)
        case "$OSrelease" in
	   B.11.00)
	        swpaths="/afs/ncsa/packages/hdf5/HPUX_11.00"
               ;;
           *)
           # use default
              ;;
        esac
	;;
    Linux)
	swpaths="/afs/ncsa/packages/hdf5/Linux"
	;;
    FreeBSD)
        swpaths="/afs/ncsa/packages/hdf5/FreeBSD"
        ;;
    OSF1)
	swpaths="/afs/ncsa/packages/hdf5/OSF1_V4.0"
	;;
    *)
	# just use the defaults
	;;
esac

# Check if the hdf5 software is actually available.
# Accept the directory only if needed .h, .a and tools are found
# in the same place.  That way, they are more likely to be of the
# same version.
# 
swpaths="$swpaths $swpaths_defaults"
for sw in $swpaths; do
    if [ -r $sw/include/hdf5.h -a -r $sw/lib/libhdf5.a -a -r $sw/bin/h5dump ]; then
	SW_inc=$sw/include
	SW_lib=$sw/lib
	SW_bin=$sw/bin
	SW_Location=$sw
	break
    fi
done
}

# locate zlib software
locate_zlib()
{
# this default is the best guess of locating zlib software
swpaths_defaults="/usr /usr/local /usr/ncsa /usr/sdt"
swpaths=


# Check if the zlib software is actually available.
# Accept the directory only if needed .h, .a and tools are found
# in the same place.  That way, they are more likely to be of the
# same version.
# Don't know something specific to check the bin directory.  Maybe gzip?
# Just make sure it exists.
# 
swpaths="$swpaths $swpaths_defaults"
for sw in $swpaths; do
    if [ -r $sw/include/zlib.h -a	\
	    \( -r $sw/lib/libz.a -o -r $sw/lib/libz.so \) -a -d $cw/bin ]; then
	SW_inc=$sw/include
	SW_lib=$sw/lib
	SW_bin=$sw/bin
	SW_Location=$sw
	break
    fi
done

# if none found, try HDF4 software which contains a version of zlib.
if [ x-$SW_Location = x- ]; then
    locate_hdf4
fi

}

# Main
#
# Options
#
if [ $# -lt 1 ]; then
    USAGE
    exit 1
fi

if [ "$1" = -h ]; then
    USAGE
    exit 0
fi

SW=$1
shift

# locations of the software seeked.
SW_inc=			# include place
SW_lib=			# library place
SW_bin=			# binary place
SW_Location=		# parent directory of all the above

OSname=`uname -s`
OSrelease=`uname -r`

case $SW in
hdf4|hdf)
    locate_hdf4
    ;;
hdf5)
    locate_hdf5
    ;;
zlib)
    locate_zlib
    ;;
*)
    echo "unknown software ($SW)"
    USAGE
    exit 1
    ;;
esac

# show the results located, separated by commas.
if [ -n "${SW_inc}" -a -n "${SW_lib}" -a -n "${SW_bin}" ]; then
    echo ${SW_inc},${SW_lib},${SW_bin}
    exit 0
else
    exit 1
fi