Whamcloud - gitweb
LU-1479 build: enable srp initiator module with lbuild
[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                 exit 1
27         fi
28
29         local dist_id="$(lsb_release -is)"
30         local howto=""
31         howto() {
32                 echo -e "To install $cmd, you can use the command:\n# $1"
33         }
34         case $dist_id in
35                  Ubuntu|Debian) howto "apt-get install $cmd" ;;
36         CentOS|RedHat*|Fedora*) howto "yum install $cmd" ;;
37                          SUSE*) howto "yast -i $cmd" ;;
38                              *) 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\"" ;;
39         esac
40
41         exit 1
42 }
43
44 check_version() {
45     local tool
46     local cmd
47     local required
48     local version
49
50     tool=$1
51     cmd=$2
52     required=$3
53     echo -n "checking for $cmd >= $required... "
54     if ! $cmd --version >/dev/null ; then
55         error_msg "missing"
56     fi
57     version=$($cmd --version | awk "/$tool \(GNU/ { print \$4 }")
58     echo "found $version"
59     if ! compare_versions "$required" "$version" ; then
60         error_msg "too old"
61     fi
62 }
63
64 echo "Checking for a complete tree..."
65 if [ -d kernel_patches ] ; then
66     # This is ldiskfs
67     REQUIRED_DIRS="build"
68     CONFIGURE_DIRS=""
69 else
70     REQUIRED_DIRS="build libcfs lnet lustre"
71     OPTIONAL_DIRS="snmp portals"
72     CONFIGURE_DIRS="libsysio lustre-iokit ldiskfs"
73 fi
74
75 for dir in $REQUIRED_DIRS ; do
76     if [ ! -d "$dir" ] ; then
77         cat >&2 <<EOF
78 Your tree seems to be missing $dir.
79 Please read README.lustrecvs for details.
80 EOF
81         exit 1
82     fi
83     ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $PWD/$dir/autoconf"
84 done
85 # optional directories for Lustre
86 for dir in $OPTIONAL_DIRS; do
87     if [ -d "$dir" ] ; then
88         ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $PWD/$dir/autoconf"
89     fi
90 done
91
92 found=false
93 for AMVER in 1.9 1.10 1.11; do
94     if which automake-$AMVER 2> /dev/null; then
95         found=true
96         break
97     fi
98 done
99
100 if ! $found; then
101     cmd=automake required="1.9" error_msg "not found"
102     exit 1
103 fi
104
105 [ "${AMVER#1.}" -ge "10" ] && AMOPT="-W no-portability"
106
107 check_version automake automake-$AMVER "1.9"
108 check_version autoconf autoconf "2.57"
109
110 run_cmd()
111 {
112     cmd="$@"
113     echo -n "Running $cmd"
114     eval $cmd
115     res=$?
116     if [ $res -ne 0 ]; then
117         echo " failed: $res"
118         echo "Aborting"
119         exit 1
120     fi
121     echo
122 }
123
124 export ACLOCAL="aclocal-$AMVER"
125 export AUTOMAKE="automake-$AMVER"
126
127 run_cmd "$ACLOCAL $ACLOCAL_FLAGS"
128 run_cmd "autoheader"
129 run_cmd "$AUTOMAKE -a -c $AMOPT"
130 run_cmd autoconf
131
132 # Run autogen.sh in these directories
133 for dir in $CONFIGURE_DIRS; do
134     if [ -d $dir ] ; then
135         pushd $dir >/dev/null
136         echo "Running autogen for $dir..."
137         run_cmd "sh autogen.sh"
138         popd >/dev/null
139     fi
140 done