build: Have configure respect GUILE_LOAD_PATH for mes to find Nyacc.
[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.21
24 srcdir=${srcdir-$(dirname $0)}
25 srcdest=
26 if test "$srcdir" != "."; then
27     srcdest=$srcdir/
28 fi
29 . ${srcdest}build-aux/trace.sh
30
31 # parse arguments
32 while [ $# -gt 0 ]; do
33     case $1 in
34         (--with-courage)
35             courageous=true
36             ;;
37         (--with-system-libc)
38             mes_libc=system
39             ;;
40         (--build=*)
41             build=${1#--build=}
42             host=${host-$build}
43             ;;
44         (--host=*)
45             host=${1#--host=}
46             ;;
47         (--prefix=*)
48             prefix=${1#--prefix=}
49             ;;
50         (--program-prefix=*)
51             program_prefix=${1#--program-prefix=}
52             ;;
53     esac
54     shift
55 done
56
57 prefix=${prefix-/usr/local}
58 mes_libc=${mes_libc-mes}
59 courageous=${courageous-false}
60
61 BASH=${BASH-$(command -v bash || command -v sh)}
62 BLOOD_ELF=${BLOOD_ELF-$(command -v blood-elf)}
63 CC=${CC-$(command -v gcc)} || true
64 CFLAGS=${CFLAGS-}
65 CPPFLAGS=${CPPFLAGS-}
66 DIFF=${DIFF-$(command -v diff || echo $PWD/pre-inst-env diff.scm)}
67 GUILD=${GUILD-$(command -v guild)} || true
68 GUILE_TOOLS=${GUILE_TOOLS-$(command -v guile-tools)} || true
69 if test ! "$GUILD"; then
70     if test "$GUILE_TOOLS"; then
71         GUILD=$GUILE_TOOLS
72     else
73         GUILD=true
74     fi
75 fi
76 GUILE=${GUILE-$(command -v guile)} || true
77 HEX2=${HEX2-$(command -v hex2)}
78 LDPFLAGS=${LDFLAGS-}
79 M1=${M1-$(command -v M1)}
80 MES_FOR_BUILD=${MES_FOR_BUILD-$(command -v mes || command -v guile || echo mes)}
81 GIT=${GIT-$(command -v git)} || true
82 PERL=${PERL-$(command -v perl)} || true
83 SHELL=${BASH-$SHELL}
84
85 if test "$srcdir" = .; then
86     top_builddir=.
87 else
88     srcdest=${srcdest}
89     top_builddir=$PWD
90 fi
91 abs_top_srcdir=${abs_top_srcdir-$(cd ${srcdir} && pwd)}
92 abs_top_builddir=$PWD
93
94 if test -z "$GUILE" -o "$GUILE" = true; then
95     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
96 else
97     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
98 fi
99
100 numbered_arch=false
101 mes_tools=named
102 if ( $HEX2 --help 2>&1 ) | grep -q "\-\-Architecture 12345"; then
103     numbered_arch=true
104     mes_tools=numbered
105 fi
106
107 bindir=$(eval echo ${bindir-$prefix/bin})
108 datadir=$(eval echo ${datadir-$prefix/share})
109 docdir=$(eval echo ${docdir-$datadir/doc/mes})
110 infodir=$(eval echo ${infodir-$datadir/info})
111 includedir=$(eval echo ${includedir-$prefix/include})
112 libdir=$(eval echo ${libdir-$prefix/lib})
113 pkgdatadir=$(eval echo ${pkgdatadir-$datadir/mes})
114 mandir=$(eval echo ${mandir-$datadir/man})
115 guile_site_dir=$(eval echo ${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION})
116 guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache})
117
118 subst () {
119     echo "creating $2"
120     sed \
121     -e s,"@PACKAGE@,$PACKAGE,"\
122     -e s,"@PACKAGE_NAME@,$PACKAGE_NAME,"\
123     -e s,"@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,"\
124     -e s,"@VERSION@,$VERSION,"\
125     -e s,"@bootstrap@,yes,"\
126     -e s,"@build@,$build,"\
127     -e s,"@host@,$host,"\
128     -e s,"@compiler@,$compiler,"\
129     -e s,"@courageous@,$courageous,"\
130     -e s,"@mes_bits@,$mes_bits,"\
131     -e s,"@mes_kernel@,$mes_kernel,"\
132     -e s,"@mes_cpu@,$mes_cpu,"\
133     -e s,"@mes_libc@,$mes_libc,"\
134     -e s,"@mes_system@,$mes_system,"\
135     -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\
136     -e s,"@abs_top_builddir@,$abs_top_builddir,"\
137     -e s,"@top_builddir@,$top_builddir,"\
138     -e s,"@srcdest@,$srcdest,"\
139     -e s,"@srcdir@,$srcdir,"\
140     -e s,"@prefix@,$prefix,"\
141     -e s,"@program_prefix@,$program_prefix,"\
142     -e s,"@bindir@,$bindir,"\
143     -e s,"@datadir@,$datadir,"\
144     -e s,"@docdir@,$docdir,"\
145     -e s,"@guile_site_dir@,$guile_site_dir,"\
146     -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\
147     -e s,"@infodir@,$infodir,"\
148     -e s,"@includedir@,$includedir,"\
149     -e s,"@libdir@,$libdir,"\
150     -e s,"@mandir@,$mandir,"\
151     -e s,"@pkgdatadir@,$pkgdatadir,"\
152     -e s,"@sysconfdir@,$sysconfdir,"\
153     -e s,"@GUILE_EFFECTIVE_VERSION@,$GUILE_EFFECTIVE_VERSION,"\
154     -e s,"@GUILE_LOAD_PATH@,$GUILE_LOAD_PATH,"\
155     -e s,"@V@,$V,"\
156     -e s,"@AR@,$AR,"\
157     -e s,"@BASH@,$BASH,"\
158     -e s,"@BLOOD_ELF@,$BLOOD_ELF,"\
159     -e s,"@CC@,$CC,"\
160     -e s,"@DIFF@,$DIFF,"\
161     -e s,"@GIT@,$GIT,"\
162     -e s,"@GUILD@,$GUILD,"\
163     -e s,"@GUILE@,$GUILE,"\
164     -e s,"@PERL@,$PERL,"\
165     -e s,"@CFLAGS@,$CFLAGS,"\
166     -e s,"@HEX2@,$HEX2,"\
167     -e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
168     -e s,"@M1@,$M1,"\
169     -e s,"@M1FLAGS@,$M1FLAGS,"\
170     -e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
171     -e s,"@numbered_arch@,$numbered_arch,"\
172     -e s,"@SHELL@,$SHELL,"\
173     $1 > $2
174 }
175
176 host=${host-$($CC -dumpmachine 2>/dev/null)}
177 if test -z "$host$host_type"; then
178     mes_cpu=${arch-$(get_machine || uname -m)}
179 else
180     mes_cpu=${host%%-*}
181 fi
182 if test "$mes_cpu" = i386\
183         || test "$mes_cpu" = i486\
184         || test "$mes_cpu" = i586\
185         || test "$mes_cpu" = i686; then
186     mes_cpu=x86
187 fi
188 if test "$mes_cpu" = armv4\
189         || test "$arch" = armv7l; then
190     mes_cpu=arm
191 fi
192 if test "$mes_cpu" = amd64; then
193     mes_cpu=x86_64
194 fi
195
196 case "$host" in
197     *linux-gnu|*linux)
198         mes_kernel=linux;;
199     *gnu)
200         mes_kernel=gnu;;
201     *freebsd*)
202         mes_kernel=frreebsd;;
203     *)
204         mes_kernel=linux;;
205 esac
206
207 case "$mes_cpu" in
208     x86_64)
209         mes_bits=64;;
210     *)
211         mes_bits=32;;
212 esac
213 #
214 if $CC --version | grep gcc; then
215     compiler=gcc
216 elif $CC --version | grep tcc; then
217     compiler=gcc
218 else
219     compiler=mescc
220     AR=${AR-$PWD/scripts/mesar}
221 fi
222
223 AR=${AR-$(command -v ar)} || true
224
225 mes_system=$mes_cpu-$mes_kernel-mes
226
227 mkdir -p scripts
228 subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile
229 subst ${srcdest}build-aux/config.sh.in config.sh
230 subst ${srcdest}build-aux/bootstrap.sh.in bootstrap.sh
231 chmod +x bootstrap.sh
232 subst ${srcdest}build-aux/build.sh.in build.sh
233 chmod +x build.sh
234 subst ${srcdest}build-aux/check.sh.in check.sh
235 chmod +x check.sh
236 subst ${srcdest}build-aux/install.sh.in install.sh
237 chmod +x install.sh
238 subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env
239 chmod +x pre-inst-env
240 subst ${srcdest}scripts/mesar.in scripts/mesar
241 chmod +x scripts/mesar
242 subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm
243 chmod +x scripts/mescc.scm
244 subst ${srcdest}scripts/mescc.in scripts/mescc
245 chmod +x scripts/mescc
246 subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh
247 chmod +x uninstall.sh
248
249 mkdir -p include/mes
250 rm -f include/mes/config.h
251 if test $mes_libc = system; then
252     cat >> include/mes/config.h <<EOF
253 #define SYSTEM_LIBC 1
254 EOF
255 else
256     cat >> include/mes/config.h <<EOF
257 #undef SYSTEM_LIBC
258 EOF
259 fi
260 cat >> include/mes/config.h <<EOF
261 #define MES_VERSION "$VERSION"
262 EOF
263
264 cat <<EOF
265 GNU Mes is configured for
266    compiler:   $compiler
267    cpu:        $mes_cpu
268    bits:       $mes_bits
269    libc:       $mes_libc
270    kernel:     $mes_kernel
271    system:     $mes_system
272    tools:      $mes_tools arch
273    courageous: $courageous
274    bootstrap:  yes
275
276 Run:
277   sh bootstrap.sh  to bootstrap build mes
278   sh check.sh      to check mes
279   sh install.sh    to install mes
280 EOF