diff --git a/build-aux/bootstrap.sh.in b/build-aux/bootstrap.sh.in
index 3665a0ec..4c2b376b 100644
--- a/build-aux/bootstrap.sh.in
+++ b/build-aux/bootstrap.sh.in
@@ -27,17 +27,22 @@ MES_STACK=${MES_STACK-5000000}
export MES_STACK
MES_PREFIX=${MES_PREFIX-$PWD}
-. build-aux/configure-lib.sh
+. ./config.sh
+. ${srcdest}build-aux/configure-lib.sh
+. ${srcdest}build-aux/cflags.sh
CPPFLAGS="-D HAVE_CONFIG_H=1 -I include"
AM_CFLAGS=""
mkdir -p mescc-lib
cp config.sh mescc-lib/config.sh
cd mescc-lib
-srcdest=../
+srcdest=../${srcdest}
+ln -sf ${srcdest}mes .
+ln -sf ${srcdest}module .
+ln -sf ${srcdest}src .
AM_CPPFLAGS="-D HAVE_CONFIG_H=1 -I ${srcdest}include -I ${srcdest}include/$mes_kernel/$mes_cpu"
-mkdir $mes_cpu-mes
+mkdir -p $mes_cpu-mes
$CC -c $AM_CPPFLAGS $CPPFLAGS $AM_CFLAGS $CFLAGS ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/crt1.c
cp crt1.o $mes_cpu-mes
cp crt1.s $mes_cpu-mes
diff --git a/build-aux/build-lib.sh b/build-aux/build-lib.sh
index b70902aa..4ef701c3 100755
--- a/build-aux/build-lib.sh
+++ b/build-aux/build-lib.sh
@@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mes. If not, see .
-srcdest=${srcdest-}
+. ./config.sh
. ${srcdest}build-aux/configure-lib.sh
. ${srcdest}build-aux/trace.sh
. ${srcdest}build-aux/cc.sh
diff --git a/build-aux/build.sh.in b/build-aux/build.sh.in
index ca7c46f7..ff2f2f0b 100644
--- a/build-aux/build.sh.in
+++ b/build-aux/build.sh.in
@@ -36,6 +36,7 @@ fi
set -u
. ./config.sh
+. ${srcdest}build-aux/cflags.sh
if $courageous; then
echo "Applying courage"
@@ -48,41 +49,6 @@ if test -n "$GUILE" -a "$GUILE" != true; then
${SHELL} ${srcdest}build-aux/build-guile.sh
fi
-AM_CFLAGS=
-
-if test $mes_libc = mes; then
- AM_CFLAGS="
--static
-"
- AM_CFLAGS="$AM_CFLAGS
--nostdinc
--nostdlib
--fno-builtin
-"
-fi
-
-AM_CPPFLAGS="
--D HAVE_CONFIG_H=1
--I ../include
--I ${srcdir}/../include
--I ${srcdir}/../include/$mes_kernel/$mes_cpu
-"
-
-AM_LDFLAGS="
--L .
-"
-if test $mes_libc = mes; then
- AM_LDFLAGS="$AM_LDFLAGS
--nostdlib
-"
-fi
-LIBS=-lc
-
-export AM_CFLAGS CFLAGS
-export AM_CPPFLAGS CPPFLAGS
-export AM_LDFLAGS LDFLAGS
-export LIBS
-
(
mkdir -p gcc-lib
cp config.sh gcc-lib
diff --git a/build-aux/cflags.sh b/build-aux/cflags.sh
new file mode 100644
index 00000000..835a5f83
--- /dev/null
+++ b/build-aux/cflags.sh
@@ -0,0 +1,50 @@
+# GNU Mes --- Maxwell Equations of Software
+# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen
+#
+# This file is part of GNU Mes.
+#
+# GNU Mes is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GNU Mes is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mes. If not, see .
+
+AM_CPPFLAGS="
+-D HAVE_CONFIG_H=1
+-I ${srcdest}include
+-I ${srcdest}include/$mes_kernel/$mes_cpu
+"
+
+AM_CFLAGS=
+
+if test $mes_libc = mes; then
+ AM_CFLAGS="$AM_CFLAGS
+-static
+-nostdinc
+-nostdlib
+-fno-builtin
+"
+fi
+
+AM_LDFLAGS="
+-L .
+"
+if test $mes_libc = mes; then
+ AM_LDFLAGS="$AM_LDFLAGS
+-static
+-nostdlib
+"
+fi
+LIBS=-lc
+
+export AM_CFLAGS CFLAGS
+export AM_CPPFLAGS CPPFLAGS
+export AM_LDFLAGS LDFLAGS
+export LIBS
diff --git a/configure.sh b/configure.sh
index 0139cbc3..704be03c 100755
--- a/configure.sh
+++ b/configure.sh
@@ -22,6 +22,10 @@ set -e
VERSION=0.21
srcdir=${srcdir-$(dirname $0)}
+srcdest=
+if test "$srcdir" != "."; then
+ srcdest=$srcdir/
+fi
. ${srcdest}build-aux/trace.sh
# parse arguments
@@ -210,6 +214,7 @@ fi
mes_system=$mes_cpu-$mes_kernel-mes
+mkdir -p scripts
subst ${srcdest}build-aux/GNUmakefile.in GNUmakefile
subst ${srcdest}build-aux/config.sh.in config.sh
subst ${srcdest}build-aux/bootstrap.sh.in bootstrap.sh