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