1
+
#!/bin/sh
 
2
+
#
 
3
+
# Copyright by The HDF Group.                                              
 
4
+
# All rights reserved.                                                     
 
5
+
#
 
6
+
# This file is part of HDF5. The full HDF5 copyright notice, including     
 
7
+
# terms governing use, modification, and redistribution, is contained in   
 
8
+
# the files COPYING and Copyright.html.  COPYING can be found at the root  
 
9
+
# of the source code distribution tree; Copyright.html can be found at the 
 
10
+
# root level of an installed copy of the electronic document set and is    
 
11
+
# linked from the top-level documents page.  It can also be found at       
 
12
+
# http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have access  
 
13
+
# to either file, you may request a copy from help@hdfgroup.org.           
 
14
+
#
 
15
+
# A script used to first configure and build the HDF5 source distribution
 
16
+
# included with the REST VOL plugin source code, and then use that built
 
17
+
# HDF5 to build the REST VOL plugin itself.
 
18
+
 
19
+
# Get the directory of the script itself
 
20
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
21
+
 
22
+
# Set the default install directory
 
23
+
INSTALL_DIR=${SCRIPT_DIR}/rest_vol_build
 
24
+
 
25
+
# Default name of the directory for the included HDF5 source distribution,
 
26
+
# as well as the default directory where it gets installed
 
27
+
HDF5_DIR="hdf5"
 
28
+
HDF5_INSTALL_DIR="${INSTALL_DIR}"
 
29
+
build_hdf5=true
 
30
+
 
31
+
NPROCS=0
 
32
+
 
33
+
# Default is to not build tools due to circular dependency on VOL being
 
34
+
# already built
 
35
+
build_tools=false
 
36
+
 
37
+
# Compiler flags for linking with cURL and YAJL
 
38
+
CURL_DIR=""
 
39
+
CURL_LINK="-lcurl"
 
40
+
YAJL_DIR=""
 
41
+
YAJL_LINK="-lyajl"
 
42
+
 
43
+
# Compiler flag for linking with the built REST VOL
 
44
+
REST_VOL_LINK="-lrestvol"
 
45
+
 
46
+
# Extra compiler options passed to the various steps, such as -Wall
 
47
+
COMP_OPTS="-Wall -pedantic -Wunused-macros"
 
48
+
 
49
+
# Extra options passed to the REST VOLs configure script
 
50
+
RV_OPTS=""
 
51
+
 
52
+
 
53
+
echo
 
54
+
echo "*************************"
 
55
+
echo "* REST VOL build script *"
 
56
+
echo "*************************"
 
57
+
echo
 
58
+
 
59
+
optspec=":hCtdmH:c:y:p:-"
 
60
+
while getopts "$optspec" optchar; do
 
61
+
    case "${optchar}" in
 
62
+
    h)
 
63
+
        echo "usage: $0 [OPTIONS]"
 
64
+
        echo
 
65
+
        echo "      -h      Print this help message."
 
66
+
        echo
 
67
+
        echo "      -d      Enable debugging output in the REST VOL."
 
68
+
        echo
 
69
+
        echo "      -C      Enable cURL debugging output in the REST VOL."
 
70
+
        echo
 
71
+
        echo "      -m      Enable memory tracking in the REST VOL."
 
72
+
        echo
 
73
+
        echo "      -H DIR  To specify a directory where HDF5 has already"
 
74
+
        echo "              been built."
 
75
+
        echo
 
76
+
        echo "      -p DIR  Similar to 'configure --prefix', specifies where"
 
77
+
        echo "              the REST VOL should be installed to. Default is"
 
78
+
        echo "              'source directory/rest_vol_build'."
 
79
+
        echo
 
80
+
        echo "      -c DIR  To specify the top-level directory where cURL is"
 
81
+
        echo "              installed, if cURL was not installed to a system"
 
82
+
        echo "              directory."
 
83
+
        echo
 
84
+
        echo "      -y DIR  To specify the top-level directory where YAJL is"
 
85
+
        echo "              installed, if YAJL was not installed to a system"
 
86
+
        echo "              directory."
 
87
+
        echo
 
88
+
        echo "      -t      Build the tools with REST VOL support. Note"
 
89
+
        echo "              that due to a circular build dependency, this"
 
90
+
        echo "              option should not be chosen until after the"
 
91
+
        echo "              included HDF5 source distribution and the"
 
92
+
        echo "              REST VOL plugin have been built once."
 
93
+
        echo
 
94
+
        exit 0
 
95
+
        ;;
 
96
+
    H)
 
97
+
        build_hdf5=false
 
98
+
        HDF5_INSTALL_DIR=$OPTARG
 
99
+
        RV_OPTS="${RV_OPTS} --with-hdf5=${HDF5_INSTALL_DIR}"
 
100
+
        echo "Set HDF5 install directory to: ${HDF5_INSTALL_DIR}"
 
101
+
        echo
 
102
+
        ;;
 
103
+
    d)
 
