build: Prepare for autoconfiscation.

Make build system more in alignment with how autotools work.  This
will make transition easier.

* mes/module/mes/boot-0.scm.in: Update from module/mes/boot-0.scm.
* scripts/mescc.in: Update from scripts/mescc.
* build-aux/pre-inst-env.in: New file.
* build-aux/cc-mes.sh: Use pre-inst-env.
* configure: Substitute new .in files.
* install.sh: Do not substitute mescc, boot-0.scm.
This commit is contained in:
Jan Nieuwenhuizen 2018-07-21 18:28:47 +02:00
parent 87269a16f6
commit 5d3fa50384
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
9 changed files with 141 additions and 68 deletions

4
.gitignore vendored
View file

@ -67,3 +67,7 @@
/doc/mes.pdf /doc/mes.pdf
/doc/mescc.1 /doc/mescc.1
/doc/version.texi /doc/version.texi
/pre-inst-env
/mes/module/mes/boot-0.scm
/scripts/mescc

View file

@ -64,8 +64,7 @@ clean-go:
check: check:
./check.sh ./check.sh
install: src/mes
install:
./install.sh ./install.sh
.config.make: ./configure .config.make: ./configure

View file

@ -63,20 +63,20 @@ else
fi fi
if [ -n "$PREPROCESS" ]; then if [ -n "$PREPROCESS" ]; then
bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -E -o "$o.E" "$c".c ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -E -o "$o.E" "$c".c
bash $MESCC $MES_CFLAGS -S "$o".E ./pre-inst-env bash $MESCC $MES_CFLAGS -S "$o".E
bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S ./pre-inst-env bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S
if [ -z "$NOLINK" ]; then if [ -z "$NOLINK" ]; then
bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS ./pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS
fi fi
elif [ -n "$COMPILE" ]; then elif [ -n "$COMPILE" ]; then
bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -S -o "$o.S" "$c".c ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -S -o "$o.S" "$c".c
bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S ./pre-inst-env bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S
if [ -z "$NOLINK" ]; then if [ -z "$NOLINK" ]; then
bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS ./pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS
fi fi
elif [ -z "$NOLINK" ]; then elif [ -z "$NOLINK" ]; then
bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -o "$o".${p}out "$c".c $MES_LIBS ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -o "$o".${p}out "$c".c $MES_LIBS
else else
bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -c -o "$o".${p}o "$c".c ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -c -o "$o".${p}o "$c".c
fi fi

View file

@ -73,7 +73,7 @@ for t in $tests; do
echo $t: [SKIP]; echo $t: [SKIP];
continue continue
fi fi
sh "$t" &> $t.${mes}log ./pre-inst-env sh "$t" &> $t.${mes}log
r=$? r=$?
total=$((total+1)) total=$((total+1))
if [ $r = 0 ]; then if [ $r = 0 ]; then

37
build-aux/pre-inst-env.in Normal file
View file

@ -0,0 +1,37 @@
#!/bin/sh
# Mes --- Maxwell Equations of Software
# Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of Mes.
#
# 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.
#
# 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 Mes. If not, see <http://www.gnu.org/licenses/>.
abs_top_srcdir="$(cd "@abs_top_srcdir@" > /dev/null; pwd -P)"
abs_top_builddir="$(cd "@abs_top_builddir@" > /dev/null; pwd -P)"
MES_PREFIX=mes
export MES_PREFIX
GUILE_LOAD_COMPILED_PATH="$abs_top_builddir/module${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH"
GUILE_LOAD_PATH="$abs_top_srcdir/module${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH
PATH="$abs_top_builddir/scripts:$PATH"
export PATH
LANG=
LC_ALL=
exec "$@"

60
configure vendored
View file

