Statistics
| Branch: | Revision:

napa-baselibs / build_all.sh @ 3f532f20

History | View | Annotate | Download (10.5 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 "$LOG4C_DIR" ] && LOG4C_DIR=$ALL_DIR/log4c;
11
  [ -z "$LIBXML2_DIR" ] && LIBXML2_DIR=$ALL_DIR/libxml2;
12
fi
13

    
14

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

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

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

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

    
44
#which flex || { echo "please install flex!"; exit 1; }
45
#which libtoolize || { echo "please install libtool!"; exit 1; }
46
which autoconf >/dev/null || { echo "please install autoconf!"; exit 1; }
47
#which autopoint || { echo "please install gettext (or autopoint) !"; exit 1; }
48

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

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

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

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

    
72
MAKE="make -j `grep processor /proc/cpuinfo | wc -l`"
73

    
74
THIRDPARTY_DIR="${BUILD_ROOT_DIR}/3RDPARTY-LIBS"
75

    
76
QUICK=false
77
REMOVE_OBJECTS=false
78
FAST_APP_BUILD=false
79

    
80
for ARG in $* ; do
81
  [ "$ARG" == "-q" ] && QUICK=true
82
  [ "$ARG" == "-r" ] && REMOVE_OBJECTS=true
83
  [ "$ARG" == "-f" ] && FAST_APP_BUILD=true
