Whamcloud - gitweb
Branch: b1_4
[fs/lustre-release.git] / lustre / liblustre / genlib.sh
1 #!/bin/bash
2 #set -xv
3
4 #
5 # This script is to generate lib lustre library as a whole. It will leave
6 # two files on current directory: liblustre.a and liblustre.so.
7 #
8 # Most concern here is the libraries linking order
9 #
10 # FIXME: How to do this cleanly use makefile?
11 #
12
13 AR=/usr/bin/ar
14 LD=/usr/bin/ld
15 RANLIB=/usr/bin/ranlib
16
17 CWD=`pwd`
18
19 SYSIO=$1
20 CRAY_PORTALS_LIBS=$2
21 LIBS=$3
22
23 if [ ! -f $SYSIO/lib/libsysio.a ]; then
24   echo "ERROR: $SYSIO/lib/libsysio.a dosen't exist"
25   exit 1
26 fi
27
28 # do cleanup at first
29 rm -f liblustre.so
30
31 ALL_OBJS=
32
33 build_obj_list() {
34   _objs=`$AR -t $1/$2`
35   for _lib in $_objs; do
36     ALL_OBJS=$ALL_OBJS"$1/$_lib ";
37   done;
38 }
39
40 #
41 # special treatment for libsysio
42 #
43 sysio_tmp=$CWD/sysio_tmp_`date +%s`
44 rm -rf $sysio_tmp
45 build_sysio_obj_list() {
46   _objs=`$AR -t $1`
47   mkdir -p $sysio_tmp
48   cd $sysio_tmp
49   $AR -x $1
50   cd ..
51   for _lib in $_objs; do
52     ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
53   done
54 }
55
56 #
57 # special treatment for libportals.a
58 #
59 cray_tmp=$CWD/cray_tmp_`date +%s`
60 rm -rf $cray_tmp
61 build_cray_portals_obj_list() {
62   _objs=`$AR -t $1`
63   mkdir -p $cray_tmp
64   cd $cray_tmp
65   $AR -x $1
66   cd ..
67   for _lib in $_objs; do
68     ALL_OBJS=$ALL_OBJS"$cray_tmp/$_lib ";
69   done
70 }
71
72 # lustre components libs
73 build_obj_list . libllite.a
74 build_obj_list ../lov liblov.a
75 build_obj_list ../obdecho libobdecho.a
76 build_obj_list ../osc libosc.a
77 build_obj_list ../mdc libmdc.a
78 build_obj_list ../ptlrpc libptlrpc.a
79 build_obj_list ../obdclass liblustreclass.a
80 build_obj_list ../lvfs liblvfs.a
81
82 # portals components libs
83 build_obj_list ../../portals/utils libuptlctl.a
84
85 if [ "x$CRAY_PORTALS_LIBS" = "x" ]; then
86   build_obj_list ../../portals/unals libtcpnal.a
87   build_obj_list ../../portals/portals libportals.a
88 # if libportals is already in our LIBS we don't need to link against it here
89 elif $(echo "$LIBS" | grep -v -- "-lportals" >/dev/null) ; then
90   build_cray_portals_obj_list $CRAY_PORTALS_LIBS/libportals.a
91 fi
92
93 # create static lib lsupport
94 rm -f $CWD/liblsupport.a
95 $AR -cru $CWD/liblsupport.a $ALL_OBJS
96 $RANLIB $CWD/liblsupport.a
97
98 # if libsysio is already in our LIBS we don't need to link against it here
99 if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
100   build_sysio_obj_list $SYSIO/lib/libsysio.a
101 fi
102
103 # create static lib lustre
104 rm -f $CWD/liblustre.a
105 $AR -cru $CWD/liblustre.a $ALL_OBJS
106 $RANLIB $CWD/liblustre.a
107
108 # create shared lib lustre
109 rm -f $CWD/liblustre.so
110 $LD -shared -o $CWD/liblustre.so -init __liblustre_setup_ -fini __liblustre_cleanup_ \
111         $ALL_OBJS -lcap -lpthread
112
113 rm -rf $sysio_tmp
114 rm -rf $cray_tmp