Whamcloud - gitweb
LU-1511 kernel: kernel update [RHEL5.8 2.6.18-308.11.1.el5]
[fs/lustre-release.git] / build / autogen.sh
1 #!/bin/bash
2
3 # taken from gnome-common/macros2/autogen.sh
4 compare_versions() {
5     ch_min_version=$1
6     ch_actual_version=$2
7     ch_status=0
8     IFS="${IFS=         }"; ch_save_IFS="$IFS"; IFS="."
9     set $ch_actual_version
10     for ch_min in $ch_min_version; do
11         ch_cur=`echo $1 | sed 's/[^0-9].*$//'`; shift # remove letter suffixes
12         if [ -z "$ch_min" ]; then break; fi
13         if [ -z "$ch_cur" ]; then ch_status=1; break; fi
14         if [ $ch_cur -gt $ch_min ]; then break; fi
15         if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
16     done
17     IFS="$ch_save_IFS"
18     return $ch_status
19 }
20
21 error_msg() {
22         echo "$cmd is $1.  Version $required (or higher) is required to build Lustre."
23
24         if [ ! -x /usr/bin/lsb_release ]; then
25                 echo "lsb_release could not be found.  If it were available more help on how to resolve this\nsituation would be available."
26         fi
27
28         local dist_id="$(lsb_release -is)"
29         local howto=""
30         howto() {
31                 echo -e "To install $cmd, you can use the command:\n# $1"
32         }
33         case $dist_id in
34                         Ubuntu) howto "apt-get install $cmd" ;;
35         CentOS|RedHat*|Fedora*) howto "yum install $cmd" ;;
36                          SUSE*) howto "yast -i $cmd" ;;
37                              *) echo -e "\nInstallation instructions for the package $cmd on $dist_id are not known.\nIf you know how to install the required package, please file a bug at\nhttp://bugs.whamcloud.com/ and include your distribution and the output from:\n\"lsb_release -is\" is: \"$dist_id\"" ;;
38         esac
39
40         exit 1
41 }
42
43 check_version() {
44     local tool
45     local cmd
46     local required
47     local version
48
49     tool=$1
50     cmd=$2
51     required=$3
52     echo -n "checking for $cmd >= $required... "
53     if ! $cmd --version >/dev/null ; then
54         error_msg "missing"
55     fi
56     version=$($cmd --version | awk "/$tool \(GNU/ { print \$4 }")
57     echo "found $version"
58     if ! compare_versions "$required" "$version" ; then
59         error_msg "too old"
60     fi
61 }
62
63 echo "Checking for a complete tree..."
64 if [ -d kernel_patches ] ; then
65     # This is ldiskfs
66     REQUIRED_DIRS="build"
67     CONFIGURE_DIRS=""
68 else
69     REQUIRED_DIRS="build lnet lustre"
70     OPTIONAL_DIRS="snmp portals"
71     CONFIGURE_DIRS="libsysio lustre-iokit ldiskfs spl zfs"
72 fi
73
74 for dir in $REQUIRED_DIRS ; do
75     if [ ! -d "$dir" ] ; then
76         cat >&2 <<EOF
77 Your tree seems to be missing $dir.
78 Please read README.lustrecvs for details.
79 EOF
80         exit 1
81     fi
82     ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $PWD/$dir/autoconf"
83 done
84 # optional directories for Lustre
85 for dir in $OPTIONAL_DIRS; do
86     if [ -d "$dir" ] ; then
87         ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $PWD/$dir/autoconf"
88     fi
89 done
90
91 found=false
92 for AMVER in 1.9 1.10 1.11; do
93     if [ "$(which automake-$AMVER 2> /dev/null)" ]; then
94         found=true
95         break
96     fi
97 done
98
99 if ! $found; then
100     cmd=automake required="1.9" error_msg "not found"
101     exit 1
102 fi
103
104 [ "${AMVER#1.}" -ge "10" ] && AMOPT="-W no-portability"
105
106 check_version automake automake-$AMVER "1.9"
107 check_version autoconf autoconf "2.57"
108
109 export ACLOCAL="aclocal-$AMVER"
110 export AUTOMAKE="automake-$AMVER"
111
112 run_cmd()
113 {
114     cmd="$@"
115     echo -n "Running $cmd... "
116     eval $cmd
117     res=$?
118     if [ $res -ne 0 ]; then
119         echo " failed: $res"
120         echo "Aborting"
121         exit 1
122     fi
123     echo
124 }
125
126 run_cmd "$ACLOCAL $ACLOCAL_FLAGS"
127 run_cmd "autoheader"
128 run_cmd "$AUTOMAKE -a -c $AMOPT"
129 run_cmd autoconf
130
131 # Run autogen.sh in these directories
132 for dir in $CONFIGURE_DIRS; do
133     if [ -d $dir ] ; then
134         pushd $dir >/dev/null
135         echo "Running autogen for $dir..."
136         run_cmd "sh autogen.sh"
137         popd >/dev/null
138     fi
139 done