Whamcloud - gitweb
- landed b_hd_cray_merge3
[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 prepend_obj_list() {
41   _objs=`$AR -t $1/$2`
42   for _lib in $_objs; do
43     ALL_OBJS="$1/$_lib "$ALL_OBJS;
44   done;
45 }
46
47 #
48 # special treatment for libsysio
49 #
50 sysio_tmp=$CWD/sysio_tmp_`date +%s`
51 rm -rf $sysio_tmp
52 build_sysio_obj_list() {
53   _objs=`$AR -t $1`
54   mkdir -p $sysio_tmp
55   cd $sysio_tmp
56   $AR -x ../$1
57   cd ..
58   for _lib in $_objs; do
59     ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
60   done
61 }
62
63 #
64 # special treatment for libportals.a
65 #
66 cray_tmp=$CWD/cray_tmp_`date +%s`
67 rm -rf $cray_tmp
68 build_cray_portals_obj_list() {
69   _objs=`$AR -t $1`
70   mkdir -p $cray_tmp
71   cd $cray_tmp
72   $AR -x $1
73   cd ..
74   for _lib in $_objs; do
75     ALL_OBJS=$ALL_OBJS"$cray_tmp/$_lib ";
76   done
77 }
78
79 # lustre components libs
80 build_obj_list . libllite.a
81 build_obj_list ../lov liblov.a
82 build_obj_list ../obdecho libobdecho.a
83 build_obj_list ../osc libosc.a
84 build_obj_list ../mdc libmdc.a
85 build_obj_list ../ptlrpc libptlrpc.a
86 build_obj_list ../sec libptlrpcs.a
87 build_obj_list ../obdclass liblustreclass.a
88 build_obj_list ../lvfs liblvfs.a
89
90 # portals components libs
91 build_obj_list ../../portals/utils libuptlctl.a
92
93 if [ "x$CRAY_PORTALS_PATH" = "x" ]; then
94   build_obj_list ../../portals/unals libtcpnal.a
95   build_obj_list ../../portals/portals libportals.a
96 else
97   build_cray_portals_obj_list $CRAY_PORTALS_PATH/lib_TV/snos64/libportals.a
98 fi
99
100 # create static lib lsupport
101 rm -f $CWD/liblsupport.a
102 $AR -cru $CWD/liblsupport.a $ALL_OBJS
103 $RANLIB $CWD/liblsupport.a
104
105 # if libsysio is already in our LIBS we don't need to link against it here
106 if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
107   build_sysio_obj_list $SYSIO/lib/libsysio.a
108 fi
109
110 # create static lib lustre
111 rm -f $CWD/liblustre.a
112 $AR -cru $CWD/liblustre.a $ALL_OBJS
113 $RANLIB $CWD/liblustre.a
114
115 # create shared lib lustre
116 rm -f $CWD/liblustre.so
117 $LD -shared -o $CWD/liblustre.so -init __liblustre_setup_ -fini __liblustre_cleanup_ \
118         $ALL_OBJS -lcap -lpthread
119
120 rm -rf $sysio_tmp
121 rm -rf $cray_tmp