Slightly better basic type detection.
[sxemacs] / autogen.sh
1 #!/bin/sh
2 # Configure script bootstrap for SXEmacs
3 #
4 # Copyright (C) 2005, 2006, 2007 Steve Youngs.
5 # Copyright (C) 2006, 2007, 2008 Sebastian Freundt.
6 # Copyright (C) 2007, 2010, 2011 Nelson Ferreira
7
8 # This file is part of SXEmacs.
9
10 # SXEmacs is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # SXEmacs is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 # Parts of SXEmacs are also distributed under a BSD-like licence.
24 # Check file headers for more information.
25
26 # BSD's m4 probably isn't gonna cut it, use gm4 if it is available
27 type gm4 >/dev/null 2>&1 && M4=gm4 || M4=m4
28
29 M4_VERSION=$($M4 --version | head -n1 | sed -e 's/^\(m4 \)\?(\?GNU M4)\? *//g' ) 
30 GOOD_M4=$( echo $M4_VERSION | awk -F. '{if( ($1>1) || ( ($1==1) && ($2>4) ) || ( ($1==1) && ($2==4) && ($3>=6) )) print 1 }')
31
32 if [ "$GOOD_M4" != "1" ]; then
33     echo You have m4 version $M4_VERSION.  SXEmacs requires m4 version 1.4.6 or later.
34     exit 1
35 fi
36
37 # To cater for Solaris
38 if test -d "/usr/xpg4/bin"; then
39     PATH=/usr/xpg4/bin:$PATH
40     export PATH
41 fi
42
43 type git >/dev/null 2>&1 && GIT=git
44 olddir=$(pwd)
45 srcdir=$(dirname $0)
46 cd "$srcdir"
47
48 EXPECTED_TREE_VERSION="22.1.14"
49
50 emacs_is_beta=t
51 if test -n "$GIT" -a -n "$($GIT symbolic-ref HEAD 2>/dev/null)"; then
52         TREE_VERSION="$($GIT tag|tail -n1|tr -d v)"
53         GIT_VERSION="$($GIT describe | head -n1)"
54         IN_GIT="1"
55 fi
56 if test -z "$TREE_VERSION"; then
57         TREE_VERSION="$EXPECTED_TREE_VERSION"
58         if test -n "$IN_GIT"; then
59             echo "If you cloned this branch into your own you should issue:"
60             echo "\tgit tag -s v${TREE_VERSION}.<your branch_name>"
61             echo "\tgit push --tag"
62         fi
63 fi
64 if test -z "$GIT_VERSION"; then
65         GIT_VERSION="${TREE_VERSION}-no_git_version"
66 fi
67
68 emacs_major_version="$(echo $TREE_VERSION|cut -d. -f1)"
69 emacs_minor_version="$(echo $TREE_VERSION|cut -d. -f2)"
70 emacs_beta_version="$(echo $TREE_VERSION|cut -d. -f3)"
71 emacs_full_version="$emacs_major_version.$emacs_minor_version.$emacs_beta_version"
72 sxemacs_codename="Geo"
73 sxemacs_git_version="$GIT_VERSION"
74
75 if test "$emacs_full_version" != "$EXPECTED_TREE_VERSION"; then
76     # Note, there is no need check for git repos, because
77     # it can only happen in such a case anyway...
78     echo "*******************************************"
79     echo " WARNING: Your git tags may be out of date "
80     echo ""
81     echo " Expected tree version $EXPECTED_TREE_VERSION "
82     echo " got $emacs_full_version (from $TREE_VERSION) "
83     set -x
84     git tag
85     git describe
86     git describe --long
87     git config -l
88     set +x
89     echo "*******************************************" 
90 fi
91
92 autoconf_ver=$(autoconf --version 2>/dev/null | head -n1)
93 autoheader_ver=$(autoheader --version 2>/dev/null | head -n1)
94 automake_ver=$(automake --version 2>/dev/null | head -n1)
95 aclocal_ver=$(aclocal --version 2>/dev/null | head -n1)
96 libtool_ver=$(libtool --version 2>/dev/null | head -n1)
97
98
99 # When things go wrong... get a bigger hammer!
100 if test -n "$PHAMMER"; then
101     HAMMER=$PHAMMER
102 fi
103
104 if test -n "$HAMMER"; then
105         if test -n "$GIT" -a -n "$($GIT symbolic-ref HEAD 2>/dev/null)"; then
106                 $GIT clean -fxd
107         else
108                 echo "ERROR: Not a git workspace, or you don't have git" >&2
109                 exit 1
110         fi
111         unset HAMMER
112 fi
113
114
115 cat>sxemacs_version.m4<<EOF
116 dnl autogenerated version number
117 m4_define([SXEM4CS_VERSION], [$emacs_full_version])
118 m4_define([SXEM4CS_MAJOR_VERSION], [$emacs_major_version])
119 m4_define([SXEM4CS_MINOR_VERSION], [$emacs_minor_version])
120 m4_define([SXEM4CS_BETA_VERSION], [$emacs_beta_version])
121 m4_define([SXEM4CS_BETA_P], [$emacs_is_beta])
122 m4_define([SXEM4CS_GIT_VERSION], [$sxemacs_git_version])
123 m4_define([SXEM4CS_CODENAME], [$sxemacs_codename])
124 m4_define([4UTOCONF_VERSION], [$autoconf_ver])
125 m4_define([4UTOHEADER_VERSION], [$autoheader_ver])
126 m4_define([4CLOCAL_VERSION], [$aclocal_ver])
127 m4_define([4UTOMAKE_VERSION], [$automake_ver])
128 m4_define([4IBTOOL_VERSION], [$libtool_ver])
129 EOF
130
131 if test -z "$FORCE"; then
132     FORCE=
133 else
134     rm -rf autom4te.cache aclocal.m4
135     FORCE=--force
136 fi
137
138 if type glibtoolize 2>/dev/null; then
139     LIBTOOLIZE=glibtoolize
140 else
141     LIBTOOLIZE=libtoolize
142 fi
143
144 autoreconf $FORCE --verbose --install -Wall
145
146 # hack-o-matic.  Using gmp's config.{guess,sub} lets us have properer
147 # detected machine configurations --SY.
148 guess=$(grep GMP config.guess)
149 sub=$(grep GMP config.sub)
150 if test -z "${guess}"; then
151     mv -vf config.guess configfsf.guess
152     cp -v configgmp.guess config.guess
153 fi
154 if test -z "${sub}"; then
155     mv -vf config.sub configfsf.sub
156     cp -v configgmp.sub config.sub
157 fi
158
159 cd $olddir