Statistics
| Branch: | Revision:

napa-baselibs / build_all.sh @ 1e08ea16

History | View | Annotate | Download (12.2 KB)

1
#!/bin/bash
2
BUILD_ROOT_DIR=`dirname $0`
3
cd "$BUILD_ROOT_DIR"
4
BUILD_ROOT_DIR=`pwd`
5

    
6
#check the architecture
7
if [ "$OSTYPE" == "linux-gnu" ]; then
8
   # do something Linux-y
9
   echo "Building for Linux"
10
elif [ "$OSTYPE" == "darwin10.0" ]; then
11
   # do something OSX-y
12
   echo "Building for OSX"
13
   CFLAGS="$CFLAGS -DMAC_OS"
14
   CXXFLAGS="$CXXFLAGS -DMAC_OS"
15
   OBJ_CHECK=0
16
   [ "$STATIC"==2 ] && STATIC=1
17
fi
18

    
19
if [ -n "$ALL_DIR" ] ; then
20
  [ -e "$ALL_DIR" ] || { echo "Directory in \$ALL_DIR does not exist: $ALL_DIR"; exit 1; }  
21
  [ -z "$LIBEVENT_DIR" ] && LIBEVENT_DIR=$ALL_DIR/libevent
22
  [ -z "$LIBCONFUSE_DIR" ] && LIBCONFUSE_DIR=$ALL_DIR/libconfuse;
23
  [ -z "$LIBXML2_DIR" ] && LIBXML2_DIR=$ALL_DIR/libxml2;
24
fi
25

    
26

    
27
# Control the inclusion of 3rd party libraries
28
# <build_local_if_missing>: download and build if not found locally or in system
29
# <build_local> 	  : download and build if not found locally
30
# <rebuild_local> 	  : rebuild it locally
31
# <system>	          : must be installed in system libs/includes
32
# any_pathname	          : must be installed under specified pathname
33
#
34
# If built locally, it will be built under ${BUILD_ROOT_DIR}/3RDPARTY-LIBS
35

    
36
[ -n "$LIBEVENT_DIR" ] || LIBEVENT_DIR="<build_local>"
37
[ -n "$LIBCONFUSE_DIR" ] || LIBCONFUSE_DIR="<build_local>"
38
[ -n "$LIBXML2_DIR" ] || LIBXML2_DIR="<build_local>"
39

    
40
# leave empty or assign 0 to disable these features.
41
# or assign 1 or anything else to enable them. 
42
# IT IS RECOMMENDED THAT YOU SET THESE FROM THE COMMAND LINE!!!
43
[ -z "$DUMMY" ] && DUMMY=0
44
[ -z "$STATIC" ] && STATIC=1
45
[ -z "$ML" ] && ML=1
46
[ -z "$MONL" ] && MONL=1
47
[ -z "$ALTO" ] && ALTO=1
48
[ -z "$RTX" ] && RTX=1
49

    
50
# Refresh base libraries if this is an svn checkout?
51
[ -n "$UPDATE_BASELIBS" ] || UPDATE_BASELIBS="" 
52
# Unconditionally clean and rebuild base libraries? 
53
[ -n "$REBUILD_BASELIBS" ] || REBUILD_BASELIBS=""
54

    
55
#which flex || { echo "please install flex!"; exit 1; }
56
#which libtoolize || { echo "please install libtool!"; exit 1; }
57
WGET_OR_CURL=`which wget`
58
[ -n "$WGET_OR_CURL" ] || { WGET_OR_CURL=`which curl` ; WGET_OR_CURLOPT="-L -O"; }
59
[ -n "$WGET_OR_CURL" ] || { echo "please install wget or curl!"; exit 1; }
60
which autoconf >/dev/null || { echo "please install autoconf!"; exit 1; }
61
#which autopoint || { echo "please install gettext (or autopoint) !"; exit 1; }
62

    
63
###############################################################################
64
####### Under normal conditions, the lines below should not be changed ########
65
###############################################################################
66

    
67
# option value of '0' is equivalent to empty
68
[ "$DUMMY" == "0" ] && DUMMY=
69
[ "$STATIC" == "0" ] && STATIC=
70
[ "$ML" == "0" ] && ML=
71
[ "$MONL" == "0" ] && MONL=
72
[ "$ALTO" == "0" ] && ALTO=
73
[ "$RTX" == "0" ] && RTX=
74

    
75
# if not empty, options are set to '1' (except for STATIC)
76
[ -n "$DUMMY" ] && DUMMY=0
77
[ -n "$ML" ] && ML=1
78
[ -n "$MONL" ] && MONL=1
79
[ -n "$ALTO" ] && ALTO=1
80

    
81
if [ -n "$RTX" ]; then
82
	CFLAGS="$CFLAGS -DRTX"
83
	CXXFLAGS="$CXXFLAGS -DRTX"
