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