Statistics
| Branch: | Revision:

napa-baselibs / build_all.sh @ 0c1b0f20

History | View | Annotate | Download (11.9 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; }  
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
MAKE="make -j `grep processor /proc/cpuinfo | wc -l`"
91

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

    
97
QUICK=false
98
REMOVE_OBJECTS=false
99
FAST_APP_BUILD=false
100

    
101
for ARG in $* ; do
102
  [ "$ARG" == "-q" ] && QUICK=true
103
  [ "$ARG" == "-r" ] && REMOVE_OBJECTS=true
104
  [ "$ARG" == "-f" ] && FAST_APP_BUILD=true
105
done
106

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

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

    
129
$REMOVE_OBJECTS && REBUILD_BASELIBS=true && REBUILD_GRAPES=true
130

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

    
142

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

    
149
check_files_in_system_paths() {
150
   FILENAMES=$1
151

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

    
237
       echo "Downloading $LIB_NAME"  
238
       mkdir -p $LIB_HOME/_src; 
239
       pushd $LIB_HOME
240
       cd _src
241
       eval "$DOWNLOAD_CMD" || { echo "ERROR Downloading $LIB_NAME" ; exit; }
242
       cd ..
243

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

    
264
prepare_libs() {
265
get_system_includes
266
get_system_libs
267

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

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

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

    
290
prepare_libs 
291

    
292
grep -q "^<" <<<$LIBEVENT_DIR  && LIBEVENT_DIR=
293
grep -q "^<" <<<$LIBCONFUSE_DIR  && LIBCONFUSE_DIR=
294
grep -q "^<" <<<$LIBXML2_DIR  && LIBXML2_DIR=
295

    
296
echo "=============== YOUR 3RDPARTY DIRECTORIES ============"
297
echo "LIBEVENT_DIR=$LIBEVENT_DIR" 
298
echo "LIBCONFUSE_DIR=$LIBCONFUSE_DIR" 
299
echo "LIBXML2_DIR=$LIBXML2_DIR"
300

    
301
echo
302
echo ">>> Press enter continue with building NAPA-BASELIBS..."
303
$QUICK || read
304

    
305
export LIBEVENT_DIR LIBCONFUSE_DIR LIBXML2_DIR
306

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

    
337
echo "=============== YOUR NAPA-BASELIBS ============"
338
find . -name '*.a' -exec ls -l '{}' ';'
339
echo