Statistics
| Branch: | Revision:

napa-baselibs / build_all.sh @ 6791077e

History | View | Annotate | Download (11.4 KB)

1
#!/bin/bash
2
SCRIPT=$(readlink -f $0)
3
BUILD_ROOT_DIR=`dirname $SCRIPT`
4

    
5
cd "$BUILD_ROOT_DIR"
6
if [ -n "$ALL_DIR" ] ; then
7
  [ -e "$ALL_DIR" ] || { echo "Directory in \$ALL_DIR does not exist: $ALL_DIR"; exit; }  
8
  [ -z "$LIBEVENT_DIR" ] && LIBEVENT_DIR=$ALL_DIR/libevent
9
  [ -z "$LIBCONFUSE_DIR" ] && LIBCONFUSE_DIR=$ALL_DIR/libconfuse;
10
  [ -z "$LIBXML2_DIR" ] && LIBXML2_DIR=$ALL_DIR/libxml2;
11
fi
12

    
13

    
14
# Control the inclusion of 3rd party libraries
15
# <build_local_if_missing>: download and build if not found locally or in system
16
# <build_local> 	  : download and build if not found locally
17
# <rebuild_local> 	  : rebuild it locally
18
# <system>	          : must be installed in system libs/includes
19
# any_pathname	          : must be installed under specified pathname
20
#
21
# If built locally, it will be built under ${BUILD_ROOT_DIR}/3RDPARTY-LIBS
22

    
23
[ -n "$LIBEVENT_DIR" ] || LIBEVENT_DIR="<build_local>"
24
[ -n "$LIBCONFUSE_DIR" ] || LIBCONFUSE_DIR="<build_local>"
25
[ -n "$LIBXML2_DIR" ] || LIBXML2_DIR="<build_local>"
26

    
27
# leave empty or assign 0 to disable these features.
28
# or assign 1 or anything else to enable them. 
29
# IT IS RECOMMENDED THAT YOU SET THESE FROM THE COMMAND LINE!!!
30
[ -z "$DUMMY" ] && DUMMY=0
31
[ -z "$STATIC" ] && STATIC=1
32
[ -z "$ML" ] && ML=1
33
[ -z "$MONL" ] && MONL=1
34
[ -z "$ALTO" ] && ALTO=1
35
[ -z "$RTX" ] && RTX=1
36

    
37
# Refresh base libraries if this is an svn checkout?
38
[ -n "$UPDATE_BASELIBS" ] || UPDATE_BASELIBS="" 
39
# Unconditionally clean and rebuild base libraries? 
40
[ -n "$REBUILD_BASELIBS" ] || REBUILD_BASELIBS=""
41

    
42
#which flex || { echo "please install flex!"; exit 1; }
43
#which libtoolize || { echo "please install libtool!"; exit 1; }
44
WGET_OR_CURL=`which wget`
45
[ -n "$WGET_OR_CURL" ] || { WGET_OR_CURL=`which curl` ; WGET_OR_CURLOPT="-L -O"; }
46
[ -n "$WGET_OR_CURL" ] || { echo "please install wget or curl!"; exit 1; }
47
which autoconf >/dev/null || { echo "please install autoconf!"; exit 1; }
48
#which autopoint || { echo "please install gettext (or autopoint) !"; exit 1; }
49

    
50
###############################################################################
51
####### Under normal conditions, the lines below should not be changed ########
52
###############################################################################
53

    
54
# option value of '0' is equivalent to empty
55
[ "$DUMMY" == "0" ] && DUMMY=
56
[ "$STATIC" == "0" ] && STATIC=
57
[ "$ML" == "0" ] && ML=
58
[ "$MONL" == "0" ] && MONL=
59
[ "$ALTO" == "0" ] && ALTO=
60
[ "$RTX" == "0" ] && RTX=
61

    
62
# if not empty, options are set to '1' (except for STATIC)
63
[ -n "$DUMMY" ] && DUMMY=0
64
[ -n "$ML" ] && ML=1
65
[ -n "$MONL" ] && MONL=1
66
[ -n "$ALTO" ] && ALTO=1
67

    
68
if [ -n "$RTX" ]; then
69
	CFLAGS="$CFLAGS -DRTX"
70
	CXXFLAGS="$CXXFLAGS -DRTX"