84
fi
85

    
86
#Set the otpions to use with configure
87
[ -n "$CFLAGS" ] && CONF_CFLAGS="CFLAGS='$CFLAGS'"
88
[ -n "$CXXFLAGS" ] && CONF_CXXFLAGS="CXXFLAGS='$CXXFLAGS'"
89

    
90
if [ "$OSTYPE" == "linux-gnu" ]; then
91
  MAKE="make -j `grep processor /proc/cpuinfo | wc -l`"
92
else
93
  MAKE="make -j 4"
94
fi
95

    
96
THIRDPARTY_DIR="${BUILD_ROOT_DIR}/3RDPARTY-LIBS"
97
[ -z "$DOWNLOAD_CACHE" ] && { DOWNLOAD_CACHE="${THIRDPARTY_DIR}/_download_cache"; mkdir -p $DOWNLOAD_CACHE; }
98
[ "$DOWNLOAD_CACHE" == "<no>" ] || [ -d "$DOWNLOAD_CACHE" -a -w "$DOWNLOAD_CACHE" ] || \
99
     { echo "ERROR: Download cache $DOWNLOAD_CACHE is not a writable directory"; exit 1; }
100

    
101
QUICK=false
102
REMOVE_OBJECTS=false
103
FAST_APP_BUILD=false
104

    
105
for ARG in $* ; do
106
  [ "$ARG" == "-q" ] && QUICK=true
107
  [ "$ARG" == "-r" ] && REMOVE_OBJECTS=true
108
  [ "$ARG" == "-f" ] && FAST_APP_BUILD=true