84
done
85

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

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

    
108
$REMOVE_OBJECTS && REBUILD_BASELIBS=true && REBUILD_GRAPES=true
109

    
110
get_system_includes() {
111
   DUMMY_FILE=`mktemp`
112
   DUMMY_OUT=`mktemp`
113
   cpp -v $DUMMY_FILE 2>$DUMMY_OUT;
114
   INC_DIRS1=`awk '/#include <...> search.*/, /^End.*/' <$DUMMY_OUT | grep -v '^#include\|^End'`
115
   GCC_INCLUDEPATH=""
116
   for D in $INC_DIRS1 ; do GCC_INCLUDEPATH="$GCC_INCLUDEPATH:$D" ; done;
117
   rm -f $DUMMY_FILE $DUMMY_OUT
118
   echo "Your system includes are: $GCC_INCLUDEPATH"
119
}
120

    
121

    
122
get_system_libs() {
123
   GCC_LIBPATH=`gcc -print-search-dirs  | grep "^libraries:" | sed -e 's/^libraries.*=//'`
124
   GCC_LIBPATH="$GCC_LIBPATH:/usr/local/lib"    
125
   echo "Your system libdirs are: $GCC_LIBPATH"
126
}
127

    
128
check_files_in_system_paths() {
129
   FILENAMES=$1
130

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

    
205
       echo "Downloading $LIB_NAME"  
206
       mkdir -p $LIB_HOME/_src; 
207
       pushd $LIB_HOME
208
       cd _src
209
       eval "$DOWNLOAD_CMD" || { echo "ERROR Downloading $LIB_NAME" ; exit; }
210
       cd ..
211

    
212
       echo "Building $LIB_NAME"  
213
       cd _src/*/.
214
       eval "$BUILD_CMD" || { echo "ERROR BUilding $LIB_NAME" ; exit; }
215
       popd
216
    fi      
217
    if [ -n "$LIB_HOME" ] ; then
218
       for F in $TEST_FILES ; do
219
          MISSING=
220
          if [ ! -e "$LIB_HOME/include/$F" -a ! -e "$LIB_HOME/lib/$F" ] ; then
221
            MISSING=true  
222
            echo "$F not found in $LIB_HOME" 
223
          fi
224
       done
225
       [ -n "$MISSING" ] && \
226
          { echo "ERROR: $LIB_NAME not found in $LIB_HOME"; exit; } 
227
       echo "INFO: $LIB_NAME is found in $LIB_HOME"
228
    fi
229
    eval "$LIB_DIR_VARNAME=$LIB_HOME"
230
}
231

    
232
prepare_libs() {
233
get_system_includes
234
get_system_libs
235

    
236
prepare_lib libevent LIBEVENT_DIR "event2/event.h libevent.a" \
237
        "wget http://www.monkey.org/~provos/libevent-2.0.3-alpha.tar.gz; \
238
                  tar xvzf libevent-2.0.3-alpha.tar.gz" \
239
        "./configure --enable-thread-support --prefix \$LIB_HOME; $MAKE; $MAKE install" 
240

    
241
prepare_lib libconfuse LIBCONFUSE_DIR "confuse.h libconfuse.a" \
242
        "wget http://savannah.nongnu.org/download/confuse/confuse-2.7.tar.gz;\
243
              tar xvzf confuse-2.7.tar.gz" \
244
        "./configure --prefix \$LIB_HOME; $MAKE; $MAKE install" 
245

    
246
[ `uname -m` = x86_64 ] && LIBEXPAT_HACK='--with-expat=builtin'
247

    
248
prepare_lib log4c LOG4C_DIR "log4c.h liblog4c.a" \
249
        "wget http://downloads.sourceforge.net/project/log4c/log4c/1.2.1/log4c-1.2.1.tar.gz; \
250
              tar xvzf log4c-1.2.1.tar.gz" \
251
        "./configure --prefix \$LIB_HOME $LIBEXPAT_HACK; $MAKE; $MAKE install"
252

    
253
prepare_lib libxml2 LIBXML2_DIR "libxml2/libxml/xmlversion.h libxml2/libxml/xmlIO.h libxml2/libxml/parser.h libxml2/libxml/tree.h libxml2.a" \
254
        "wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz; \
255
              tar xvzf libxml2-2.7.6.tar.gz" \
256
        "./configure --with-threads --prefix \$LIB_HOME; $MAKE; $MAKE install" 
257
}
258

    
259
prepare_libs 
260

    
261
grep -q "^<" <<<$LIBEVENT_DIR  && LIBEVENT_DIR=
262
grep -q "^<" <<<$LIBCONFUSE_DIR  && LIBCONFUSE_DIR=
263
grep -q "^<" <<<$LIBXML2_DIR  && LIBXML2_DIR=
264

    
265
echo "=============== YOUR 3RDPARTY DIRECTORIES ============"
266
echo "LIBEVENT_DIR=$LIBEVENT_DIR" 
267
echo "LIBCONFUSE_DIR=$LIBCONFUSE_DIR" 
268
echo "LOG4C_DIR=$LOG4C_DIR" 
269
echo "LIBXML2_DIR=$LIBXML2_DIR"
270

    
271
echo
272
echo ">>> Press enter continue with building NAPA-BASELIBS..."
273
$QUICK || read
274

    
275
export LIBEVENT_DIR LIBCONFUSE_DIR LIBXML2_DIR
276

    
277
   EVOPT= ; [ -n LIBEVENT_DIR ] && EVOPT="--with-libevent2=$LIBEVENT_DIR"
278
   CONFOPT= ; [ -n LIBCONFUSE_DIR ] && CONFOPT="--with-libconfuse=$LIBCONFUSE_DIR"
279
   if [ -e .svn -a -n "$UPDATE_BASELIBS" ] ; then
280
      svn update
281
   fi
282
   if [ ! -e Makefile -o -n "$REBUILD_BASELIBS" ] ; then
283
     [ -e Makefile ] && $MAKE distclean
284
   mkdir -p m4 config
285
     autoreconf --force -I config -I m4 --install
286
     ./configure $EVOPT $CONFOPT
287
     echo "//blah" > common/chunk.c
288
   fi
289
   for SUBDIR in dclog common monl rep ALTOclient ; do
290
       echo "Making `pwd`/$SUBDIR"
291
       $MAKE -C $SUBDIR
292
   done
293
   cd ml
294
      if [ ! -e Makefile -o -n "$REBUILD_BASELIBS" ] ; then
295
        mkdir -p m4 config
296
        autoreconf --force -I config -I m4 --install
297
        ./configure $EVOPT $CONFOPT
298
	$MAKE clean
299
      fi
300
      $MAKE
301
   cd .. 
302

    
303
echo "=============== YOUR NAPA-BASELIBS ============"
304
find . -name '*.a' -exec ls -l '{}' ';'
305
echo