71
fi
72

    
73
#Set the otpions to use with configure
74
[ -n "$CFLAGS" ] && CONF_CFLAGS="CFLAGS='$CFLAGS'"
75
[ -n "$CXXFLAGS" ] && CONF_CXXFLAGS="CXXFLAGS='$CXXFLAGS'"
76

    
77
MAKE="make -j `grep processor /proc/cpuinfo | wc -l`"
78

    
79
THIRDPARTY_DIR="${BUILD_ROOT_DIR}/3RDPARTY-LIBS"
80
[ -z "$DOWNLOAD_CACHE" ] && { DOWNLOAD_CACHE="${THIRDPARTY_DIR}/_download_cache"; mkdir -p $DOWNLOAD_CACHE; }
81
[ "$DOWNLOAD_CACHE" == "<no>" ] || [ -d "$DOWNLOAD_CACHE" -a -w "$DOWNLOAD_CACHE" ] || \
82
     { echo "ERROR: Download cache $DOWNLOAD_CACHE is not a writable directory"; exit; }
83

    
84
QUICK=false
85
REMOVE_OBJECTS=false
86
FAST_APP_BUILD=false
87

    
88
for ARG in $* ; do
89
  [ "$ARG" == "-q" ] && QUICK=true
90
  [ "$ARG" == "-r" ] && REMOVE_OBJECTS=true
91
  [ "$ARG" == "-f" ] && FAST_APP_BUILD=true
92
done
93

    
94
$REMOVE_OBJECTS && $FAST_APP_BUILD && echo "-r and -f can't be used together" && exit 1
95

    
96
cd "$BUILD_ROOT_DIR"
97
echo; echo; echo
98
if  ! $QUICK  ; then
99
echo "=================================================="
100
echo "Welcome to the NAPA-Wine applications build script"
101
echo "Options for this script:"
102
echo "     -q: quick_build (no user input after phases)"
103
echo "     -r: rebuild (clean NAPA, GRAPES and Streamer. 3rd party libs are not rebuilt)"
104
echo "         WARNING: if this fails, please check out a fresh copy from SVN and start again"
105
echo "     -f: fast (do not make clean in Applications. This may cause build to fail)"
106
echo
107
echo "WARNING: build will most probably fail after an svn update. Use -r. If even that fails"
108
echo "         download a new fresh copy from SVN!"
109
echo "=================================================="
110
echo
111
#echo Build is done in `pwd`
112
echo ">>> Press Enter to continue..."
113
read
114
fi
115

    
116
$REMOVE_OBJECTS && REBUILD_BASELIBS=true && REBUILD_GRAPES=true
117

    
118
get_system_includes() {
119
   DUMMY_FILE=`mktemp`
120
   DUMMY_OUT=`mktemp`
121
   cpp -v $DUMMY_FILE 2>$DUMMY_OUT;
122
   INC_DIRS1=`awk '/#include <...> search.*/, /^End.*/' <$DUMMY_OUT | grep -v '^#include\|^End'`
123
   GCC_INCLUDEPATH=""
124
   for D in $INC_DIRS1 ; do GCC_INCLUDEPATH="$GCC_INCLUDEPATH:$D" ; done;
125
   rm -f $DUMMY_FILE $DUMMY_OUT
126
   echo "Your system includes are: $GCC_INCLUDEPATH"
127
}
128

    
129

    
130
get_system_libs() {
131
   GCC_LIBPATH=`gcc -print-search-dirs  | grep "^libraries:" | sed -e 's/^libraries.*=//'`
132
   GCC_LIBPATH="$GCC_LIBPATH:/usr/local/lib"    
133
   echo "Your system libdirs are: $GCC_LIBPATH"
134
}
135

    
136
check_files_in_system_paths() {
137
   FILENAMES=$1
138

    
139
   FOUND_ALL=1   
140
   for FNAME in $FILENAMES ; do 
141
     echo $FNAME | grep -q '\.h$' && SPATH=$GCC_INCLUDEPATH
142
     echo $FNAME | grep -q '\.a$' && SPATH=$GCC_LIBPATH
143
     [ -z "$SPATH" ] && echo "Unknown file type to check: $FNAME (.a and .h supported)" && exit
144
     FOUND=
145
     for P in `tr ":" " " <<<$SPATH` ; do
146
       [ -n "$P" -a -e "$P/$FNAME" ] && FOUND=$P
147
     done
148
     if [ -z "$FOUND" ] ; then
149
          FOUND_ALL= 
150
          echo "$FNAME is not installed on your system"
151
     fi
152
   done
153
   [ -n "$FOUND_ALL" ]
154
} 
155
   
