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