109
done
110

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

    
113
cd "$BUILD_ROOT_DIR"
114
echo; echo; echo
115
if  ! $QUICK  ; then
116
echo "=================================================="
117
echo "Welcome to the NAPA-Wine applications build script"
118
echo "Options for this script:"
119
echo "     -q: quick_build (no user input after phases)"
120
echo "     -r: rebuild (clean NAPA, GRAPES and Streamer. 3rd party libs are not rebuilt)"
121
echo "         WARNING: if this fails, please check out a fresh copy from SVN and start again"
122
echo "     -f: fast (do not make clean in Applications. This may cause build to fail)"
123
echo
124
echo "WARNING: build will most probably fail after an svn update. Use -r. If even that fails"
125
echo "         download a new fresh copy from SVN!"
126
echo "=================================================="
127
echo
128
#echo Build is done in `pwd`
129
echo ">>> Press Enter to continue..."
130
read
131
fi
132

    
133
$REMOVE_OBJECTS && REBUILD_BASELIBS=true && REBUILD_GRAPES=true
134

    
135
get_system_includes() {
136
   DUMMY_FILE=`mktemp temp_file.XXXX`
137
   DUMMY_OUT=`mktemp temp_out.XXXX`
138
   ${CPP:-cpp} -v $DUMMY_FILE 2>$DUMMY_OUT;
139
   INC_DIRS1=`awk '/#include <...> search.*/, /^End.*/' <$DUMMY_OUT | grep -v '^#include\|^End'`
140
   GCC_INCLUDEPATH=""
141
   for D in $INC_DIRS1 ; do GCC_INCLUDEPATH="$GCC_INCLUDEPATH:$D" ; done;
142
   rm -f $DUMMY_FILE $DUMMY_OUT
143
   echo "Your system includes are: $GCC_INCLUDEPATH"
144
}
145

    
146

    
147
get_system_libs() {
148
   GCC_LIBPATH=`gcc -print-search-dirs  | grep "^libraries:" | sed -e 's/^libraries.*=//'`
149
   GCC_LIBPATH="$GCC_LIBPATH:/usr/local/lib"    
150
   echo "Your system libdirs are: $GCC_LIBPATH"
151
}
152

    
153
check_files_in_system_paths() {
154
   FILENAMES=$1
155

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

    
241
       echo "Downloading $LIB_NAME"  
242
       mkdir -p $LIB_HOME/_src; 
243
       pushd $LIB_HOME
244
       cd _src
245
       eval "$DOWNLOAD_CMD" || { echo "ERROR Downloading $LIB_NAME" ; exit 1; }
246
       cd ..
247

    
248
       echo "Building $LIB_NAME"  
249
       cd _src/*/.
250
       eval "$BUILD_CMD" || { echo "ERROR BUilding $LIB_NAME" ; exit 1; }
251
       popd
252
    fi      
253
    if [ -n "$LIB_HOME" ] ; then
254
       for F in $TEST_FILES ; do
255
          MISSING=
256
          if [ ! -e "$LIB_HOME/include/$F" -a ! -e "$LIB_HOME/lib/$F" ] ; then
257
            MISSING=true  
258
            echo "$F not found in $LIB_HOME" 
259
          fi
260
       done
261
       [ -n "$MISSING" ] && \
262
          { echo "ERROR: $LIB_NAME not found in $LIB_HOME"; exit 1; } 
263
       echo "INFO: $LIB_NAME is found in $LIB_HOME"
264
    fi
265
    eval "$LIB_DIR_VARNAME=$LIB_HOME"
266
}
267

    
268
prepare_libs() {
269
get_system_includes
270
get_system_libs
271

    
272
prepare_lib libevent LIBEVENT_DIR "event2/event.h libevent.a" \
273
        "cache_or_wget http://www.monkey.org/~provos/libevent-2.0.3-alpha.tar.gz; \
274
                  tar xvzf libevent-2.0.3-alpha.tar.gz" \
275
			 "./configure --prefix=\$LIB_HOME ${HOSTARCH:+--host=$HOSTARCH};\
276
        $MAKE; make install" 
277

    
278
prepare_lib libconfuse LIBCONFUSE_DIR "confuse.h libconfuse.a" \
279
	"cache_or_wget http://savannah.nongnu.org/download/confuse/confuse-2.7.tar.gz;\
280
	tar xvzf confuse-2.7.tar.gz" \
281
			 "./configure --disable-examples --prefix=\$LIB_HOME  ${HOSTARCH:+--host=$HOSTARCH};\
282
			 $MAKE; make install" 
283
[ `uname -m` = x86_64 ] && LIBEXPAT_HACK='--with-expat=builtin'
284

    
285
if [ -n "$ALTO" ] ; then
286
prepare_lib libxml2 LIBXML2_DIR "libxml2/libxml/xmlversion.h libxml2/libxml/xmlIO.h libxml2/libxml/parser.h libxml2/libxml/tree.h libxml2.a" \
287
        "cache_or_wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz; \
288
              tar xvzf libxml2-2.7.6.tar.gz" \
289
        "./configure --with-python=no --with-threads --prefix=\$LIB_HOME  ${HOSTARCH:+--host=$HOSTARCH};\
290
		    $MAKE; make install" 
291
fi
292
}
293

    
294
prepare_libs 
295

    
296
grep -q "^<" <<<$LIBEVENT_DIR  && LIBEVENT_DIR=
297
grep -q "^<" <<<$LIBCONFUSE_DIR  && LIBCONFUSE_DIR=
298
grep -q "^<" <<<$LIBXML2_DIR  && LIBXML2_DIR=
299

    
300
echo "=============== YOUR 3RDPARTY DIRECTORIES ============"
301
echo "LIBEVENT_DIR=$LIBEVENT_DIR" 
302
echo "LIBCONFUSE_DIR=$LIBCONFUSE_DIR" 
303
echo "LIBXML2_DIR=$LIBXML2_DIR"
304

    
305
echo
306
echo ">>> Press enter continue with building NAPA-BASELIBS..."
307
$QUICK || read
308

    
309
export LIBEVENT_DIR LIBCONFUSE_DIR LIBXML2_DIR
310

    
311
   EVOPT= ; [ -n LIBEVENT_DIR ] && EVOPT="--with-libevent2=$LIBEVENT_DIR"
312
   CONFOPT= ; [ -n LIBCONFUSE_DIR ] && CONFOPT="--with-libconfuse=$LIBCONFUSE_DIR"
313
   if [ -e .svn -a -n "$UPDATE_BASELIBS" ] ; then
314
      svn update
315
   fi
316
   if [ ! -e Makefile -o -n "$REBUILD_BASELIBS" ] ; then
317
     [ -e Makefile ] && $MAKE distclean
318
   mkdir -p m4 config
319
     autoreconf --force -I config -I m4 --install
320
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}"
321
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}" > conf.sh
322
     sh conf.sh
323
     echo "//blah" > common/chunk.c
324
   fi
325
   ALTO_NEEDED=`grep 1 <<<"$ALTO"`
326
   for SUBDIR in dclog common monl rep ${ALTO_NEEDED:+ALTOclient} ; do
327
       echo "Making `pwd`/$SUBDIR"
328
       $MAKE -C $SUBDIR || { echo "ERROR Building $SUBDIR"; exit 1; }
329
   done
330
   cd ml
331
      if [ ! -e Makefile -o -n "$REBUILD_BASELIBS" ] ; then
332
        mkdir -p m4 config
333
        autoreconf --force -I config -I m4 --install
334
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}"
335
     echo "./configure $EVOPT $CONFOPT $CONF_CFLAGS $CONF_CXXFLAGS ${HOSTARCH:+--host=$HOSTARCH}" > conf.sh
336
     sh conf.sh
337
	$MAKE clean
338
      fi
339
      $MAKE || { echo "ERROR Building ml"; exit 1; }
340
   cd .. 
341

    
342
echo "=============== YOUR NAPA-BASELIBS ============"
343
find . -name '*.a' -exec ls -l '{}' ';'
344
echo