104
+
        RV_OPTS="${RV_OPTS} --enable-build-mode=debug"
 
105
+
        echo "Enabled plugin debugging"
 
106
+
        echo
 
107
+
        ;;
 
108
+
    m)
 
109
+
        RV_OPTS="${RV_OPTS} --enable-mem-tracking"
 
110
+
        echo "Enabled plugin memory tracking"
 
111
+
        echo
 
112
+
        ;;
 
113
+
    C)
 
114
+
        RV_OPTS="${RV_OPTS} --enable-curl-debug"
 
115
+
        echo "Enabled cURL debugging"
 
116
+
        echo
 
117
+
        ;;
 
118
+
    p)
 
119
+
        INSTALL_DIR="$OPTARG"
 
120
+
        echo "Prefix set to: ${INSTALL_DIR}"
 
121
+
        echo
 
122
+
        ;;
 
123
+
    c)
 
124
+
        CURL_DIR="$OPTARG"
 
125
+
        CURL_LINK="-L${CURL_DIR}/lib ${CURL_LINK}"
 
126
+
        RV_OPTS="${RV_OPTS} --with-curl=${CURL_DIR}"
 
127
+
        echo "Libcurl directory set to: ${CURL_DIR}"
 
128
+
        echo
 
129
+
        ;;
 
130
+
    y)
 
131
+
        YAJL_DIR="$OPTARG"
 
132
+
        YAJL_LINK="-L${YAJL_DIR}/lib ${YAJL_LINK}"
 
133
+
        RV_OPTS="${RV_OPTS} --with-yajl=${YAJL_DIR}"
 
134
+
        echo "Libyajl directory set to: ${YAJL_DIR}"
 
135
+
        echo
 
136
+
        ;;
 
137
+
    t)
 
138
+
        build_tools=true
 
139
+
        echo "Building tools with REST VOL support"
 
140
+
        echo
 
141
+
        ;;
 
142
+
    *)
 
143
+
        if [ "$OPTERR" != 1 ] || case $optspec in :*) ;; *) false; esac; then
 
144
+
            echo "ERROR: non-option argument: '-${OPTARG}'" >&2
 
145
+
            echo "Quitting"
 
146
+
            exit 1
 
147
+
        fi
 
148
+
        ;;
 
149
+
    esac
 
150
+
done
 
151
+
 
152
+
 
153
+
# Try to determine a good number of cores to use for parallelizing both builds
 
154
+
if [ "$NPROCS" -eq "0" ]; then
 
155
+
    NPROCS=`getconf _NPROCESSORS_ONLN 2> /dev/null`
 
156
+
 
157
+
    # Handle FreeBSD
 
158
+
    if [ -z "$NPROCS" ]; then
 
159
+
        NPROCS=`getconf NPROCESSORS_ONLN 2> /dev/null`
 
160
+
    fi
 
161
+
fi
 
162
+
 
163
+
 
164
+
# If the user hasn't already, first build HDF5
 
165
+
if [ "$build_hdf5" = true ]; then
 
166
+
    echo "*****************"
 
167
+
    echo "* Building HDF5 *"
 
168
+
    echo "*****************"
 
169
+
    echo
 
170
+
 
171
+
    cd ${SCRIPT_DIR}/${HDF5_DIR}
 
172
+
 
173
+
    ./autogen.sh
 
174
+
 
175
+
    # If we are building the tools with REST VOL support, link in the already built
 
176
+
    # REST VOL library, along with cURL and YAJL.
 
177
+
    if [ "${build_tools}" = true ]; then
 
178
+
        ./configure --prefix=${HDF5_INSTALL_DIR} CFLAGS="${COMP_OPTS} -L${INSTALL_DIR}/lib ${REST_VOL_LINK} ${CURL_LINK} ${YAJL_LINK}" || exit 1
 
179
+
    else
 
180
+
        ./configure --prefix=${HDF5_INSTALL_DIR} CFLAGS="${COMP_OPTS}" || exit 1
 
181
+
    fi
 
182
+
 
183
+
    make -j${NPROCS} && make install || exit 1
 
184
+
 
185
+
    # If building the tools with REST VOL support, don't rebuild the REST VOL
 
186
+
    if [ "${build_tools}" = true ]; then
 
187
+
        exit 0
 
188
+
    fi
 
189
+
fi
 
190
+
 
191
+
 
192
+
# Once HDF5 has been built, build the REST VOL plugin against HDF5.
 
193
+
echo "*******************************************"
 
194
+
echo "* Building REST VOL plugin and test suite *"
 
195
+
echo "*******************************************"
 
196
+
echo
 
197
+
 
198
+
cd ${SCRIPT_DIR}
 
199
+
 
200
+
./autogen.sh
 
201
+
 
202
+
./configure --prefix=${INSTALL_DIR} ${RV_OPTS} CFLAGS="${COMP_OPTS}"
 
203
+
 
204
+
make -j${NPROCS} && make install || exit 1
 
205
+
 
206
+
exit 0