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