build: Cater for ARM.
[mes.git] / configure.sh
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 #
6 # This file is part of GNU Mes.
7 #
8 # GNU Mes is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GNU Mes is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Mes.  If not, see <http://www.gnu.org/licenses/>.
20
21 set -e
22
23 VERSION=0.19
24 srcdir=${srcdir-$(dirname $0)}
25 . ${srcdest}build-aux/trace.sh
26
27 # parse --with-system-libc
28 cmdline=$(echo " $@")
29 p=${cmdline/ --with-system-libc/}
30 if test "$p" != "$cmdline"; then
31     mes_libc=${mes_libc-system}
32 else
33     mes_libc=mes
34 fi
35
36 # parse --with-courage
37 cmdline=$(echo " $@")
38 p=${cmdline/ --with-courage/}
39 if test "$p" != "$cmdline"; then
40     courageous=true
41 else
42     courageous=false
43 fi
44
45 # parse --prefix=PREFIX
46 p=${cmdline/ --prefix=/ -prefix=}
47 if test "$p" != "$cmdline"; then
48     p=${p##* -prefix=}
49     p=${p% *}
50     p=${p% -*}
51     prefix=${p-/usr/local}
52
53 else
54     prefix=${prefix-/usr/local}
55 fi
56
57 # parse --build=BUILD
58 p=${cmdline/ --build=/ -build=}
59 if [ "$p" != "$cmdline" ]; then
60     p=${p##* -build=}
61     p=${p% *}
62     p=${p% -*}
63     build=${p-$build}
64 else
65     build=$build
66 fi
67
68 # parse --host=HOST
69 p=${cmdline/ --host=/ -host=}
70 if [ "$p" != "$cmdline" ]; then
71     p=${p##* -host=}
72     p=${p% *}
73     p=${p% -*}
74     host=${p-$build}
75
76 else
77     host=${host-$build}
78 fi
79
80 # parse --program-prefix=
81 p=${cmdline/ --program-prefix=/ -program-prefix=}
82 if test "$p" != "$cmdline"; then
83     p=${p##* -program-prefix=}
84     p=${p% *}
85     p=${p% -*}
86     program_prefix=$p
87 fi
88
89 AR=${AR-$(command -v ar)} || true
90 BASH=${BASH-$(command -v bash)}
91 BLOOD_ELF=${BLOOD_ELF-$(command -v blood-elf)}
92 CC=${CC-$(command -v gcc)} || true
93 DIFF=${DIFF-$(command -v diff || echo $PWD/pre-inst-env diff.scm)}
94 GUILD=${GUILD-$(command -v guild)} || true
95 GUILE_TOOLS=${GUILE_TOOLS-$(command -v guile-tools)} || true
96 if test ! "$GUILD"; then
97     if test "$GUILE_TOOLS"; then
98         GUILD=$GUILE_TOOLS
99     else
100         GUILD=true
101     fi
102 fi
103 GUILE=${GUILE-$(command -v guile)} || true
104 HEX2=${HEX2-$(command -v hex2)}
105 M1=${M1-$(command -v M1)}
106 MES_FOR_BUILD=${MES_FOR_BUILD-$(command -v mes || command -v guile || echo mes)}
107 GIT=${GIT-$(command -v git)} || true
108 PERL=${PERL-$(command -v perl)} || true
109 MES_SEED=${MES_SEED-../mes-seed}
110
111 if test "$srcdir" = .; then
112     top_builddir=.
113 else
114     srcdest=${srcdest}
115     top_builddir=$PWD
116 fi
117 abs_top_srcdir=${abs_top_srcdir-$(cd ${srcdir} && pwd)}
118 abs_top_builddir=$PWD
119
120 if test -z "$GUILE" -o "$GUILE" = true; then
121     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
122 else
123     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
124 fi
125 bindir=$(eval echo ${bindir-$prefix/bin})
126 datadir=$(eval echo ${datadir-$prefix/share})
127 docdir=$(eval echo ${docdir-$datadir/doc/mes-$VERSION})
128 infodir=$(eval echo ${infodir-$datadir/info})
129 includedir=$(eval echo ${libdir-$prefix/include})
130 libdir=$(eval echo ${libdir-$prefix/lib})
131 mandir=$(eval echo ${mandir-$datadir/man})
132 moduledir=$(eval echo ${moduledir-$datadir/mes/module})
133 moduledir_="$moduledir/"
134 guile_site_dir=$(eval echo ${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION})
135 guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache})
136
137 subst () {
138     sed \
139     -e s,"@PACKAGE@,$PACKAGE,"\
140     -e s,"@PACKAGE_NAME@,$PACKAGE_NAME,"\
141     -e s,"@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,"\
142     -e s,"@VERSION@,$VERSION,"\
143     -e s,"@build@,$build,"\
144     -e s,"@host@,$host,"\
145     -e s,"@compiler@,$compiler,"\
146     -e s,"@courageous@,$courageous,"\
147     -e s,"@mes_bits@,$mes_bits,"\
148     -e s,"@mes_kernel@,$mes_kernel,"\
149     -e s,"@mes_cpu@,$mes_cpu,"\
150     -e s,"@mes_libc@,$mes_libc,"\
151     -e s,"@mes_system@,$mes_system,"\
152     -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\
153     -e s,"@abs_top_builddir@,$abs_top_builddir,"\
154     -e s,"@top_builddir@,$top_builddir,"\
155     -e s,"@srcdest@,$srcdest,"\
156     -e s,"@srcdir@,$srcdir,"\
157     -e s,"@prefix@,$prefix,"\
158     -e s,"@program_prefix@,$program_prefix,"\
159     -e s,"@bindir@,$bindir,"\
160     -e s,"@datadir@,$datadir,"\
161     -e s,"@docdir@,$docdir,"\
162     -e s,"@guile_site_dir@,$guile_site_dir,"\
163     -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\
164     -e s,"@infodir@,$infodir,"\
165     -e s,"@includedir@,$includedir,"\
166     -e s,"@libdir@,$libdir,"\
167     -e s,"@mandir@,$mandir,"\
168     -e s,"@moduledir@,$moduledir,"\
169     -e s,"@sysconfdir@,$sysconfdir,"\
170     -e s,"@GUILE_EFFECTIVE_VERSION@,$GUILE_EFFECTIVE_VERSION,"\
171     -e s,"@V@,$V,"\
172     -e s,"@AR@,$AR,"\
173     -e s,"@BASH@,$BASH,"\
174     -e s,"@BLOOD_ELF@,$BLOOD_ELF,"\
175     -e s,"@CC@,$CC,"\
176     -e s,"@DIFF@,$DIFF,"\
177     -e s,"@GIT@,$GIT,"\
178     -e s,"@GUILD@,$GUILD,"\
179     -e s,"@GUILE@,$GUILE,"\
180     -e s,"@PERL@,$PERL,"\
181     -e s,"@CFLAGS@,$CFLAGS,"\
182     -e s,"@HEX2@,$HEX2,"\
183     -e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
184     -e s,"@M1@,$M1,"\
185     -e s,"@M1FLAGS@,$M1FLAGS,"\
186     -e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
187     -e s,"@MES_SEED@,$MES_SEED,"\
188     -e s,"@MES_SEED@,$MES_SEED,"\
189     -e s,"@SHELL@,$SHELL,"\
190     -e s,"mes/module/,$moduledir/,"\
191     $1 > $2
192 }
193
194 host=${host-$($CC -dumpmachine 2>/dev/null)}
195 if test -z "$host$host_type"; then
196     mes_cpu=${arch-$(get_machine || uname -m)}
197 else
198     mes_cpu=${host%%-*}
199 fi
200 if test "$mes_cpu" = i386\
201         || test "$mes_cpu" = i486\
202         || test "$mes_cpu" = i586\
203         || test "$mes_cpu" = i686; then
204     mes_cpu=x86
205 fi
206 if test "$mes_cpu" = armv4\
207         || test "$arch" = armv7l; then
208     mes_cpu=arm
209 fi
210
211 case "$host" in
212     *linux-gnu|*linux)
213         mes_kernel=linux;;
214     *gnu)
215         mes_kernel=gnu;;
216     *)
217         mes_kernel=linux;;
218 esac
219
220 case "$mes_cpu" in
221     x86_64)
222         mes_bits=64;;
223     *)
224         mes_bits=32;;
225 esac
226 #
227 if $CC --version | grep gcc; then #2>/dev/null; then
228     compiler=gcc
229 elif $CC --version | grep tcc; then #2>/dev/null; then
230     compiler=gcc
231 else
232     compiler=mescc
233 fi
234
235 mes_system=$mes_cpu-$mes_kernel-mes
236
237 subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile
238 subst ${srcdest}build-aux/config.sh.in config.sh
239 subst ${srcdest}build-aux/build.sh.in build.sh
240 chmod +x build.sh
241 subst ${srcdest}build-aux/check.sh.in check.sh
242 chmod +x check.sh
243 subst ${srcdest}build-aux/install.sh.in install.sh
244 chmod +x install.sh
245 subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env
246 chmod +x pre-inst-env
247 subst ${srcdest}scripts/ar.in scripts/ar
248 chmod +x scripts/ar
249 subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm
250 chmod +x scripts/mescc.scm
251 subst ${srcdest}scripts/mescc.in scripts/mescc
252 chmod +x scripts/mescc
253 subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh
254 chmod +x uninstall.sh
255
256 mkdir -p include/mes
257 if test $mes_libc = system; then
258     cat >> include/mes/config.h <<EOF
259 #define SYSTEM_LIBC 1
260 EOF
261 else
262     cat >> include/mes/config.h <<EOF
263 #undef SYSTEM_LIBC
264 EOF
265 fi
266 cat >> include/mes/config.h <<EOF
267 #define VERSION '"'$VERSION'"'
268 #define pkgdatadir "'"$pkgdatadir'"'
269
270 EOF
271
272 cat <<EOF
273 GNU Mes is configured for
274    compiler: $compiler
275    cpu:      $mes_cpu
276    bits:     $mes_bits
277    libc:     $mes_libc
278    kernel:   $mes_kernel
279    system:   $mes_system
280
281 Run:
282   ./build.sh      to build mes
283   ./check.sh      to check mes
284   ./install.sh    to install mes
285 EOF