mescc: Remove dead code. Thanks Mark Weaver.
[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 else
53     prefix=${prefix-/usr/local}
54 fi
55
56 # parse --build=BUILD
57 p=${cmdline/ --build=/ -build=}
58 if [ "$p" != "$cmdline" ]; then
59     p=${p##* -build=}
60     p=${p% *}
61     p=${p% -*}
62     build=${p-$build}
63 else
64     build=$build
65 fi
66
67 # parse --host=HOST
68 p=${cmdline/ --host=/ -host=}
69 if [ "$p" != "$cmdline" ]; then
70     p=${p##* -host=}
71     p=${p% *}
72     p=${p% -*}
73     host=${p-$build}
74 elif test -n "$build"; then
75     host=${host-$build}
76 fi
77
78 # parse --program-prefix=
79 p=${cmdline/ --program-prefix=/ -program-prefix=}
80 if test "$p" != "$cmdline"; then
81     p=${p##* -program-prefix=}
82     p=${p% *}
83     p=${p% -*}
84     program_prefix=$p
85 fi
86
87 AR=${AR-$(command -v ar)} || true
88 BASH=${BASH-$(command -v bash)}
89 BLOOD_ELF=${BLOOD_ELF-$(command -v blood-elf)}
90 CC=${CC-$(command -v gcc)} || true
91 DIFF=${DIFF-$(command -v diff || echo $PWD/pre-inst-env diff.scm)}
92 GUILD=${GUILD-$(command -v guild)} || true
93 GUILE_TOOLS=${GUILE_TOOLS-$(command -v guile-tools)} || true
94 if test ! "$GUILD"; then
95     if test "$GUILE_TOOLS"; then
96         GUILD=$GUILE_TOOLS
97     else
98         GUILD=true
99     fi
100 fi
101 GUILE=${GUILE-$(command -v guile)} || true
102 HEX2=${HEX2-$(command -v hex2)}
103 M1=${M1-$(command -v M1)}
104 MES_FOR_BUILD=${MES_FOR_BUILD-$(command -v mes || command -v guile || echo mes)}
105 GIT=${GIT-$(command -v git)} || true
106 PERL=${PERL-$(command -v perl)} || true
107 SHELL=${BASH-$SHELL}
108
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 pkgdatadir=$(eval echo ${pkgdatadir-$datadir/mes})
132 mandir=$(eval echo ${mandir-$datadir/man})
133 guile_site_dir=$(eval echo ${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION})
134 guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache})
135
136 subst () {
137     echo "creating $2"
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,"@pkgdatadir@,$pkgdatadir,"\
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     $1 > $2
191 }
192
193 host=${host-$($CC -dumpmachine 2>/dev/null)}
194 if test -z "$host$host_type"; then
195     mes_cpu=${arch-$(get_machine || uname -m)}
196 else
197     mes_cpu=${host%%-*}
198 fi
199 if test "$mes_cpu" = i386\
200         || test "$mes_cpu" = i486\
201         || test "$mes_cpu" = i586\
202         || test "$mes_cpu" = i686; then
203     mes_cpu=x86
204 fi
205 if test "$mes_cpu" = armv4\
206         || test "$arch" = armv7l; then
207     mes_cpu=arm
208 fi
209 if test "$mes_cpu" = amd64; then
210     mes_cpu=x86_64
211 fi
212
213 case "$host" in
214     *linux-gnu|*linux)
215         mes_kernel=linux;;
216     *gnu)
217         mes_kernel=gnu;;
218     *)
219         mes_kernel=linux;;
220 esac
221
222 case "$mes_cpu" in
223     x86_64)
224         mes_bits=64;;
225     *)
226         mes_bits=32;;
227 esac
228 #
229 if $CC --version | grep gcc; then #2>/dev/null; then
230     compiler=gcc
231 elif $CC --version | grep tcc; then #2>/dev/null; then
232     compiler=gcc
233 else
234     compiler=mescc
235 fi
236
237 mes_system=$mes_cpu-$mes_kernel-mes
238
239 subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile
240 subst ${srcdest}build-aux/config.sh.in config.sh
241 subst ${srcdest}build-aux/bootstrap.sh.in bootstrap.sh
242 chmod +x bootstrap.sh
243 subst ${srcdest}build-aux/build.sh.in build.sh
244 chmod +x build.sh
245 subst ${srcdest}build-aux/check.sh.in check.sh
246 chmod +x check.sh
247 subst ${srcdest}build-aux/install.sh.in install.sh
248 chmod +x install.sh
249 subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env
250 chmod +x pre-inst-env
251 subst ${srcdest}scripts/mesar.in scripts/mesar
252 chmod +x scripts/mesar
253 subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm
254 chmod +x scripts/mescc.scm
255 subst ${srcdest}scripts/mescc.in scripts/mescc
256 chmod +x scripts/mescc
257 subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh
258 chmod +x uninstall.sh
259
260 mkdir -p include/mes
261 rm -f include/mes/config.h
262 if test $mes_libc = system; then
263     cat >> include/mes/config.h <<EOF
264 #define SYSTEM_LIBC 1
265 EOF
266 else
267     cat >> include/mes/config.h <<EOF
268 #undef SYSTEM_LIBC
269 EOF
270 fi
271 cat >> include/mes/config.h <<EOF
272 #define MES_VERSION "$VERSION"
273 #define MES_PKGDATADIR "$pkgdatadir"
274 EOF
275
276 cat <<EOF
277 GNU Mes is configured for
278    compiler: $compiler
279    cpu:      $mes_cpu
280    bits:     $mes_bits
281    libc:     $mes_libc
282    kernel:   $mes_kernel
283    system:   $mes_system
284
285 Run:
286   ./build.sh      to build mes
287   ./check.sh      to check mes
288   ./install.sh    to install mes
289 EOF