#!/bin/bash
#set -xv
+set -e
#
# This script is to generate lib lustre library as a whole. It will leave
# two files on current directory: liblustre.a and liblustre.so.
-# Integrate them into Makefile.am later
+#
+# Most concern here is the libraries linking order
+#
+# FIXME: How to do this cleanly use makefile?
#
AR=/usr/bin/ar
CWD=`pwd`
SYSIO=$1
+LIBS=$2
+LND_LIBS=$3
+PTHREAD_LIBS=$4
+QUOTA_LIBS=$5
+CAP_LIBS=$6
+
+if [ ! -f $SYSIO/lib/libsysio.a ]; then
+ echo "ERROR: $SYSIO/lib/libsysio.a dosen't exist"
+ exit 1
+fi
-#if [ ! -f $SYSIO/lib/libsysio.a ]; then
-# echo "ERROR: $SYSIO/lib/libsysio.a dosen't exist"
-# exit 1
-#fi
-#
# do cleanup at first
-#rm -f liblustre.so
+rm -f liblustre.so
ALL_OBJS=
#
# special treatment for libsysio
#
-#sysio_tmp=$CWD/sysio_tmp_`date +%s`
-#build_sysio_obj_list() {
-# _objs=`$AR -t $1`
-# mkdir -p $sysio_tmp
-# $AR -x $1
-# mv $_objs $sysio_tmp
-# for _lib in $_objs; do
-# ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
-# done
-#}
+sysio_tmp=$CWD/sysio_tmp_`date +%s`
+rm -rf $sysio_tmp
+build_sysio_obj_list() {
+ _objs=`$AR -t $1`
+ mkdir -p $sysio_tmp
+ cd $sysio_tmp
+ $AR -x $1
+ cd ..
+ for _lib in $_objs; do
+ ALL_OBJS=$ALL_OBJS"$sysio_tmp/$_lib ";
+ done
+}
# lustre components libs
build_obj_list . libllite.a
build_obj_list ../obdecho libobdecho.a
build_obj_list ../osc libosc.a
build_obj_list ../mdc libmdc.a
+build_obj_list ../mgc libmgc.a
build_obj_list ../ptlrpc libptlrpc.a
build_obj_list ../obdclass liblustreclass.a
build_obj_list ../lvfs liblvfs.a
-# portals components libs
-build_obj_list ../portals/utils libuptlctl.a
-build_obj_list ../portals/unals libtcpnal.a
-build_obj_list ../portals/portals libportals.a
+# lnet components libs
+build_obj_list ../../lnet/utils libuptlctl.a
+build_obj_list ../../lnet/libcfs libcfs.a
+if $(echo "$LND_LIBS" | grep "socklnd" >/dev/null) ; then
+ build_obj_list ../../lnet/ulnds/socklnd libsocklnd.a
+fi
+if $(echo "$LND_LIBS" | grep "ptllnd" >/dev/null) ; then
+ build_obj_list ../../lnet/ulnds/ptllnd libptllnd.a
+fi
+build_obj_list ../../lnet/lnet liblnet.a
+
+if [ "x$QUOTA_LIBS" != "x" ]; then
+ build_obj_list ../quota libquota.a
+fi
# create static lib lsupport
rm -f $CWD/liblsupport.a
$AR -cru $CWD/liblsupport.a $ALL_OBJS
$RANLIB $CWD/liblsupport.a
-# libsysio components libs
-build_obj_list $SYSIO/drivers/native libsysio_native.a
-build_obj_list $SYSIO/drivers/sockets libsysio_sockets.a
-build_obj_list $SYSIO/src libsysio.a
-build_obj_list $SYSIO/dev/stdfd libsysio_stdfd.a
-#
-#build_sysio_obj_list $SYSIO/lib/libsysio.a
-#
+# if libsysio is already in our LIBS we don't need to link against it here
+if $(echo "$LIBS" | grep -v -- "-lsysio" >/dev/null) ; then
+ build_sysio_obj_list $SYSIO/lib/libsysio.a
+fi
# create static lib lustre
rm -f $CWD/liblustre.a
# create shared lib lustre
rm -f $CWD/liblustre.so
+OS=`uname`
+if test x$OS = xAIX; then
+gcc -shared -o $CWD/liblustre.so $ALL_OBJS -lpthread -Xlinker -bnoipath ../../libsyscall.so
+else
$LD -shared -o $CWD/liblustre.so -init __liblustre_setup_ -fini __liblustre_cleanup_ \
- $ALL_OBJS -lcap -lpthread
+ $ALL_OBJS $CAP_LIBS $PTHREAD_LIBS
+fi
-#rm -rf $sysio_tmp
+rm -rf $sysio_tmp