156
cache_or_wget() {
157
	URL=$1
158
		FILE=$2
159
		[ -z "$FILE" ] && FILE=`grep -o '[^/]*$' <<<"$URL"`
160
		if [ "$DOWNLOAD_CACHE" == "<no>" -o ! -e "$DOWNLOAD_CACHE/$FILE" ] ; then 
161
			$WGET_OR_CURL $WGET_OR_CURLOPT $URL || [ ! -e $FILE ] || { echo "ERROR: download of $URL failed"; exit; }
162
	[ "$DOWNLOAD_CACHE" == "<no>" ] || cp $FILE $DOWNLOAD_CACHE;
163
		else 
164
			cp $DOWNLOAD_CACHE/$FILE .
165
				fi
166
}
167
   
168
prepare_lib() {
169
    LIB_NAME="$1"
170
    LIB_DIR_VARNAME="$2"
171
    eval "LIB_DIR=\"\$$2\""
172
#echo $LIB_DIR_VARNAME is $LIB_DIR 
173
    TEST_FILES="$3"
174
    DOWNLOAD_CMD="$4"
175
    BUILD_CMD="$5"
176
    
177
    LIB_HOME="${THIRDPARTY_DIR}/${LIB_NAME}"
178
    if [ "$LIB_DIR" == '<rebuild_local>' ] ; then INSTALL_COMPONENT=true
179
    elif [ "$LIB_DIR" == '<system>' \
180
        -o "$LIB_DIR" == '<build_local>' \
181
	-o "$LIB_DIR" == '<build_local_if_missing>' ] ; then
182
       INSTALL_COMPONENT=true
183
       if [ "$LIB_DIR" == '<build_local>' -o "$LIB_DIR" == '<build_local_if_missing>' ] ; then
184
          for F in $TEST_FILES ; do
185
             INSTALL_COMPONENT=
186
             if [ ! -e "$LIB_HOME/include/$F" -a ! -e "$LIB_HOME/lib/$F" ] ; then
187
   	       INSTALL_COMPONENT=true  
188
             fi
189
             echo "$LIB_HOME/include/$F -o -e $LIB_HOME/lib/$F $INSTALL_COMPONENT" ; 
190
          done
191
       fi
192
       if [ -z "$INSTALL_COMPONENT" ]  ; then
193
          echo "INFO: Library $LIB_NAME is found locally. Will not be rebuilt"  
194
       elif [ "$LIB_DIR" != '<build_local>' ] && check_files_in_system_paths "$TEST_FILES" ; then
195
          echo "INFO: Library $LIB_NAME is deployed on your system"
196
          LIB_HOME=
197
          INSTALL_COMPONENT=
198
       elif [ "$LIB_DIR" == '<system>' ] ; then
199
           echo "ERROR: $LIB_NAME specified as '<system>' but not found on search path"
200
           exit
201
       else
202
          echo "INFO: Library $LIB_NAME will be built locally"
203
       fi
204
      
205
    else 
206
      INSTALL_COMPONENT=
207
      grep -q '^<' <<<$LIB_DIR && \
208
	 { echo "ERROR: Invalid location for $LIB_NAME: $LIB_DIR" ; exit; }
209
      [ -e "$LIB_DIR" ] || \
210
	 { echo "ERROR: Nonexistent location for $LIB_NAME: $LIB_DIR"; exit; }
211
      LIB_HOME=$(readlink -f $LIB_DIR)
212
    fi
213
    if [ -n "$INSTALL_COMPONENT" ] ; then
214
       echo
215
       echo "==============================================="
216
       echo "Installing $LIB_NAME to $LIB_HOME"
217
       echo "==============================================="
218
       echo "INFO: Download command: $DOWNLOAD_CMD"
219
       echo "INFO: Build command: $BUILD_CMD"
220
       echo ">>> Press Enter to proceed..."
221
       $QUICK || read
222
       rm -rf $LIB_HOME
223

    
224
       echo "Downloading $LIB_NAME"  
225
       mkdir -p $LIB_HOME/_src; 
226
       pushd $LIB_HOME
227
       cd _src
228
       eval "$DOWNLOAD_CMD" || { echo "ERROR Downloading $LIB_NAME" ; exit; }
229
       cd ..
230

    
231
       echo "Building $LIB_NAME"  
232
       cd _src/*/.
233
       eval "$BUILD_CMD" || { echo "ERROR BUilding $LIB_NAME" ; exit; }
234
       popd
235
    fi      
236
    if [ -n "$LIB_HOME" ] ; then
237
       for F in $TEST_FILES ; do
238
          MISSING=
239
          if [ ! -e "$LIB_HOME/include/$F" -a ! -e "$LIB_HOME/lib/$F" ] ; then
240
            MISSING=true  
241
            echo "$F not found in $LIB_HOME" 
242
          fi
243
       done
244
       [ -n "$MISSING" ] && \
245
          { echo "ERROR: $LIB_NAME not found in $LIB_HOME"; exit; } 
246
       echo "INFO: $LIB_NAME is found in $LIB_HOME"
247
    fi
248
    eval "$LIB_DIR_VARNAME=$LIB_HOME"
249
}
250

    
251
prepare_libs() {
252
get_system_includes
253
get_system_libs
254

    
255
prepare_lib libevent LIBEVENT_DIR "event2/event.h libevent.a" \
256
        "wget http://www.monkey.org/~provos/libevent-2.0.3-alpha.tar.gz; \
257
                  tar xvzf libevent-2.0.3-alpha.tar.gz" \
258
        "./configure --enable-thread-support --prefix \$LIB_HOME; $MAKE; $MAKE install" 
259

    
260
prepare_lib libconfuse LIBCONFUSE_DIR "confuse.h libconfuse.a" \
261
        "wget http://savannah.nongnu.org/download/confuse/confuse-2.7.tar.gz;\
262
              tar xvzf confuse-2.7.tar.gz" \
263
        "./configure --prefix \$LIB_HOME; $MAKE; $MAKE install" 
264

    
265
[ `uname -m` = x86_64 ] && LIBEXPAT_HACK='--with-expat=builtin'
266

    
267
prepare_lib libxml2 LIBXML2_DIR "libxml2/libxml/xmlversion.h libxml2/libxml/xmlIO.h libxml2/libxml/parser.h libxml2/libxml/tree.h libxml2.a" \
268
        "wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz; \
269
              tar xvzf libxml2-2.7.6.tar.gz" \
270
        "./configure --with-threads --prefix \$LIB_HOME; $MAKE; $MAKE install" 
271
}
272

    
273
prepare_libs 
274

    
275
grep -q "^<" <<<$LIBEVENT_DIR  && LIBEVENT_DIR=
276
grep -q "^<" <<<$LIBCONFUSE_DIR  && LIBCONFUSE_DIR=
277
grep -q "^<" <<<$LIBXML2_DIR  && LIBXML2_DIR=
278

    
279
echo "=============== YOUR 3RDPARTY DIRECTORIES ============"
280
echo "LIBEVENT_DIR=$LIBEVENT_DIR" 
281
echo "LIBCONFUSE_DIR=$LIBCONFUSE_DIR" 
282
echo "LIBXML2_DIR=$LIBXML2_DIR"
283

    
284
echo
285
echo ">>> Press enter continue with building NAPA-BASELIBS..."
286
$QUICK || read
287

    
288
export LIBEVENT_DIR LIBCONFUSE_DIR LIBXML2_DIR
289

    
290
   EVOPT= ; [ -n LIBEVENT_DIR ] && EVOPT="--with-libevent2=$LIBEVENT_DIR"
291
   CONFOPT= ; [ -n LIBCONFUSE_DIR ] && CONFOPT="--with-libconfuse=$LIBCONFUSE_DIR"
292
   if [ -e .svn -a -n "$UPDATE_BASELIBS" ] ; then
293
      svn update
294
   fi
295
   if [ ! -e Makefile -o -n "$REBUILD_BASELIBS" ] ; then
296
     [ -e Makefile ] && $MAKE distclean
297
   mkdir -p m4 config
298
     autoreconf --force -I config -I m4 --install
299
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}"
300
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}" > conf.sh
301
     sh conf.sh
302
     echo "//blah" > common/chunk.c
303
   fi
304
   for SUBDIR in dclog common monl rep ALTOclient ; do
305
       echo "Making `pwd`/$SUBDIR"
306
       $MAKE -C $SUBDIR
307
   done
308
   cd ml
309
      if [ ! -e Makefile -o -n "$REBUILD_BASELIBS" ] ; then
310
        mkdir -p m4 config
311
        autoreconf --force -I config -I m4 --install
312
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}"
313
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}" > conf.sh
314
     sh conf.sh
315
	$MAKE clean
316
      fi
317
      $MAKE
318
   cd .. 
319

    
320
echo "=============== YOUR NAPA-BASELIBS ============"
321
find . -name '*.a' -exec ls -l '{}' ';'
322
echo