@ -46,6 +46,7 @@ exec ${GUILE-guile} -L . --no-auto-compile -e '(configure)' -s "$0" ${1+"$@"}
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>. ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
(define-module (configure) (define-module (configure)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (ice-9 and-let-star) #:use-module (ice-9 and-let-star)
#:use-module (ice-9 curried-definitions) #:use-module (ice-9 curried-definitions)
@ -54,12 +55,18 @@ exec ${GUILE-guile} -L . --no-auto-compile -e '(configure)' -s "$0" ${1+"$@"}
#:use-module (ice-9 optargs) #:use-module (ice-9 optargs)
#:use-module (ice-9 popen) #:use-module (ice-9 popen)
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
#:export (main)) #:export (main))
(define* (PATH-search-path name #:key (default name) warn?)
(or (search-path (string-split (getenv "PATH") #\:) name)
(and (and warn? (format (current-error-port) "warning: not found: ~a\n" name))
default)))
(define *shell* "sh") (define *shell* "sh")
(define PACKAGE "mes") (define PACKAGE "mes")
(define VERSION "0.16.1") (define VERSION "0.16.1")
(define GUILE (or (getenv "guile") "guile")) (define GUILE (PATH-search-path (or (getenv "guile") "guile")))
(define GUILE_EFFECTIVE_VERSION (effective-version)) (define GUILE_EFFECTIVE_VERSION (effective-version))
(define prefix "/usr/local") (define prefix "/usr/local")
@ -128,11 +135,6 @@ exec ${GUILE-guile} -L . --no-auto-compile -e '(configure)' -s "$0" ${1+"$@"}
(char-set-complement (char-set #\.))))) (char-set-complement (char-set #\.)))))
(map string->number version))) (map string->number version)))
(define* (PATH-search-path name #:key (default name) warn?)
(or (search-path (string-split (getenv "PATH") #\:) name)
(and (and warn? (format (current-error-port) "warning: not found: ~a\n" name))
default)))
(define optional '()) (define optional '())
(define required '()) (define required '())
(define* (check-version name expected (define* (check-version name expected
@ -261,8 +263,22 @@ Some influential environment variables:
TINYCC_SEED location of tinycc-seed TINYCC_SEED location of tinycc-seed
" PACKAGE VERSION (getenv "prefix"))) " PACKAGE VERSION (getenv "prefix")))
(define* (substitute file-name pairs
#:key (target (if (string-suffix? ".in" file-name)
(string-drop-right file-name 3) target)))
(with-output-to-file target
(lambda _
(display
(fold (lambda (o result)
(regexp-substitute/global #f (car o) result 'pre (cdr o) 'post))
(with-input-from-file file-name read-string) pairs)))))
(define (main args) (define (main args)
(let* ((CC (or (getenv "CC") "gcc")) (let* ((CC (or (getenv "CC") "gcc"))
(srcdir (dirname (car (command-line))))
(abs-top-srcdir (canonicalize-path srcdir))
(builddir (getcwd))
(abs-top-builddir (canonicalize-path builddir))
(BUILD_TRIPLET %host-type) (BUILD_TRIPLET %host-type)
(ARCH (car (string-split BUILD_TRIPLET #\-))) (ARCH (car (string-split BUILD_TRIPLET #\-)))
(options (parse-opts args)) (options (parse-opts args))
@ -271,6 +287,13 @@ Some influential environment variables:
(prefix (option-ref options 'prefix prefix)) (prefix (option-ref options 'prefix prefix))
(infodir (option-ref options 'infodir infodir)) (infodir (option-ref options 'infodir infodir))
(sysconfdir (option-ref options 'sysconfdir sysconfdir)) (sysconfdir (option-ref options 'sysconfdir sysconfdir))
(datadir (string-append prefix "/share/mes"))
(moduledir (string-append datadir"module"))
(guile-effective-version (effective-version))
(guile-site-dir (if (equal? prefix ".") (canonicalize-path ".")
(string-append prefix "/share/guile/site/" guile-effective-version)))
(guile-site-ccache-dir (if (equal? prefix ".") (canonicalize-path ".")
(string-append prefix "/lib/guile/" guile-effective-version "/site-ccache")))
(verbose? (option-ref options 'verbose #f)) (verbose? (option-ref options 'verbose #f))
(with-courage? (option-ref options 'with-courage #f)) (with-courage? (option-ref options 'with-courage #f))
(disable-silent-rules? (option-ref options 'disable-silent-rules #f)) (disable-silent-rules? (option-ref options 'disable-silent-rules #f))
@ -281,6 +304,7 @@ Some influential environment variables:
(let ((CC32 (or (getenv "CC32") (let ((CC32 (or (getenv "CC32")
(if (member ARCH '("i686" "arm")) (string-append BUILD_TRIPLET "-" CC) (if (member ARCH '("i686" "arm")) (string-append BUILD_TRIPLET "-" CC)
"i686-unknown-linux-gnu-gcc"))) "i686-unknown-linux-gnu-gcc")))
(BASH (or (getenv "BASH") "bash"))
(HELP2MAN (or (getenv "HELP2MAN") "help2man")) (HELP2MAN (or (getenv "HELP2MAN") "help2man"))
(TCC (or (getenv "TCC") "tcc")) (TCC (or (getenv "TCC") "tcc"))
(MAKEINFO (or (getenv "MAKEINFO") "makeinfo")) (MAKEINFO (or (getenv "MAKEINFO") "makeinfo"))
@ -319,6 +343,9 @@ Some influential environment variables:
(when (and (not (member ARCH '("i686" "x86_64"))) (not with-courage?)) (when (and (not (member ARCH '("i686" "x86_64"))) (not with-courage?))
(stderr "platform not supported: ~a, try --with-courage\n" ARCH) (stderr "platform not supported: ~a, try --with-courage\n" ARCH)
(exit 1)) (exit 1))
(if (check-version "bash" '(2))
(set! BASH (PATH-search-path BASH))
(set! BASH #f))
(if (not (check-version CC '(4 8) #:optional? #t)) (if (not (check-version CC '(4 8) #:optional? #t))
(set! CC #f)) (set! CC #f))
(when CC (when CC
@ -349,6 +376,8 @@ Some influential environment variables:
(stdout "prefix:=~a\n" (gulp-pipe (string-append "echo " prefix))) (stdout "prefix:=~a\n" (gulp-pipe (string-append "echo " prefix)))
(stdout "infodir:=~a\n" infodir) (stdout "infodir:=~a\n" infodir)
(stdout "mandir:=~a\n" mandir) (stdout "mandir:=~a\n" mandir)
(stdout "datadir:=~a\n" datadir)
(stdout "moduledir:=~a\n" moduledir)
(stdout "sysconfdir:=~a\n" sysconfdir) (stdout "sysconfdir:=~a\n" sysconfdir)
(stdout "ARCH:=~a\n" ARCH) (stdout "ARCH:=~a\n" ARCH)
@ -378,6 +407,25 @@ Some influential environment variables:
(when HEX2FLAGS (stdout "HEX2FLAGS:=~a\n" HEX2FLAGS)) (when HEX2FLAGS (stdout "HEX2FLAGS:=~a\n" HEX2FLAGS))
(when M1FLAGS (stdout "M1FLAGS:=~a\n" M1FLAGS)) (when M1FLAGS (stdout "M1FLAGS:=~a\n" M1FLAGS))
(when MES_CFLAGS (stdout "MES_CFLAGS:=~a\n" MES_CFLAGS)))) (when MES_CFLAGS (stdout "MES_CFLAGS:=~a\n" MES_CFLAGS))))
(let ((pairs `(("@abs_top_srcdir@" . ,abs-top-srcdir)
("@abs_top_builddir@" . ,abs-top-builddir)
("@BASH@" . ,BASH)
("@GUILE@" . ,GUILE)
("@guile_site_dir@" . ,guile-site-dir)
("@guile_site_ccache_dir@" . ,guile-site-ccache-dir)
("@VERSION@" . ,VERSION)
("mes/module/" . ,(string-append moduledir "/")))))
(for-each (lambda (o)
(substitute o pairs)
(chmod (string-drop-right o 3) #o755))
'(
"build-aux/pre-inst-env.in"
"mes/module/mes/boot-0.scm.in"
"scripts/mescc.in"
)))
(chmod "build-aux/pre-inst-env" #o755)
(rename-file "build-aux/pre-inst-env" "pre-inst-env")
(chmod "scripts/mescc" #o755)
(format (current-output-port) (format (current-output-port)
"\nRun: "\nRun:
~a to build mes ~a to build mes

View file

@ -15,24 +15,45 @@ MES_PREFIX=${MES_PREFIX-$prefix/share/mes}
MES_SEED=${MES_SEED-../MES-SEED} MES_SEED=${MES_SEED-../MES-SEED}
TINYCC_SEED=${TINYCC_SEED-../TINYCC-SEED} TINYCC_SEED=${TINYCC_SEED-../TINYCC-SEED}
GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2} GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')}
datadir=${moduledir-$prefix/share/mes} bindir=${bindir-$prefix/bin}
docdir=${moduledir-$prefix/share/doc/mes} datadir=${datadir-$prefix/share/mes}
docdir=${docdir-$prefix/share/doc/mes}
infodir=${infodir-$prefix/share/info}
mandir=${mandir-$prefix/share/man} mandir=${mandir-$prefix/share/man}
moduledir=${moduledir-$datadir/module} moduledir=${moduledir-$datadir/module}
guile_site_dir=${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION} guile_site_dir=${guile_site_dir-$prefix/share/guile/site/$GUILE_EFFECTIVE_VERSION}
guile_site_ccache_dir=${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache} guile_site_ccache_dir=${guile_site_ccache_dir-$prefix/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache}
docdir=${moduledir-$prefix/share/doc/mes}
mkdir -p $DESTDIR$prefix/bin mkdir -p $DESTDIR$bindir
cp src/mes $DESTDIR$prefix/bin/mes cp src/mes $DESTDIR$bindir/mes
cp scripts/mescc $DESTDIR$bindir/mescc
mkdir -p $DESTDIR$prefix/lib sed \
mkdir -p $DESTDIR$MES_PREFIX/lib -e "s,^#! /bin/sh,#! $SHELL," \
cp scripts/mescc $DESTDIR$prefix/bin/mescc scripts/diff.scm > $DESTDIR$bindir/diff.scm
chmod -w+x $DESTDIR$bindir/diff.scm
mkdir -p $DESTDIR$MES_PREFIX
tar -cf- doc include lib scaffold | tar -xf- -C $DESTDIR$MES_PREFIX mkdir -p $docdir
cp\
AUTHORS\
BOOTSTRAP\
COPYING\
HACKING\
INSTALL\
NEWS\
README\
$DESTDIR$docdir
if [ -f ${top_builddest}ChangeLog ]; then
cp ${top_builddest}ChangeLog $DESTDIR$docdir
else
cp ChangeLog $DESTDIR$docdir
fi
tar -cf- include lib | tar -xf- -C $DESTDIR$MES_PREFIX
tar -cf- scaffold --exclude='*.gcc*' --exclude='*.mes*' | tar -xf- -C $DESTDIR$MES_PREFIX
tar -cf- --exclude='*.go' module | tar -xf- -C $DESTDIR$MES_PREFIX tar -cf- --exclude='*.go' module | tar -xf- -C $DESTDIR$MES_PREFIX
tar -cf- -C mes module | tar -xf- -C $DESTDIR$MES_PREFIX tar -cf- -C mes module | tar -xf- -C $DESTDIR$MES_PREFIX
@ -41,38 +62,9 @@ mkdir -p $DESTDIR$guile_site_ccache_dir
tar -cf- -C module --exclude='*.go' . | tar -xf- -C $DESTDIR$guile_site_dir tar -cf- -C module --exclude='*.go' . | tar -xf- -C $DESTDIR$guile_site_dir
tar -cf- -C module --exclude='*.scm' . | tar -xf- -C $DESTDIR$guile_site_ccache_dir tar -cf- -C module --exclude='*.scm' . | tar -xf- -C $DESTDIR$guile_site_ccache_dir
chmod +w $DESTDIR$prefix/bin/mescc
sed \
-e "s,^#! /bin/sh,#! $SHELL," \
-e "s,@datadir@,$datadir,g" \
-e "s,@docdir@,$docdir,g" \
-e "s,@guile_site_ccache_dir@,$guile_site_ccache_dir,g" \
-e "s,@guile_site_dir@,$guile_site_dir,g" \
-e "s,@moduledir@,$moduledir,g" \
-e "s,@prefix@,$prefix,g" \
-e "s,@VERSION@,$VERSION,g" \
scripts/mescc > $DESTDIR$prefix/bin/mescc
chmod +w $DESTDIR$moduledir/mes/boot-0.scm
sed \
-e "s,^#! /bin/sh,#! $SHELL," \
-e "s,mes/module/,$moduledir/," \
-e "s,@datadir@,$datadir,g" \
-e "s,@docdir@,$docdir,g" \
-e "s,@guile_site_ccache_dir@,$guile_site_ccache_dir,g" \
-e "s,@guile_site_dir@,$guile_site_dir,g" \
-e "s,@moduledir@,$moduledir,g" \
-e "s,@prefix@,$prefix,g" \
-e "s,@VERSION@,$VERSION,g" \
mes/module/mes/boot-0.scm > $DESTDIR$moduledir/mes/boot-0.scm
sed \
-e "s,^#! /bin/sh,#! $SHELL," \
scripts/diff.scm > $DESTDIR$prefix/bin/diff.scm
chmod -w+x $DESTDIR$prefix/bin/diff.scm
if [ -f doc/mes.info ]; then if [ -f doc/mes.info ]; then
mkdir -p $DESTDIR$prefix/share/info mkdir -p $DESTDIR$prefix/share/info
tar -cf- doc/mes.info* doc/images | tar -xf- --strip-components=1 -C $DESTDIR$prefix/share/info tar -cf- doc/mes.info* doc/images | tar -xf- --strip-components=1 -C $DESTDIR$infodir
install-info --info-dir=$DESTDIR$prefix/share/info doc/mes.info install-info --info-dir=$DESTDIR$prefix/share/info doc/mes.info
fi fi

View file

@ -1,25 +1,18 @@
#! /bin/sh #! @BASH@
# -*-scheme-*- # -*-scheme-*-
if [ -n "$BUILD_DEBUG" ]; then if [ -n "$BUILD_DEBUG" ]; then
set -x set -x
fi fi
prefix=${prefix-@prefix@} prefix=${prefix-@prefix@}
if [ "@prefix@" = @prefix""@ -o ! -d "$prefix/share/mes/module" ]
then
MES_PREFIX=${MES_PREFIX-$(cd $(dirname $0)/.. && pwd)/mes}
else
MES_PREFIX=${MES_PREFIX-$prefix/share/mes} MES_PREFIX=${MES_PREFIX-$prefix/share/mes}
fi
export MES_PREFIX export MES_PREFIX
mes_p=$(command -v mes) mes_p=$(command -v mes)
guile_site_dir=${guile_site_dir-@guile_site_dir@} guile_site_dir=${guile_site_dir-@guile_site_dir@}
[ "$guile_site_dir" = @"guile_site_dir"@ ] && guile_site_dir=$(dirname $0)/../module
GUILE_LOAD_PATH=$guile_site_dir:$GUILE_LOAD_PATH GUILE_LOAD_PATH=$guile_site_dir:$GUILE_LOAD_PATH
if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
guile_site_ccache_dir=${guile_site_ccache_dir-@guile_site_ccache_dir@} guile_site_ccache_dir=${guile_site_ccache_dir-@guile_site_ccache_dir@}
[ "$guile_site_ccache_dir" = @"guile_site_ccache_dir"@ ] && guile_site_ccache_dir=$(dirname $0)/../module
GUILE_LOAD_COMPILED_PATH=$guile_site_ccache_dir:$GUILE_LOAD_COMPILED_PATH GUILE_LOAD_COMPILED_PATH=$guile_site_ccache_dir:$GUILE_LOAD_COMPILED_PATH
GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0} GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
export GUILE_AUTO_COMPILE export GUILE_AUTO_COMPILE