build: Support building with Gash.
[mes.git] / configure.sh
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2018 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.18
24 srcdir=${srcdir-$(dirname $0)}
25 . ${srcdest}build-aux/trace.sh
26
27 # parse --mes
28 cmdline=$(echo " $@")
29 p=${cmdline/ --mes/}
30 if [ "$p" != "$cmdline" ]; then
31     mes_p=${mes_p-1}
32 fi
33
34 # parse --prefix=PREFIX
35 p=${cmdline/ --prefix=/ -prefix=}
36 if [ "$p" != "$cmdline" ]; then
37     p=${p##* -prefix=}
38     p=${p% *}
39     p=${p% -*}
40     prefix=${p-/usr/local}
41
42 else
43     prefix=${prefix-/usr/local}
44 fi
45
46 # parse --program-prefix=
47 p=${cmdline/ --program-prefix=/ -program-prefix=}
48 if [ "$p" != "$cmdline" ]; then
49     p=${p##* -program-prefix=}
50     p=${p% *}
51     p=${p% -*}
52     program_prefix=$p
53 fi
54
55 AR=${AR-$(command -v ar)} || true
56 BASH=${BASH-$(command -v bash)}
57 BLOOD_ELF=${BLOOD_ELF-$(command -v blood-elf)}
58 CC=${CC-$(command -v gcc)} || true
59 GUILD=${GUILD-$(command -v guild)} || true
60 GUILE_TOOLS=${GUILE_TOOLS-$(command -v guile-tools)} || true
61 if [ ! "$GUILD" ]; then
62     if [ "$GUILE_TOOLS" ]; then
63         GUILD=$GUILE_TOOLS
64     else
65         GUILD=true
66     fi
67 fi
68 GUILE=${GUILE-$(command -v guile)} || true
69 HEX2=${HEX2-$(command -v hex2)}
70 M1=${M1-$(command -v M1)}
71 MES_FOR_BUILD=${MES_FOR_BUILD-$(command -v mes || command -v guile || echo mes)}
72 GIT=${GIT-$(command -v git)} || true
73 PERL=${PERL-$(command -v perl)} || true
74 MES_SEED=${MES_SEED-../mes-seed}
75
76 if [ "$srcdir" = . ]; then
77     top_builddir=.
78 else
79     srcdest=${srcdest}
80     top_builddir=$PWD
81 fi
82 abs_top_srcdir=${abs_top_srcdir-$(cd ${srcdir} && pwd)}
83 abs_top_builddir=$PWD
84
85 if [ -z "$GUILE" -o "$GUILE" = true ]; then
86     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
87 else
88     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
89 fi
90 bindir=$(eval echo ${bindir-$prefix/bin})
91 datadir=$(eval echo ${datadir-$prefix/share})
92 docdir=$(eval echo ${docdir-$datadir/doc/mes-$VERSION})
93 infodir=$(eval echo ${infodir-$datadir/info})
94 libdir=$(eval echo ${libdir-$prefix/lib})
95 mandir=$(eval echo ${mandir-$datadir/man})
96 moduledir=$(eval echo ${moduledir-$datadir/mes/module})
97 moduledir_="$moduledir/"
98 guile_site_dir=$(eval echo ${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION})
99 guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache})
100
101 subst () {
102     sed \
103     -e s,"@PACKAGE@,$PACKAGE,"\
104     -e s,"@VERSION@,$VERSION,"\
105     -e s,"@arch@,$arch,"\
106     -e s,"@build@,$build,"\
107     -e s,"@host@,$host,"\
108     -e s,"@compiler@,$compiler,"\
109     -e s,"@gcc_p@,$gcc_p,"\
110     -e s,"@mes_p@,$mes_p,"\
111     -e s,"@mesc_p@,$mesc_p,"\
112     -e s,"@tcc_p@,$tcc_p,"\
113     -e s,"@mes_arch@,$mes_arch,"\
114     -e s,"@posix_p@,$posix_p,"\
115     -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\
116     -e s,"@abs_top_builddir@,$abs_top_builddir,"\
117     -e s,"@top_builddir@,$top_builddir,"\
118     -e s,"@srcdest@,$srcdest,"\
119     -e s,"@srcdir@,$srcdir,"\
120     -e s,"@prefix@,$prefix,"\
121     -e s,"@program_prefix@,$program_prefix,"\
122     -e s,"@bindir@,$bindir,"\
123     -e s,"@datadir@,$datadir,"\
124     -e s,"@docdir@,$docdir,"\
125     -e s,"@guile_site_dir@,$guile_site_dir,"\
126     -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\
127     -e s,"@infodir@,$infodir,"\
128     -e s,"@libdir@,$libdir,"\
129     -e s,"@mandir@,$mandir,"\
130     -e s,"@moduledir@,$moduledir,"\
131     -e s,"@sysconfdir@,$sysconfdir,"\
132     -e s,"@GUILE_EFFECTIVE_VERSION@,$GUILE_EFFECTIVE_VERSION,"\
133     -e s,"@V@,$V,"\
134     -e s,"@AR@,$AR,"\
135     -e s,"@BASH@,$BASH,"\
136     -e s,"@BLOOD_ELF@,$BLOOD_ELF,"\
137     -e s,"@CC@,$CC,"\
138     -e s,"@GIT@,$GIT,"\
139     -e s,"@GUILD@,$GUILD,"\
140     -e s,"@GUILE@,$GUILE,"\
141     -e s,"@PERL@,$PERL,"\
142     -e s,"@CFLAGS@,$CFLAGS,"\
143     -e s,"@HEX2@,$HEX2,"\
144     -e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
145     -e s,"@M1@,$M1,"\
146     -e s,"@M1FLAGS@,$M1FLAGS,"\
147     -e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
148     -e s,"@MES_SEED@,$MES_SEED,"\
149     -e s,"@MES_SEED@,$MES_SEED,"\
150     -e s,"@SHELL@,$SHELL,"\
151     -e s,"mes/module/,$moduledir/,"\
152     $1 > $2
153 }
154
155 subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env
156 chmod +x pre-inst-env
157 subst ${srcdest}scripts/mescc.in scripts/mescc
158 chmod +x scripts/mescc
159 subst ${srcdest}scripts/mescc.scm.in scripts/mescc.scm
160 chmod +x scripts/mescc.scm
161
162 host=${host-$($CC -dumpmachine 2>/dev/null || echo x86)}
163 if [ -z "$host" ]; then
164     arch=${arch-$(get_machine || uname -m)}
165 else
166     arch=${host%%-*}
167 fi
168 if [ "$arch" = i386\
169              -o "$arch" = i486\
170              -o "$arch" = i586\
171              -o "$arch" = i686\
172    ]; then
173     arch=x86
174 fi
175
176 #
177 if $CC --version | grep gcc; then #2>/dev/null; then
178     gcc_p=1
179     compiler=gcc
180 elif $CC --version | grep tcc; then #2>/dev/null; then
181     tcc_p=1
182     compiler=tcc
183 else
184     mes_p=1
185     mesc_p=1
186     compiler=mescc
187 fi
188
189 mes_arch=$arch
190 if [ "$mes_p" -o "$mesc_p" ]; then
191     mes_arch=$arch-mes
192 fi
193
194 if [ ! "$mesc_p" ]; then
195     mes_arch=$mes_arch-$compiler
196 fi
197 if [ ! "$mesc_p" -a ! "$mes_p" ]; then
198     posix_p=1
199 fi
200
201 subst ${srcdest}mes/module/mes/boot-0.scm.in mes/module/mes/boot-0.scm
202 subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile
203 subst ${srcdest}build-aux/config.status.in config.status
204 subst ${srcdest}build-aux/build.sh.in build.sh
205 chmod +x build.sh
206 subst ${srcdest}build-aux/bootstrap.sh.in bootstrap.sh
207 chmod +x bootstrap.sh
208 subst ${srcdest}build-aux/check.sh.in check.sh
209 chmod +x check.sh
210 subst ${srcdest}build-aux/install.sh.in install.sh
211 chmod +x install.sh
212 subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh
213 chmod +x uninstall.sh
214
215 cat <<EOF
216 GNU Mes is configured for $mes_arch
217
218 Run:
219   ./build.sh      to build mes
220   ./check.sh      to check mes
221   ./install.sh    to install mes
222 EOF