Whamcloud - gitweb
Branch HEAD
[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
28 if [ ! -f $SYSIO/lib/libsysio.a ]; then
29   echo "ERROR: $SYSIO/lib/libsysio.a dosen't exist"
30   exit 1
31 fi
32
33 # do cleanup at first
34 rm -f liblustre.so
35
36 ALL_OBJS=
37
38 build_obj_list() {
39   _objs=`$AR -t $1/$2`
40   for _lib in $_objs; do
41     ALL_OBJS=$ALL_OBJS"$1/$_lib ";
42   done;
43 }
44
45 #
46 # special treatment for libsysio
47 #
48 sysio_tmp=$CWD/sysio_tmp_`date +%s`
49 rm -rf $sysio_tmp
50 build_sysio_obj_list() {
51   _objs=`$AR -t $1`
52   mkdir -p $sysio_tmp
53   cd $sysio_tmp
54   $AR -x $1
55   cd ..
56   for _lib in $_objs; do
57     ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
58   done
59 }
60
61 # lustre components libs
62 build_obj_list . libllite.a
63 build_obj_list ../lov liblov.a
64 build_obj_list ../obdecho libobdecho.a
65 build_obj_list ../osc libosc.a
66 build_obj_list ../lmv liblmv.a
67 build_obj_list ../mdc libmdc.a
68 build_obj_list ../fid libfid.a
69 build_obj_list ../fld libfld.a
70 build_obj_list ../mgc libmgc.a
71 build_obj_list ../ptlrpc libptlrpc.a
72 build_obj_list ../obdclass liblustreclass.a
73 build_obj_list ../lvfs liblvfs.a
74
75 # lnet components libs
76 build_obj_list ../../lnet/utils libuptlctl.a
77 build_obj_list ../../lnet/libcfs libcfs.a
78 if $(echo "$LND_LIBS" | grep "socklnd" >/dev/null) ; then
79         build_obj_list ../../lnet/ulnds/socklnd libsocklnd.a
80 fi
81 if $(echo "$LND_LIBS" | grep "ptllnd" >/dev/null) ; then
82         build_obj_list ../../lnet/ulnds/ptllnd libptllnd.a
83 fi
84 build_obj_list ../../lnet/lnet liblnet.a
85
86 if [ "x$QUOTA_LIBS" != "x" ]; then
87   build_obj_list ../quota libquota.a
88 fi
89
90 # create static lib lsupport
91 rm -f $CWD/liblsupport.a
92 $AR -cru $CWD/liblsupport.a $ALL_OBJS
93 $RANLIB $CWD/liblsupport.a
94
95 # if libsysio is already in our LIBS we don't need to link against it here
96 if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
97   build_sysio_obj_list $SYSIO/lib/libsysio.a
98 fi
99
100 # create static lib lustre
101 rm -f $CWD/liblustre.a
102 $AR -cru $CWD/liblustre.a $ALL_OBJS
103 $RANLIB $CWD/liblustre.a
104
105 # create shared lib lustre
106 rm -f $CWD/liblustre.so
107 OS=`uname`
108 if test x$OS = xAIX; then
109 $LD -shared -o $CWD/liblustre.so $ALL_OBJS -lpthread -Xlinker -bnoipath ../../libsyscall.so
110 else
111 $LD -shared -nostdlib -o $CWD/liblustre.so $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS
112 fi
113
114 rm -rf $sysio_tmp