67013db0b2c0f1582bf780a3b909d18fcc3758a7
[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 SHELL=${BASH-$SHELL}
110
111 MES_SEED=${MES_SEED-../mes-seed}
112
113 if test "$srcdir" = .; then
114     top_builddir=.
115 else
116     srcdest=${srcdest}
117     top_builddir=$PWD
118 fi
119 abs_top_srcdir=${abs_top_srcdir-$(cd ${srcdir} && pwd)}
120 abs_top_builddir=$PWD
121
122 if test -z "$GUILE" -o "$GUILE" = true; then
123     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
124 else
125     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
126 fi
127 bindir=$(eval echo ${bindir-$prefix/bin})
128 datadir=$(eval echo ${datadir-$prefix/share})
129 docdir=$(eval echo ${docdir-$datadir/doc/mes-$VERSION})
130 infodir=$(eval echo ${infodir-$datadir/info})
131 includedir=$(eval echo ${libdir-$prefix/include})
132 libdir=$(eval echo ${libdir-$prefix/lib})
133 mandir=$(eval echo ${mandir-$datadir/man})
134 moduledir=$(eval echo ${moduledir-$datadir/mes/module})
135 moduledir_="$moduledir/"
136 guile_site_dir=$(eval echo ${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION})
137 guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache})
138
139 subst () {
140     sed \
141     -e s,"@PACKAGE@,$PACKAGE,"\
142     -e s,"@PACKAGE_NAME@,$PACKAGE_NAME,"\
143     -e s,"@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,"\
144     -e s,"@VERSION@,$VERSION,"\
145     -e s,"@build@,$build,"\
146     -e s,"@host@,$host,"\
147     -e s,"@compiler@,$compiler,"\
148     -e s,"@courageous@,$courageous,"\
149     -e s,"@mes_bits@,$mes_bits,"\
150     -e s,"@mes_kernel@,$mes_kernel,"\
151     -e s,"@mes_cpu@,$mes_cpu,"\
152     -e s,"@mes_libc@,$mes_libc,"\
153     -e s,"@mes_system@,$mes_system,"\
154     -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\
155     -e s,"@abs_top_builddir@,$abs_top_builddir,"\
156     -e s,"@top_builddir@,$top_builddir,"\
157     -e s,"@srcdest@,$srcdest,"\
158     -e s,"@srcdir@,$srcdir,"\
159     -e s,"@prefix@,$prefix,"\
160     -e s,"@program_prefix@,$program_prefix,"\
161     -e s,"@bindir@,$bindir,"\
162     -e s,"@datadir@,$datadir,"\
163     -e s,"@docdir@,$docdir,"\
164     -e s,"@guile_site_dir@,$guile_site_dir,"\
165     -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\
166     -e s,"@infodir@,$infodir,"\
167     -e s,"@includedir@,$includedir,"\
168     -e s,"@libdir@,$libdir,"\
169     -e s,"@mandir@,$mandir,"\
170     -e s,"@moduledir@,$moduledir,"\
171     -e s,"@sysconfdir@,$sysconfdir,"\
172     -e s,"@GUILE_EFFECTIVE_VERSION@,$GUILE_EFFECTIVE_VERSION,"\
173     -e s,"@V@,$V,"\
174     -e s,"@AR@,$AR,"\
175     -e s,"@BASH@,$BASH,"\
176     -e s,"@BLOOD_ELF@,$BLOOD_ELF,"\
177     -e s,"@CC@,$CC,"\
178     -e s,"@DIFF@,$DIFF,"\
179     -e s,"@GIT@,$GIT,"\
180     -e s,"@GUILD@,$GUILD,"\
181     -e s,"@GUILE@,$GUILE,"\
182     -e s,"@PERL@,$PERL,"\
183     -e s,"@CFLAGS@,$CFLAGS,"\
184     -e s,"@HEX2@,$HEX2,"\
185     -e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
186     -e s,"@M1@,$M1,"\
187     -e s,"@M1FLAGS@,$M1FLAGS,"\
188     -e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
189     -e s,"@MES_SEED@,$MES_SEED,"\
190     -e s,"@MES_SEED@,$MES_SEED,"\
191     -e s,"@SHELL@,$SHELL,"\
192     -e s,"mes/module/,$moduledir/,"\
193     $1 > $2
194 }
195
196 host=${host-$($CC -dumpmachine 2>/dev/null)}
197 if test -z "$host$host_type"; then
198     mes_cpu=${arch-$(get_machine || uname -m)}
199 else
200     mes_cpu=${host%%-*}
201 fi
202 if test "$mes_cpu" = i386\
203         || test "$mes_cpu" = i486\
204         || test "$mes_cpu" = i586\
205         || test "$mes_cpu" = i686; then
206     mes_cpu=x86
207 fi
208 if test "$mes_cpu" = armv4\
209         || test "$arch" = armv7l; then
210     mes_cpu=arm
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/build.sh.in build.sh
242 chmod +x build.sh
243 subst ${srcdest}build-aux/check.sh.in check.sh
244 chmod +x check.sh
245 subst ${srcdest}build-aux/install.sh.in install.sh
246 chmod +x install.sh
247 subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env
248 chmod +x pre-inst-env
249 subst ${srcdest}scripts/ar.in scripts/ar
250 chmod +x scripts/ar
251 subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm
252 chmod +x scripts/mescc.scm
253 subst ${srcdest}scripts/mescc.in scripts/mescc
254 chmod +x scripts/mescc
255 subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh
256 chmod +x uninstall.sh
257
258 mkdir -p include/mes
259 if test $mes_libc = system; then
260     cat >> include/mes/config.h <<EOF
261 #define SYSTEM_LIBC 1
262 EOF
263 else
264     cat >> include/mes/config.h <<EOF
265 #undef SYSTEM_LIBC
266 EOF
267 fi
268 cat >> include/mes/config.h <<EOF
269 #define VERSION '"'$VERSION'"'
270 #define pkgdatadir "'"$pkgdatadir'"'
271
272 EOF
273
274 cat <<EOF
275 GNU Mes is configured for
276    compiler: $compiler
277    cpu:      $mes_cpu
278    bits:     $mes_bits
279    libc:     $mes_libc
280    kernel:   $mes_kernel
281    system:   $mes_system
282
283 Run:
284   ./build.sh      to build mes
285   ./check.sh      to check mes
286   ./install.sh    to install mes
287 EOF