Whamcloud - gitweb
Branch b1_6
[fs/lustre-release.git] / lustre / liblustre / genlib.sh
1 #!/bin/bash
2 #set -xv
3 set -e
4
5 #
6 # This script is to generate lib lustre library as a whole. It will leave
7 # two files on current directory: liblustre.a and liblustre.so.
8 #
9 # Most concern here is the libraries linking order
10 #
11 # FIXME: How to do this cleanly use makefile?
12 #
13
14 AR=/usr/bin/ar
15 # see http://osdir.com/ml/gmane.comp.gnu.binutils.bugs/2006-01/msg00016.php
16 LD=gcc
17 RANLIB=/usr/bin/ranlib
18
19 CWD=`pwd`
20
21 SYSIO=$1
22 LIBS=$2
23 LND_LIBS=$3
24 PTHREAD_LIBS=$4
25 QUOTA_LIBS=$5
26 CAP_LIBS=$6
27 ZLIB=$7
28
29 if [ ! -f $SYSIO/lib/libsysio.a ]; then
30   echo "ERROR: $SYSIO/lib/libsysio.a dosen't exist"
31   exit 1
32 fi
33
34 # do cleanup at first
35 rm -f liblustre.so
36
37 ALL_OBJS=
38
39 build_obj_list() {
40   _objs=`$AR -t $1/$2`
41   for _lib in $_objs; do
42     ALL_OBJS=$ALL_OBJS"$1/$_lib ";
43   done;
44 }
45
46 #
47 # special treatment for libsysio
48 #
49 sysio_tmp=$CWD/sysio_tmp_`date +%s`
50 rm -rf $sysio_tmp
51 build_sysio_obj_list() {
52   _objs=`$AR -t $1`
53   mkdir -p $sysio_tmp
54   cd $sysio_tmp
55   $AR -x $1
56   cd ..
57   for _lib in $_objs; do
58     ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
59   done
60 }
61
62 # lustre components libs
63 build_obj_list . libllite.a
64 build_obj_list ../lov liblov.a
65 build_obj_list ../obdecho libobdecho.a
66 build_obj_list ../osc libosc.a
67 build_obj_list ../mdc libmdc.a
68 build_obj_list ../mgc libmgc.a
69 build_obj_list ../ptlrpc libptlrpc.a
70 build_obj_list ../obdclass liblustreclass.a
71 build_obj_list ../lvfs liblvfs.a
72
73 # lnet components libs
74 build_obj_list ../../lnet/utils libuptlctl.a
75 build_obj_list ../../lnet/libcfs libcfs.a
76 if $(echo "$LND_LIBS" | grep "socklnd" >/dev/null) ; then
77         build_obj_list ../../lnet/ulnds/socklnd libsocklnd.a
78 fi
79 if $(echo "$LND_LIBS" | grep "ptllnd" >/dev/null) ; then
80         build_obj_list ../../lnet/ulnds/ptllnd libptllnd.a
81 fi
82 build_obj_list ../../lnet/lnet liblnet.a
83
84 if [ "x$QUOTA_LIBS" != "x" ]; then
85   build_obj_list ../quota libquota.a
86 fi
87
88 # create static lib lsupport
89 rm -f $CWD/liblsupport.a
90 $AR -cru $CWD/liblsupport.a $ALL_OBJS
91 $RANLIB $CWD/liblsupport.a
92
93 # if libsysio is already in our LIBS we don't need to link against it here
94 if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
95   build_sysio_obj_list $SYSIO/lib/libsysio.a
96 fi
97
98 # create static lib lustre
99 rm -f $CWD/liblustre.a
100 $AR -cru $CWD/liblustre.a $ALL_OBJS
101 $RANLIB $CWD/liblustre.a
102
103 # create shared lib lustre
104 rm -f $CWD/liblustre.so
105 OS=`uname`
106 if test x$OS = xAIX; then
107 $LD -shared -o $CWD/liblustre.so $ALL_OBJS -lpthread -Xlinker -bnoipath ../../libsyscall.so
108 else
109 $LD -shared -nostdlib -o $CWD/liblustre.so $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS $ZLIB
110 fi
111
112 rm -rf $sysio_tmp