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