Whamcloud - gitweb
land b1_5 onto 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 LD=/usr/bin/ld
16 RANLIB=/usr/bin/ranlib
17
18 CWD=`pwd`
19
20 SYSIO=$1
21 LIBS=$2
22 LND_LIBS=$3
23 PTHREAD_LIBS=$4
24 QUOTA_LIBS=$5
25 CAP_LIBS=$6
26
27 if [ ! -f $SYSIO/lib/libsysio.a ]; then
28   echo "ERROR: $SYSIO/lib/libsysio.a dosen't exist"
29   exit 1
30 fi
31
32 # do cleanup at first
33 rm -f liblustre.so
34
35 ALL_OBJS=
36
37 build_obj_list() {
38   _objs=`$AR -t $1/$2`
39   for _lib in $_objs; do
40     ALL_OBJS=$ALL_OBJS"$1/$_lib ";
41   done;
42 }
43
44 #
45 # special treatment for libsysio
46 #
47 sysio_tmp=$CWD/sysio_tmp_`date +%s`
48 rm -rf $sysio_tmp
49 build_sysio_obj_list() {
50   _objs=`$AR -t $1`
51   mkdir -p $sysio_tmp
52   cd $sysio_tmp
53   $AR -x $1
54   cd ..
55   for _lib in $_objs; do
56     ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
57   done
58 }
59
60 # lustre components libs
61 build_obj_list . libllite.a
62 build_obj_list ../lov liblov.a
63 build_obj_list ../obdecho libobdecho.a
64 build_obj_list ../osc libosc.a
65 build_obj_list ../mdc libmdc.a
66 build_obj_list ../mgc libmgc.a
67 build_obj_list ../ptlrpc libptlrpc.a
68 build_obj_list ../obdclass liblustreclass.a
69 build_obj_list ../lvfs liblvfs.a
70
71 # lnet components libs
72 build_obj_list ../../lnet/utils libuptlctl.a
73 build_obj_list ../../lnet/libcfs libcfs.a
74 if $(echo "$LND_LIBS" | grep "socklnd" >/dev/null) ; then
75         build_obj_list ../../lnet/ulnds/socklnd libsocklnd.a
76 fi
77 if $(echo "$LND_LIBS" | grep "ptllnd" >/dev/null) ; then
78         build_obj_list ../../lnet/ulnds/ptllnd libptllnd.a
79 fi
80 build_obj_list ../../lnet/lnet liblnet.a
81
82 if [ "x$QUOTA_LIBS" != "x" ]; then
83   build_obj_list ../quota libquota.a
84 fi
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 gcc -shared -o $CWD/liblustre.so  $ALL_OBJS -lpthread -Xlinker -bnoipath ../../libsyscall.so
106 else
107 $LD -shared -o $CWD/liblustre.so -init __liblustre_setup_ -fini __liblustre_cleanup_ \
108         $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS
109 fi
110
111 rm -rf $sysio_tmp