Whamcloud - gitweb
LU-1199 build: Untangle the ldiskfs build system from lustre
[fs/lustre-release.git] / ldiskfs / autogen.sh
1 #!/bin/sh
2
3 # NOTE: Please avoid bashisms (bash specific syntax) in this script
4
5 # taken from gnome-common/macros2/autogen.sh
6 compare_versions() {
7         ch_min_version=$1
8         ch_actual_version=$2
9         ch_status=0
10         IFS="${IFS=     }"; ch_save_IFS="$IFS"; IFS="."
11         set $ch_actual_version
12         for ch_min in $ch_min_version; do
13                 # remove letter suffixes
14                 ch_cur=$(echo $1 | sed 's/[^0-9].*$//'); shift
15                 if [ -z "$ch_min" ]; then break; fi
16                 if [ -z "$ch_cur" ]; then ch_status=1; break; fi
17                 if [ $ch_cur -gt $ch_min ]; then break; fi
18                 if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
19         done
20         IFS="$ch_save_IFS"
21         return $ch_status
22 }
23
24 error_msg() {
25         echo "$cmd is $1.  Version $required (or higher) is"\
26              " required to build Lustre."
27
28         if [ ! -x /usr/bin/lsb_release ]; then
29                 echo "lsb_release could not be found.  "\
30                      "If it were available more help on how to resolve this"
31                 echo "situation would be available."
32                 exit 1
33         fi
34
35         local dist_id="$(lsb_release -is)"
36         local howto=""
37         howto() {
38                 echo -e "To install $cmd, you can use the command:\n# $1"
39         }
40         case $dist_id in
41                  Ubuntu|Debian) howto "apt-get install $cmd" ;;
42         CentOS|RedHat*|Fedora*) howto "yum install $cmd" ;;
43                          SUSE*) howto "yast -i $cmd" ;;
44                              *) cat <<EOF
45 Installation instructions for the package $cmd on $dist_id are not known.
46 If you know how to install the required package, please file a bug at
47 http://bugs.whamcloud.com/ and include your distribution and the output from:
48 "lsb_release -is" is: "$dist_id"
49 EOF
50                         ;;
51         esac
52
53         exit 1
54 }
55
56 check_version() {
57         local tool
58         local cmd
59         local required
60         local version
61
62         tool=$1
63         cmd=$2
64         required=$3
65         echo -n "checking for $cmd >= $required... "
66         if ! $cmd --version >/dev/null ; then
67                 error_msg "missing"
68         fi
69         version=$($cmd --version | awk "/$tool \(GNU/ { print \$4 }")
70         echo "found $version"
71         if ! compare_versions "$required" "$version" ; then
72                 error_msg "too old"
73         fi
74 }
75
76 found=false
77 for AMVER in 1.9 1.10 1.11; do
78         if which automake-$AMVER 2> /dev/null; then
79                 found=true
80                 break
81         fi
82 done
83
84 if ! $found; then
85         cmd=automake required="1.9" error_msg "not found"
86         exit 1
87 fi
88
89 [ "${AMVER#1.}" -ge "10" ] && AMOPT="-W no-portability"
90
91 check_version automake automake-$AMVER "1.9"
92 check_version autoconf autoconf "2.57"
93
94 run_cmd()
95 {
96         cmd="$@"
97         echo -n "Running $cmd"
98         eval $cmd
99         res=$?
100         if [ $res -ne 0 ]; then
101                 echo " failed: $res"
102                 echo "Aborting"
103                 exit 1
104         fi
105         echo
106 }
107
108 ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $PWD/build/autoconf"
109
110 export ACLOCAL="aclocal-$AMVER"
111 export AUTOMAKE="automake-$AMVER"
112
113 run_cmd "$ACLOCAL $ACLOCAL_FLAGS"
114 run_cmd "autoheader"
115 run_cmd "$AUTOMAKE -a -c $AMOPT"
116 run_cmd autoconf