mescc: Compile fixes.
[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 PERL=${PERL-$(command -v perl)} || true
73 MES_SEED=${MES_SEED-../mes-seed}
74
75 if [ "$srcdir" = . ]; then
76     top_builddir=.
77 else
78     srcdest=${srcdest}
79     top_builddir=$PWD
80 fi
81 abs_top_srcdir=${abs_top_srcdir-$(cd ${srcdir} && pwd)}
82 abs_top_builddir=$PWD
83
84 if [ -z "$GUILE" -o "$GUILE" = true ]; then
85     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2}
86 else
87     GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
88 fi
89 bindir=$(eval echo ${bindir-$prefix/bin})
90 datadir=$(eval echo ${datadir-$prefix/share})
91 docdir=$(eval echo ${docdir-$datadir/doc/mes-$VERSION})
92 infodir=$(eval echo ${infodir-$datadir/info})
93 libdir=$(eval echo ${libdir-$prefix/lib})
94 mandir=$(eval echo ${mandir-$datadir/man})
95 moduledir=$(eval echo ${moduledir-$datadir/mes/module})
96 moduledir_="$moduledir/"
97 guile_site_dir=$(eval echo ${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION})
98 guile_site_ccache_dir=$(eval echo ${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache})
99
100 subst () {
101     sed \
102     -e s,"@PACKAGE@,$PACKAGE,"\
103     -e s,"@VERSION@,$VERSION,"\
104     -e s,"@arch@,$arch,"\
105     -e s,"@build@,$build,"\
106     -e s,"@host@,$host,"\
107     -e s,"@compiler@,$compiler,"\
108     -e s,"@gcc_p@,$gcc_p,"\
109     -e s,"@mes_p@,$mes_p,"\
110     -e s,"@mesc_p@,$mesc_p,"\
111     -e s,"@tcc_p@,$tcc_p,"\
112     -e s,"@mes_arch@,$mes_arch,"\
113     -e s,"@posix_p@,$posix_p,"\
114     -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\
115     -e s,"@abs_top_builddir@,$abs_top_builddir,"\
116     -e s,"@top_builddir@,$top_builddir,"\
117     -e s,"@srcdest@,$srcdest,"\
118     -e s,"@srcdir@,$srcdir,"\
119     -e s,"@prefix@,$prefix,"\
120     -e s,"@program_prefix@,$program_prefix,"\
121     -e s,"@bindir@,$bindir,"\
122     -e s,"@datadir@,$datadir,"\
123     -e s,"@docdir@,$docdir,"\
124     -e s,"@guile_site_dir@,$guile_site_dir,"\
125     -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\
126     -e s,"@infodir@,$infodir,"\
127     -e s,"@libdir@,$libdir,"\
128     -e s,"@mandir@,$mandir,"\
129     -e s,"@moduledir@,$moduledir,"\
130     -e s,"@sysconfdir@,$sysconfdir,"\
131     -e s,"@GUILE_EFFECTIVE_VERSION@,$GUILE_EFFECTIVE_VERSION,"\
132     -e s,"@V@,$V,"\
133     -e s,"@AR@,$AR,"\
134     -e s,"@BASH@,$BASH,"\
135     -e s,"@BLOOD_ELF@,$BLOOD_ELF,"\
136     -e s,"@CC@,$CC,"\
137     -e s,"@GUILD@,$GUILD,"\
138     -e s,"@GUILE@,$GUILE,"\
139     -e s,"@PERL@,$PERL,"\
140     -e s,"@CFLAGS@,$CFLAGS,"\
141     -e s,"@HEX2@,$HEX2,"\
142     -e s,"@HEX2FLAGS@,$HEX2FLAGS,"\
143     -e s,"@M1@,$M1,"\
144     -e s,"@M1FLAGS@,$M1FLAGS,"\
145     -e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\
146     -e s,"@MES_SEED@,$MES_SEED,"\
147     -e s,"mes/module/,$moduledir/,"\
148     $1 > $2
149 }
150
151 subst ${srcdest}build-aux/pre-inst-env.in pre-inst-env
152 chmod +x pre-inst-env
153 subst ${srcdest}scripts/mescc.in scripts/mescc
154 chmod +x scripts/mescc
155
156 host=${host-$($CC -dumpmachine 2>/dev/null || echo x86)}
157 if [ -z "$host" ]; then
158     arch=${arch-$(get_machine || uname -m)}
159 else
160     arch=${host%%-*}
161 fi
162 if [ "$arch" = i386\
163              -o "$arch" = i486\
164              -o "$arch" = i586\
165              -o "$arch" = i686\
166    ]; then
167     arch=x86
168 fi
169
170 #
171 if $CC --version | grep gcc 2>/dev/null; then
172     gcc_p=1
173     compiler=gcc
174 elif $CC --version | grep tcc 2>/dev/null; then
175     tcc_p=1
176     compiler=tcc
177 else
178     mes_p=1
179     mesc_p=1
180     compiler=mescc
181 fi
182
183 mes_arch=$arch
184 if [ "$mes_p" -o "$mesc_p" ]; then
185     mes_arch=$arch-mes
186 fi
187
188 if [ ! "$mesc_p" ]; then
189     mes_arch=$mes_arch-$compiler
190 fi
191 if [ ! "$mesc_p" -a ! "$mes_p" ]; then
192     posix_p=1
193 fi
194
195 subst ${srcdest}mes/module/mes/boot-0.scm.in mes/module/mes/boot-0.scm
196 subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile
197 subst ${srcdest}build-aux/config.status.in config.status
198 subst ${srcdest}build-aux/build.sh.in build.sh
199 chmod +x build.sh
200 subst ${srcdest}build-aux/check.sh.in check.sh
201 chmod +x check.sh
202 subst ${srcdest}build-aux/install.sh.in install.sh
203 chmod +x install.sh
204 subst ${srcdest}build-aux/uninstall.sh.in uninstall.sh
205 chmod +x uninstall.sh
206
207 cat <<EOF
208 GNU Mes is configured for $mes_arch
209
210 Run:
211   ./build.sh      to build mes
212   ./check.sh      to check mes
213   ./install.sh    to install mes
214 EOF