diff --git a/AUTHORS b/AUTHORS index dad7087f..046934ff 100644 --- a/AUTHORS +++ b/AUTHORS @@ -52,8 +52,5 @@ mes/module/srfi/srfi-16.scm Srfi-26 from Guile mes/module/srfi/srfi-26.scm -Sxml bits from Guile -mes/module/sxml/xpath.scm - GNU FDL in texinfo from GNU doc/fdl-1.3.texi diff --git a/GNUmakefile b/GNUmakefile index b3d3fac5..07377307 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,13 +18,19 @@ GUILE_FLAGS:=--no-auto-compile -L . -L module -C . -C module -include .config.make +cleaning_p:=$(filter clean%, $(MAKECMDGOALS)) -.config.make: +ifndef cleaning_p +ifndef config.make +config.make:=.config.make +include $(config.make) +$(config.make): ./configure --prefix=$(prefix) +endif +endif -PHONY_TARGETS:= all all-go build check clean clean-go default doc help install install-info man\ -gcc mes src/mes mes-gcc mes-tcc +PHONY_TARGETS:= all all-go build check clean clean-go default dist doc help install\ +install-info man gcc mes ${top_builddest}src/mes mes-gcc mes-tcc generate-ChangeLog .PHONY: $(PHONY_TARGETS) @@ -64,10 +70,10 @@ clean-go: check: ./check.sh -install: src/mes +install: ${top_builddest}src/mes ./install.sh -.config.make: ./configure +$(config.make): configure seed: all-go mes-gcc mes-tcc ifdef TCC @@ -86,14 +92,15 @@ endif $(MESCC_TOOLS_SEED)/libs cd $(MESCC_TOOLS_SEED) && MES_PREFIX=$(PWD) ./bootstrap.sh -doc/version.texi: doc/mes.texi GNUmakefile +${top_builddest}doc/version.texi: doc/mes.texi GNUmakefile + @mkdir -p $(@D) (set `LANG= date -r $< +'%d %B %Y'`;\ echo "@set UPDATED $$1 $$2 $$3"; \ echo "@set UPDATED-MONTH $$2 $$3"; \ echo "@set EDITION $(VERSION)"; \ echo "@set VERSION $(VERSION)") > $@ -doc: doc/version.texi +doc: ${top_builddest}doc/version.texi ifdef MAKEINFO doc: info else @@ -106,32 +113,66 @@ else $(warning skipping man: no help2man) endif -info: doc/mes.info +info: ${top_builddest}doc/mes.info -doc/mes.info: doc/mes.texi doc/version.texi GNUmakefile - $(MAKEINFO) -o $@ -I doc $< +${top_builddest}doc/mes.info: doc/mes.texi ${top_builddest}doc/version.texi GNUmakefile + $(MAKEINFO) -o $@ -I ${top_builddest}doc -I doc $< install-info: info -man: doc/mes.1 doc/mescc.1 +man: ${top_builddest}doc/mes.1 ${top_builddest}doc/mescc.1 -src/mes: build +${top_builddest}src/mes: build -doc/mes.1: src/mes - MES_ARENA=10000000 ./pre-inst-env $(HELP2MAN) $< > $@ +${top_builddest}doc/mes.1: ${top_builddest}src/mes + MES_ARENA=10000000 ${top_builddir}/pre-inst-env $(HELP2MAN) $( $@ -doc/mescc.1: src/mes scripts/mescc - MES_ARENA=10000000 ./pre-inst-env $(HELP2MAN) $< > $@ +${top_builddest}doc/mescc.1: ${top_builddest}src/mes ${top_builddest}scripts/mescc + MES_ARENA=10000000 ${top_builddir}/pre-inst-env $(HELP2MAN) $( $@ -html: mes/index.html +html: ${top_builddest}mes/index.html -mes/index.html: doc/mes.texi - $(MAKEINFO) --html -o doc/mes $< +${top_builddest}mes/index.html: doc/mes.texi + $(MAKEINFO) --html -o ${top_builddest}doc/mes $< -pdf: doc/mes.pdf +pdf: ${top_builddest}doc/mes.pdf -doc/mes.pdf: doc/mes.texi - $(MAKEINFO) --pdf -o doc/mes.pdf $< +${top_builddest}doc/mes.pdf: doc/mes.texi + $(MAKEINFO) --pdf -I ${top_builddest}/doc -o doc/mes.pdf $< + +### dist +COMMIT=$(shell test -d .git && (git describe --dirty 2>/dev/null) || cat .tarball-version) +TARBALL_VERSION=$(COMMIT:v%=%) +TARBALL_DIR:=$(PACKAGE)-$(TARBALL_VERSION) +TARBALL:=${top_builddest}$(TARBALL_DIR).tar.gz + +${top_builddest}.tarball-version: + echo $(COMMIT) > $@ + +GIT_ARCHIVE_HEAD:=git archive HEAD -- +GIT_LS_FILES:=git ls-files +ifeq ($(wildcard .git),) +GIT_ARCHIVE_HEAD:=tar -cf- +GIT_LS_FILES:=find +endif + +dist: $(TARBALL) + +tree-clean-p: + test ! -d .git || git diff --exit-code > /dev/null + test ! -d .git || git diff --cached --exit-code > /dev/null + @echo commit:$(COMMIT) + +generate-ChangeLog: + $(PERL) build-aux/gitlog-to-changelog --srcdir=${srcdir} > ChangeLog + +$(TARBALL): ${top_builddest}.tarball-version | generate-ChangeLog + ($(GIT_LS_FILES)\ + --exclude=$(TARBALL_DIR);\ + echo $^ | tr ' ' '\n')\ + | GZIP=-n tar --sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner\ + --transform=s,^,$(TARBALL_DIR)/,S -T- -czf $@ + git checkout ChangeLog define HELP_TOP Usage: make [OPTION]... [TARGET]... @@ -139,7 +180,8 @@ Usage: make [OPTION]... [TARGET]... Targets: all update everything all-go update .go files - cc update src/mes.gcc-out + gcc update src/mes.gcc-out + dist update $(TARBALL) doc update documentation mes-gcc update src/mes.mes-gcc-out mes-tcc update src/mes.mes-tcc-out diff --git a/build-aux/GNUmakefile.in b/build-aux/GNUmakefile.in new file mode 100644 index 00000000..4916b99c --- /dev/null +++ b/build-aux/GNUmakefile.in @@ -0,0 +1,30 @@ +# Mes --- Maxwell Equations of Software +# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# +# 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 . + +PHONY_TARGETS:= all all-go build check clean clean-go default dist doc help install\ +install-info man gcc mes src/mes mes-gcc mes-tcc +.PHONY: $(PHONY_TARGETS) + +default: all + +$(PHONY_TARGETS): + $(MAKE) -C $(srcdir) $@ + +include .config.make +config.make:=$(PWD)/.config.make +include $(srcdir)/build-aux/export.make diff --git a/build-aux/build-cc.sh b/build-aux/build-cc.sh index 97f16c0d..1fbbce5d 100755 --- a/build-aux/build-cc.sh +++ b/build-aux/build-cc.sh @@ -20,36 +20,16 @@ set -e -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi +. build-aux/config.sh +. build-aux/trace.sh -export CC CFLAGS CPPFLAGS -export CC_CFLAGS CC_CPPFLAGS - -CC=${CC-gcc} -CC_CFLAGS=${CC_CFLAGS-" ---std=gnu99 --O0 --g -"} - -CC_CPPFLAGS=${CC_CPPFLAGS-" --D VERSION=\"$VERSION\" --D MODULEDIR=\"$moduledir\" --D PREFIX=\"$prefix\" --I src --I lib --I include -"} - -build-aux/mes-snarf.scm src/gc.c -build-aux/mes-snarf.scm src/lib.c -build-aux/mes-snarf.scm src/math.c -build-aux/mes-snarf.scm src/mes.c -build-aux/mes-snarf.scm src/posix.c -build-aux/mes-snarf.scm src/reader.c -build-aux/mes-snarf.scm src/vector.c +trace "SNARF gc.c" build-aux/mes-snarf.scm src/gc.c +trace "SNARF lib.c" build-aux/mes-snarf.scm src/lib.c +trace "SNARF math.c" build-aux/mes-snarf.scm src/math.c +trace "SNARF mes.c" build-aux/mes-snarf.scm src/mes.c +trace "SNARF posix.c" build-aux/mes-snarf.scm src/posix.c +trace "SNARF reader.c" build-aux/mes-snarf.scm src/reader.c +trace "SNARF vector.c" build-aux/mes-snarf.scm src/vector.c ARCHDIR=1 NOLINK=1 sh build-aux/cc.sh lib/libmes sh build-aux/cc.sh src/mes diff --git a/build-aux/build-cc32.sh b/build-aux/build-cc32.sh index 3df24aa9..e4412215 100755 --- a/build-aux/build-cc32.sh +++ b/build-aux/build-cc32.sh @@ -20,56 +20,28 @@ set -e -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi +. build-aux/config.sh +. build-aux/trace.sh -moduledir=${moduledir-${datadir}${datadir:+/}module} -export CC32 TCC CPPFLAGS -export CC32 TCC CC32_CPPFLAGS CC32_CFLAGS +LIBC=${LIBC-c} -CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)} -build-aux/mes-snarf.scm --mes src/gc.c -build-aux/mes-snarf.scm --mes src/lib.c -build-aux/mes-snarf.scm --mes src/math.c -build-aux/mes-snarf.scm --mes src/mes.c -build-aux/mes-snarf.scm --mes src/posix.c -build-aux/mes-snarf.scm --mes src/reader.c -build-aux/mes-snarf.scm --mes src/vector.c +##moduledir=${moduledir-${datadir}${datadir:+/}module} -build-aux/mes-snarf.scm src/gc.c -build-aux/mes-snarf.scm src/lib.c -build-aux/mes-snarf.scm src/math.c -build-aux/mes-snarf.scm src/mes.c -build-aux/mes-snarf.scm src/posix.c -build-aux/mes-snarf.scm src/reader.c -build-aux/mes-snarf.scm src/vector.c +# trace "SNARF gc.c" build-aux/mes-snarf.scm src/gc.c +# trace "SNARF lib.c" build-aux/mes-snarf.scm src/lib.c +# trace "SNARF math.c" build-aux/mes-snarf.scm src/math.c +# trace "SNARF mes.c" build-aux/mes-snarf.scm src/mes.c +# trace "SNARF posix.c" build-aux/mes-snarf.scm src/posix.c +# trace "SNARF reader.c" build-aux/mes-snarf.scm src/reader.c +# trace "SNARF vector.c" build-aux/mes-snarf.scm src/vector.c -CC32_CPPFLAGS=${CC32_CPPFLAGS-" --D VERSION=\"$VERSION\" --D MODULEDIR=\"$moduledir\" --D PREFIX=\"$prefix\" --I src --I lib --I include -"} - -CC32_CFLAGS=${CC32_CFLAGS-" --std=gnu99 --O0 --fno-builtin --fno-stack-protector --g --m32 --nostdinc --nostdlib --Wno-discarded-qualifiers --Wno-int-to-pointer-cast --Wno-pointer-to-int-cast --Wno-pointer-sign --Wno-int-conversion --Wno-incompatible-pointer-types -"} +trace "MSNARF gc.c" build-aux/mes-snarf.scm --mes src/gc.c +trace "MSNARF lib.c" build-aux/mes-snarf.scm --mes src/lib.c +trace "MSNARF math.c" build-aux/mes-snarf.scm --mes src/math.c +trace "MSNARF mes.c" build-aux/mes-snarf.scm --mes src/mes.c +trace "MSNARF posix.c" build-aux/mes-snarf.scm --mes src/posix.c +trace "MSNARF reader.c" build-aux/mes-snarf.scm --mes src/reader.c +trace "MSNARF vector.c" build-aux/mes-snarf.scm --mes src/vector.c ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/linux/crt0 ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/linux/crt1 @@ -83,12 +55,12 @@ ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libtcc1 ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc+gnu ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libg -sh build-aux/cc32-mes.sh scaffold/main -sh build-aux/cc32-mes.sh scaffold/hello -sh build-aux/cc32-mes.sh scaffold/argv -sh build-aux/cc32-mes.sh scaffold/malloc -sh build-aux/cc32-mes.sh scaffold/micro-mes -sh build-aux/cc32-mes.sh scaffold/tiny-mes -sh build-aux/cc32-mes.sh scaffold/mini-mes +# sh build-aux/cc32-mes.sh scaffold/main +# sh build-aux/cc32-mes.sh scaffold/hello +# sh build-aux/cc32-mes.sh scaffold/argv +# sh build-aux/cc32-mes.sh scaffold/malloc +# sh build-aux/cc32-mes.sh scaffold/micro-mes +# sh build-aux/cc32-mes.sh scaffold/tiny-mes +# sh build-aux/cc32-mes.sh scaffold/mini-mes sh build-aux/cc32-mes.sh src/mes diff --git a/build-aux/build-guile.sh b/build-aux/build-guile.sh index b14aa12a..15af30f3 100755 --- a/build-aux/build-guile.sh +++ b/build-aux/build-guile.sh @@ -18,9 +18,7 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -if [ "$V" = 2 ]; then - set -x -fi +. build-aux/trace.sh export GUILE export GUILE_AUTO_COMPILE @@ -58,14 +56,10 @@ if [ "$GUILE_EFFECTIVE_VERSION" = "2.0" ]; then fi GUILE_AUTO_COMPILE=0 -[ -z "$V" -o "$V" = 1 ] && LOG='build.log' || LOG=/dev/stdout for i in $SCM_FILES $SCRIPTS; do - go=${i%%.scm}.go + go=${top_builddest}${i%%.scm}.go if [ $i -nt $go ]; then - [ -z "$V" -o "$V" = 1 ] && echo " GUILEC $i" || true - [ "$V" = 1 ] && set -x - $GUILE_TOOLS compile -L ${abs}module -L ${abs}/build-aux -L ${abs}scripts -o $go $i >>$LOG - { [ "$V" = 1 ] && set +x || true; } > /dev/null 2>&1 + trace "GUILEC $i" $GUILE_TOOLS compile -L ${abs}module -L ${abs}/build-aux -L ${abs}scripts -o $go $i fi done diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index 1461fdc1..5668a1f3 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -18,82 +18,62 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi - -export BLOOD_ELF GUILE HEX2 M1 MES MESCC -export M1FLAGS HEX2FLAGS PREPROCESS -export MES_SEED MES_ARENA +. build-aux/config.sh +. build-aux/trace.sh GUILE=${GUILE-guile} if [ -z "$GUILE" -o "$GUILE" = "true" ] || ! command -v $GUILE > /dev/null; then GUILE=src/mes fi -HEX2=${HEX2-hex2} -M1=${M1-M1} -BLOOD_ELF=${BLOOD_ELF-blood-elf} -MES_SEED=${MES_SEED-../mes-seed} -MESCC=${MESCC-$(command -v mescc)} -[ -z "$MESCC" ] && MESCC=scripts/mescc +[ -z "$MESCC" ] && MESCC=${top_builddest}scripts/mescc MES=${MES-$(command -v mes)} -[ -z "$MES" ] && MES=src/mes +[ -z "$MES" ] && MES=${top_builddest}src/mes set -e -M1FLAGS=${M1FLAGS-" ---LittleEndian ---Architecture 1 -"} -HEX2FLAGS=${HEX2FLAGS-" ---LittleEndian ---Architecture 1 ---BaseAddress 0x1000000 -"} - if [ -d "$MES_SEED" ]; then - $M1\ + trace "M1 crt1.S" $M1\ $M1FLAGS\ -f lib/x86-mes/x86.M1\ -f $MES_SEED/x86-mes/crt1.S\ - -o lib/x86-mes/crt1.o - $M1\ + -o ${top_builddest}lib/x86-mes/crt1.o + trace "M1 libc.S" $M1\ $M1FLAGS\ -f lib/x86-mes/x86.M1\ -f $MES_SEED/x86-mes/libc.S\ - -o lib/x86-mes/libc.o - $M1\ + -o ${top_builddest}lib/x86-mes/libc.o + trace "M1 mes.S" $M1\ --LittleEndian\ --Architecture 1\ -f lib/x86-mes/x86.M1\ -f $MES_SEED/x86-mes/mes.S\ - -o src/mes.o - $BLOOD_ELF\ + -o ${top_builddest}src/mes.o + trace "BLOOD_ELF mes.S" $BLOOD_ELF\ -f lib/x86-mes/x86.M1\ -f $MES_SEED/x86-mes/mes.S\ -f $MES_SEED/x86-mes/libc.S\ - -o src/mes.S.blood-elf - $M1\ + -o ${top_builddest}src/mes.S.blood-elf + trace "M1 mes.blood-elf" $M1\ --LittleEndian\ --Architecture 1\ - -f src/mes.S.blood-elf\ - -o src/mes.o.blood-elf - $HEX2\ + -f ${top_builddest}src/mes.S.blood-elf\ + -o ${top_builddest}src/mes.o.blood-elf + trace "HEX2 mes.o" $HEX2\ $HEX2FLAGS\ -f lib/x86-mes/elf32-header.hex2\ - -f lib/x86-mes/crt1.o\ - -f lib/x86-mes/libc.o\ - -f src/mes.o\ - -f src/mes.o.blood-elf\ + -f ${top_builddest}lib/x86-mes/crt1.o\ + -f ${top_builddest}lib/x86-mes/libc.o\ + -f ${top_builddest}src/mes.o\ + -f ${top_builddest}src/mes.o.blood-elf\ --exec_enable\ - -o src/mes.seed-out - cp src/mes.seed-out src/mes - $M1\ + -o ${top_builddest}src/mes.seed-out + cp ${top_builddest}src/mes.seed-out ${top_builddest}src/mes + trace "M1 libc+tcc.S" $M1\ $M1FLAGS\ -f lib/x86-mes/x86.M1\ -f $MES_SEED/x86-mes/libc+tcc.S\ - -o lib/x86-mes/libc+tcc.o + -o ${top_builddest}lib/x86-mes/libc+tcc.o fi PREPROCESS=1 @@ -118,13 +98,13 @@ ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/libc+gnu [ -n "$SEED" ] && exit 0 MES_ARENA=${MES_ARENA-100000000} -bash build-aux/mes-snarf.scm --mes src/gc.c -bash build-aux/mes-snarf.scm --mes src/lib.c -bash build-aux/mes-snarf.scm --mes src/math.c -bash build-aux/mes-snarf.scm --mes src/mes.c -bash build-aux/mes-snarf.scm --mes src/posix.c -bash build-aux/mes-snarf.scm --mes src/reader.c -bash build-aux/mes-snarf.scm --mes src/vector.c +trace "MSNARF gc.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/gc.c +trace "MSNARF lib.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/lib.c +trace "MSNARF math.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/math.c +trace "MSNARF mes.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/mes.c +trace "MSNARF posix.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/posix.c +trace "MSNARF reader.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/reader.c +trace "MSNARF vector.c" ${top_builddir}/pre-inst-env bash build-aux/mes-snarf.scm --mes src/vector.c echo MES_ARENA=$MES_ARENA bash build-aux/cc-mes.sh scaffold/main @@ -137,4 +117,4 @@ bash build-aux/cc-mes.sh scaffold/malloc ##sh build-aux/cc-mes.sh scaffold/tiny-mes # bash build-aux/cc-mes.sh scaffold/mini-mes bash build-aux/cc-mes.sh src/mes -cp src/mes.mes-out src/mes +cp ${top_builddest}src/mes.mes-out ${top_builddest}src/mes diff --git a/build-aux/cc-mes.sh b/build-aux/cc-mes.sh index 079212f1..5e9bf973 100755 --- a/build-aux/cc-mes.sh +++ b/build-aux/cc-mes.sh @@ -18,33 +18,17 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi +set -e -export BLOOD_ELF GUILE HEX2 M1 MES MESCC -export M1FLAGS HEX2FLAGS PREPROCESS +. build-aux/config.sh +. build-aux/trace.sh -HEX2=${HEX2-hex2} -M1=${M1-M1} -BLOOD_ELF=${BLOOD_ELF-blood-elf} MESCC=${MESCC-$(command -v mescc)} [ -z "$MESCC" ] && MESCC=scripts/mescc MES=${MES-$(command -v mes)} -[ -z "$MES" ] && MES=src/mes +[ -z "$MES" ] && MES=${top_builddest}src/mes -MES_CPPFLAGS=${MES_CPPFLAGS-" --D VERSION=\"$VERSION\" --D MODULEDIR=\"$moduledir\" --D PREFIX=\"$prefix\" --I src --I lib --I include -"} -MES_CCFLAGS=${MES_CCFLAGS-" -"} - -if [ -n "$BUILD_DEBUG" ]; then +if [ "$V" = 2 ]; then MES_CFLAGS="$MES_CFLAGS -v" fi @@ -53,30 +37,31 @@ c=$1 set -e if [ -z "$ARCHDIR" ]; then - o="$c" + o="${top_builddest}$c" + d=${top_builddest}${c%%/*} p="mes-" else b=${c##*/} - d=${c%%/*} - o="$d/x86-mes/$b" - mkdir -p $d/x86-mes + d=${top_builddest}${c%%/*}/x86-mes + o="$d/$b" fi +mkdir -p $d if [ -n "$PREPROCESS" ]; then - ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -E -o "$o.E" "$c".c - ./pre-inst-env bash $MESCC $MES_CFLAGS -S "$o".E - ./pre-inst-env bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S + trace "MESCPP $c.c" ${top_builddir}/pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -E -o "$o.E" "$c".c + trace "MESCC $c.E" ${top_builddir}/pre-inst-env bash $MESCC $MES_CFLAGS -S "$o".E + trace "MESAS $c.S" ${top_builddir}/pre-inst-env bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S if [ -z "$NOLINK" ]; then - ./pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS + trace "MESLD $c.o" ${top_builddir}/pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS fi elif [ -n "$COMPILE" ]; then - ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -S -o "$o.S" "$c".c - ./pre-inst-env bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S + trace "MESCC $c.c" trace "MESCC $c.c" ${top_builddir}/pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -S -o "$o.S" "$c".c + trace "MESAS $c.S" ${top_builddir}/pre-inst-env bash $MESCC $MES_CFLAGS -c -o "$o".${p}o "$o".S if [ -z "$NOLINK" ]; then - ./pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS + trace "MESLD $c.o" ${top_builddir}/pre-inst-env bash $MESCC $MES_CFLAGS -o "$o".${p}out "$o".${p}o $MES_LIBS fi elif [ -z "$NOLINK" ]; then - ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -o "$o".${p}out "$c".c $MES_LIBS + trace "MESLD $c.c" ${top_builddir}/pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -o "$o".${p}out "$c".c $MES_LIBS else - ./pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -c -o "$o".${p}o "$c".c + trace "MESCC $c.c" ${top_builddir}/pre-inst-env bash $MESCC $MES_CPPFLAGS $MES_CFLAGS -c -o "$o".${p}o "$c".c fi diff --git a/build-aux/cc.sh b/build-aux/cc.sh index d0d4eedf..fcd468f3 100755 --- a/build-aux/cc.sh +++ b/build-aux/cc.sh @@ -20,38 +20,23 @@ set -e -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi - -CC_CPPFLAGS=${CC_CPPFLAGS-" --D VERSION=\"$VERSION\" --D MODULEDIR=\"$moduledir\" --D PREFIX=\"$prefix\" --I src --I lib --I include -"} - -CC_CFLAGS=${CC_CFLAGS-" ---std=gnu99 --O0 --g -"} +. build-aux/trace.sh +. build-aux/config.sh c=$1 if [ -z "$ARCHDIR" ]; then - o="$c" + o="${top_builddest}$c" + d=${top_builddest}${c%%/*} p="gcc-" else b=${c##*/} - d=${c%/*} - o="$d/gcc/$b" - mkdir -p $d/gcc + d=${top_builddest}${c%/*}/gcc + o="$d/$b" fi +mkdir -p $d -$CC\ +trace "CC $c.c" $CC\ -c\ $CC_CPPFLAGS\ $CPPFLAGS\ @@ -63,12 +48,12 @@ $CC\ "$c".c if [ -z "$NOLINK" ]; then - $CC\ + trace "CCLD "$o".${p}out" $CC\ $CC_CPPFLAGS\ $CPPFLAGS\ $CC_CFLAGS\ $CFLAGS\ -o "$o".${p}out\ "$o".${p}o\ - lib/gcc/libmes.o + ${top_builddest}lib/gcc/libmes.o fi diff --git a/build-aux/cc32-mes.sh b/build-aux/cc32-mes.sh index 2ac327d9..b51e3791 100755 --- a/build-aux/cc32-mes.sh +++ b/build-aux/cc32-mes.sh @@ -20,30 +20,8 @@ set -e -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi - -CC32_CPPFLAGS=${CC32_CPPFLAGS-" --D VERSION=\"$VERSION\" --D MODULEDIR=\"$moduledir\" --D PREFIX=\"$prefix\" --I src --I lib --I include -"} - -CC32_CFLAGS=${CC32_CFLAGS-" --std=gnu99 --O0 --fno-builtin --fno-stack-protector --g --m32 --nostdinc --nostdlib -"} -LIBC=${LIBC-c} +. build-aux/config.sh +. build-aux/trace.sh a=mes-gcc if [ "$CC32" = "$TCC" ]; then @@ -53,22 +31,23 @@ fi arch=x86-$a if [ -n "$LIBC" ]; then - CC32LIBS="lib/$arch/lib$LIBC.o" + CC32LIBS="${top_builddest}lib/$arch/lib$LIBC.o" fi c=$1 if [ -z "$ARCHDIR" ]; then - o="$c" + o="${top_builddest}$c" + d=${top_builddest}${c%%/*} p="$a-" else b=${c##*/} - d=${c%%/*} - o="$d/$arch/$b" - mkdir -p $d/$arch + d=${top_builddest}${c%%/*}/$arch + o="$d/$b" fi +mkdir -p $d -$CC32\ +trace "CC32 $c.c" $CC32\ -c\ $CC32_CPPFLAGS\ $CC32_CFLAGS\ @@ -76,11 +55,11 @@ $CC32\ "$c".c if [ -z "$NOLINK" ]; then - $CC32\ + trace "CCLD32 $c.c" $CC32\ $CC32_CPPFLAGS\ $CC32_CFLAGS\ -o "$o".${p}out\ - lib/$arch/crt1.o\ + ${top_builddest}lib/$arch/crt1.o\ "$o".${p}o\ $CC32LIBS fi diff --git a/build-aux/check-boot.sh b/build-aux/check-boot.sh index 8d29f43c..d4687ce8 100755 --- a/build-aux/check-boot.sh +++ b/build-aux/check-boot.sh @@ -18,6 +18,10 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . +set -e + +. build-aux/config.sh +. build-aux/trace.sh export GUILE MES MES=${MES-./src/mes} @@ -27,8 +31,6 @@ if ! command -v $GUILE > /dev/null; then GUILE=true fi -set -e - tests=" 00-zero.scm @@ -116,16 +118,18 @@ for i in $tests; do echo ' [SKIP]' continue; fi - $GUILE -L module -C module -L . <(echo '(use-modules (mes guile))'; cat scaffold/boot/$i) >& /dev/null + trace "TEST $i.guile" $GUILE -L module -C ${builddest}/module -L . <(echo '(use-modules (mes guile))'; cat scaffold/boot/$i) x=$( - if [ -z "${i/5[0-9]-*/}" ]; then - cat scaffold/boot/$i | MES_BOOT=boot-00.scm $MES 2>&1; + if [ "$MES" = guile ]; then + true + elif [ -z "${i/5[0-9]-*/}" ]; then + cat scaffold/boot/$i | MES_BOOT=${srcdir}/boot-00.scm $MES 2>&1; elif [ -z "${i/6[0-9]-*/}" ]; then - cat scaffold/boot/$i | MES_BOOT=boot-01.scm $MES 2>&1; + cat scaffold/boot/$i | MES_BOOT=${srcdir}/boot-01.scm $MES 2>&1; else - MES_BOOT=scaffold/boot/$i $MES 2>&1; + MES_BOOT=${srcdir}/scaffold/boot/$i $MES 2>&1; fi ) \ && echo ' [PASS]' \ - || (r=$?; echo ' [FAIL]'; echo -e "$x"; echo scaffold/boot/$i; exit $r) + || (r=$?; echo ' [FAIL]'; echo -e "$x"; echo ${top_builddest}scaffold/boot/$i; exit $r) done diff --git a/build-aux/check-mes.sh b/build-aux/check-mes.sh index 0d5aaffb..c41a30cc 100755 --- a/build-aux/check-mes.sh +++ b/build-aux/check-mes.sh @@ -18,9 +18,10 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -export BASH -export GUILE MES MES_ARENA -export BUILD_DEBUG +set -e + +. build-aux/config.sh +. build-aux/trace.sh if [ "$MES" = guile ]; then mes=guile- @@ -30,8 +31,6 @@ GUILE=${GUILE-guile} MES=${MES-src/mes} MES_ARENA=${MES_ARENA-100000000} -set -e - tests=" tests/boot.test tests/read.test @@ -61,10 +60,7 @@ tests/match.test tests/psyntax.test " -slow_or_broken=" -tests/peg.test -" - +mkdir -p ${top_builddest}tests set +e fail=0 total=0 @@ -73,7 +69,7 @@ for t in $tests; do echo $t: [SKIP]; continue fi - ./pre-inst-env sh "$t" &> $t.${mes}log + ${top_builddir}/pre-inst-env sh "$t" &> ${top_builddest}$t.${mes}log r=$? total=$((total+1)) if [ $r = 0 ]; then diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index 0f9d294a..b7244dad 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -18,18 +18,12 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi - -export BLOOD_ELF GUILE HEX2 M1 MES MESCC -export M1FLAGS HEX2FLAGS PREPROCESS -export MES_ARENA MES_PREFIX MES_SEED -export BUILD_DEBUG -export LIBC CC32LIBS MES_LIBS +set -e +. build-aux/config.sh +. build-aux/trace.sh MES=${MES-src/mes} -MESCC=${MESCC-scripts/mescc} +[ -z "$MESCC" ] && MESCC=${top_builddest}scripts/mescc GUILE=${GUILE-guile} MES_PREFIX=${MES_PREFIX-mes} @@ -38,9 +32,9 @@ M1=${M1-M1} BLOOD_ELF=${BLOOD_ELF-blood-elf} MES_SEED=${MES_SEED-../mes-seed} MESCC=${MESCC-$(command -v mescc)} -[ -z "$MESCC" ] && MESCC=scripts/mescc +[ -z "$MESCC" ] && MESCC=${top_builddest}scripts/mescc MES=${MES-$(command -v mes)} -[ -z "$MES" ] && MES=src/mes +[ -z "$MES" ] && MES=${top_builddest}src/mes if ! command -v $GUILE > /dev/null; then GUILE=true @@ -158,6 +152,7 @@ expect=$(echo $broken | wc -w) pass=0 fail=0 total=0 +mkdir -p ${top_builddest}scaffold/tests for t in $tests; do if [ -z "${t/[012][0-9]-*/}" ]; then LIBC=c-mini @@ -172,7 +167,7 @@ for t in $tests; do LIBC=c MES_LIBS= fi - sh build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log + sh build-aux/test.sh "scaffold/tests/$t" &> ${top_builddest}scaffold/tests/"$t".log r=$? total=$((total+1)) if [ $r = 0 ]; then @@ -278,18 +273,20 @@ broken="$broken #42_function_pointer ; f* functions #49_bracket_evaluation ; float + LIBC=c+gnu MES_LIBS="-l c+gnu" expect=$(echo $broken | wc -w) ARGS="arg1 arg2 arg3 arg4 arg5" export ARGS +mkdir -p ${top_builddest}scaffold/tinycc for t in $tests; do if [ ! -f scaffold/tinycc/"$t.c" ]; then echo ' [SKIP]' continue; fi - sh build-aux/test.sh "scaffold/tinycc/$t" &> scaffold/tinycc/"$t".log + sh build-aux/test.sh "scaffold/tinycc/$t" &> ${top_builddest}scaffold/tinycc/"$t".log r=$? total=$((total+1)) if [ $r = 0 ]; then diff --git a/build-aux/config.sh b/build-aux/config.sh new file mode 100644 index 00000000..b14948e9 --- /dev/null +++ b/build-aux/config.sh @@ -0,0 +1,138 @@ +# GNU Mes --- Maxwell Equations of Software +# Copyright © 2018 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 . + +top_builddir=${top_builddir-.} + +if [ "$V" = 2 ]; then + echo $0 + echo top_builddest=${top_builddest} + echo top_builddir=${top_builddir} +fi + +export CC +export CC CFLAGS +export CC32 +export CC_CFLAGS +export CC_CFLAGS +export CC_CPPFLAGS +export CC_CPPFLAGS +export CFLAGS +export CPPFLAGS +export CPPFLAGS +export GUILE +export HEX2 +export HEX2FLAGS +export LIBC +export M1 +export M1FLAGS +export MES +export MES_CFLAGS +export MES_LIBS +export TCC + +export MES_DEBUG +export MES_SEED +export MES_ARENA +export COMPILE +export PREPROCESS +export V + +export abs_top_builddir +export abs_top_srcdir +export datadir +export moduledir +export prefix +export srcdir +export top_builddest +export top_builddir + +MESCC=${MESCC-mescc} +BLOOD_ELF=${BLOOD_ELF-blood-elf} +HEX2=${HEX2-hex2} +M1=${M1-M1} + +CC_CPPFLAGS=${CC_CPPFLAGS-" +-D 'VERSION=\"$VERSION\"' +-D 'MODULEDIR=\"$moduledir\"' +-D 'PREFIX=\"$prefix\"' +-D boo +-I ${top_builddest}src +-I src +-I lib +-I include +"} + +CC_CFLAGS=${CC_CFLAGS-" +--std=gnu99 +-O0 +-g +"} + +CC32_CPPFLAGS=${CC32_CPPFLAGS-" +-D 'VERSION=\"$VERSION\"' +-D 'MODULEDIR=\"$moduledir\"' +-D 'PREFIX=\"$prefix\"' +-I ${top_builddest}src +-I src +-I lib +-I include +"} + +CC32_CFLAGS=${CC32_CFLAGS-" +-std=gnu99 +-O0 +-fno-builtin +-fno-stack-protector +-g +-m32 +-nostdinc +-nostdlib +-Wno-discarded-qualifiers +-Wno-int-to-pointer-cast +-Wno-pointer-to-int-cast +-Wno-pointer-sign +-Wno-int-conversion +-Wno-incompatible-pointer-types +"} + +MES_CPPFLAGS=${MES_CPPFLAGS-" +-D 'VERSION=\"$VERSION\"' +-D 'MODULEDIR=\"$moduledir\"' +-D 'PREFIX=\"$prefix\"' +-I ${top_builddest}src +-I src +-I lib +-I include +"} + +MES_CFLAGS=${MES_CFLAGS-" +"} + +MES_CFLAGS=${MES_CFLAGS-" +"} + +M1FLAGS=${M1FLAGS-" +--LittleEndian +--Architecture 1 +"} + +HEX2FLAGS=${HEX2FLAGS-" +--LittleEndian +--Architecture 1 +--BaseAddress 0x1000000 +"} diff --git a/build-aux/export.make b/build-aux/export.make index afc0de2b..50f49f75 100644 --- a/build-aux/export.make +++ b/build-aux/export.make @@ -1,5 +1,16 @@ -ifdef BUILD_DEBUG -export BUILD_DEBUG +export PACKAGE +export VERSION + +export abs_top_builddir +export abs_top_srcdir +export top_builddest +export top_builddir +export config.make +export srcdir + + +ifdef V +export V endif ifdef DESTDIR @@ -18,10 +29,6 @@ ifdef mandir export mandir endif -ifdef VERSION -export VERSION -endif - ifdef ARCH export ARCH endif diff --git a/build-aux/mes-snarf.scm b/build-aux/mes-snarf.scm index 7379e16c..ca796499 100755 --- a/build-aux/mes-snarf.scm +++ b/build-aux/mes-snarf.scm @@ -46,7 +46,8 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes (mes-use-module (srfi srfi-9)) (mes-use-module (srfi srfi-26)) -(format (current-error-port) "mes-snarf[~a]...\n" %scheme) +(when (and=> (getenv "V") (lambda (v) (> (string->number v) 1))) + (format (current-error-port) "mes-snarf[~a]...\n" %scheme)) (define (char->char from to char) (if (eq? char from) to char)) @@ -209,7 +210,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes (functions (filter (negate internal?) functions)) (symbols (snarf-symbols string)) (base-name (basename file-name ".c")) - (dir (or (getenv "OUT") (dirname file-name))) + (dir (string-append (or (getenv "top_builddest") "") (dirname file-name))) (base-name (string-append dir "/" base-name)) (base-name (if %gcc? base-name (string-append base-name ".mes"))) @@ -234,6 +235,7 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes (list header source environment symbols.h symbols.i symbol-names.i))) (define (file-write file) + (system* "mkdir" "-p" (dirname (file.name file))) (with-output-to-file (file.name file) (lambda () (display (file.content file))))) (define (main args) diff --git a/build-aux/pre-inst-env.in b/build-aux/pre-inst-env.in index 6ad5835b..7aab6b74 100644 --- a/build-aux/pre-inst-env.in +++ b/build-aux/pre-inst-env.in @@ -1,4 +1,4 @@ -#!/bin/sh +#! @BASH@ # Mes --- Maxwell Equations of Software # Copyright © 2018 Jan (janneke) Nieuwenhuizen @@ -18,19 +18,29 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -abs_top_srcdir="$(cd "@abs_top_srcdir@" > /dev/null; pwd -P)" -abs_top_builddir="$(cd "@abs_top_builddir@" > /dev/null; pwd -P)" +top_builddest="@top_builddest@" +abs_top_srcdir="@abs_top_srcdir@" +abs_top_builddir="@abs_top_builddir@" 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" +if [ -n "$top_builddest" ]; then + GUILE_LOAD_PATH="$abs_top_buildir/module:$GUILE_LOAD_PATH" +fi export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH -PATH="$abs_top_builddir/scripts:$PATH" +PATH="$abs_top_builddir/scripts:$abs_top_builddir/src:$abs_top_builddir/build-aux:$PATH" export PATH +MES=${MES-${top_builddest}src/mes} +export MES + +GUIX_PACKAGE_PATH="$abs_top_srcdir/guix${GUIX_PACKAGE_PATH:+:}$GUIX_PACKAGE_PATH" +export GUIX_PACKAGE_PATH + LANG= LC_ALL= diff --git a/build-aux/test.sh b/build-aux/test.sh index 7845fcc0..2fc590e1 100755 --- a/build-aux/test.sh +++ b/build-aux/test.sh @@ -18,39 +18,38 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi +set -e +. build-aux/config.sh +. build-aux/trace.sh MES_ARENA=100000000 -export LIBC MES_LIBS - GUILE=${GUILE-$MES} DIFF=${DIFF-$(command -v diff)} -[ -z "$DIFF" ] && DIFF="sh scripts/diff.scm" +[ -z "$DIFF" ] && DIFF="sh ${top_builddest}scripts/diff.scm" t=${1-scaffold/tests/t} -rm -f "$t".mes-out +o="${top_builddest}$t" +rm -f "$o".mes-out shift set -e -rm -f "$t".gcc-out +rm -f "$o".gcc-out if [ -n "$CC" ]; then sh build-aux/cc.sh "$t" r=0 [ -f "$t".exit ] && r=$(cat "$t".exit) set +e - "$t".gcc-out $ARGS > "$t".gcc-stdout + "$o".gcc-out $ARGS > "$o".gcc-stdout m=$? - cat "$t".gcc-stdout + cat "$o".gcc-stdout set -e [ $m = $r ] if [ -f "$t".expect ]; then - $DIFF -ub "$t".expect "$t".gcc-stdout; + $DIFF -ub "$t".expect "$o".gcc-stdout; fi fi @@ -61,29 +60,29 @@ if [ -n "$CC32" ]; then r=0 [ -f "$t".exit ] && r=$(cat "$t".exit) set +e - "$t".mes-gcc-out $ARGS > "$t".mes-gcc-stdout + "$o".mes-gcc-out $ARGS > "$o".mes-gcc-stdout m=$? cat "$t".mes-gcc-stdout set -e [ $m = $r ] if [ -f "$t".expect ]; then - $DIFF -ub "$t".expect "$t".mes-gcc-stdout; + $DIFF -ub "$t".expect "$o".mes-gcc-stdout; fi fi -rm -f "$t".mes-out +rm -f "$o".mes-out sh build-aux/cc-mes.sh "$t" r=0 [ -f "$t".exit ] && r=$(cat "$t".exit) set +e -"$t".mes-out $ARGS > "$t".mes-stdout +"$o".mes-out $ARGS > "$o".mes-stdout m=$? -cat "$t".mes-stdout +cat "$o".mes-stdout set -e [ $m = $r ] if [ -f "$t".expect ]; then - $DIFF -ub "$t".expect "$t".mes-stdout; + $DIFF -ub "$t".expect "$o".mes-stdout; fi diff --git a/build-aux/trace.sh b/build-aux/trace.sh new file mode 100644 index 00000000..7c275eac --- /dev/null +++ b/build-aux/trace.sh @@ -0,0 +1,41 @@ +# GNU Mes --- Maxwell Equations of Software +# Copyright © 2018 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 . + +if [ -z "$V" -o "$V0" = 0 ]; then + function trace () { + echo " $1" + shift + eval "$@" $LOG + } + LOG=" >>${top_builddest}build.log 2>&1" +fi +if [ "$V" = 1 ]; then + function trace () { + shift + echo "$@" + eval "$@ $LOG" + } + LOG=" >>${top_builddest}build.log 2>&1" +fi +if [ "$V" = 2 ]; then + set -x + function trace () { + shift + eval "$@" + } +fi diff --git a/build.sh b/build.sh index 1da79e9c..bfb9ec63 100755 --- a/build.sh +++ b/build.sh @@ -18,82 +18,30 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -if [ -n "$BUILD_DEBUG" ]; then - set -x -fi +. build-aux/config.sh +. build-aux/trace.sh -# dash does not export foo=${foo-bar} for some values -export prefix datadir moduledir -export CC CC32 TCC GUILE MESCC MES_SEED -export MES_ARENA MES_DEBUG -export CPPFLAGS CFLAGS C32FLAGS MESCCFLAGS -export BUILD_DEBUG - -CC=${CC-$(command -v gcc)} -CC32=${CC32-$(command -v i686-unknown-linux-gnu-gcc)} -MESCC=${MESCC-$(command -v mescc)} MES_SEED=${MES_SEED-../mes-seed} GUILE=${GUILE-$(command -v guile)} MES_ARENA=${MES_ARENA-100000000} -MES_DEBUG=${MES_DEBUG-1} -prefix=${prefix-/usr/local} -datadir=${datadir-$prefix/share/mes} -moduledir=${moduledir-${datadir}${datadir:+/}module} -set -e - -CC_CPPFLAGS=${CC_CPPFLAGS-" --D VERSION=\"$VERSION\" --D MODULEDIR=\"$moduledir\" --D PREFIX=\"$prefix\" --I src --I lib --I include -"} -CC32_CPPFLAGS=${CC_CPPFLAGS-CC32_CPPFLAGS} -CC_CFLAGS=${CC_CFLAGS-" ---std=gnu99 --O0 --g -"} -CC32_FLAGS=${CC32_FLAGS-" ---std=gnu99 --O0 --fno-stack-protector --g --m32 --nostdinc --nostdlib -"} -MES_CFLAGS=${MES_CFLAGS-" -"} -M1FLAGS=${M1FLAGS-" ---LittleEndian ---Architecture 1 -"} -HEX2FLAGS=${HEX2FLAGS-" ---LittleEndian ---Architecture 1 ---BaseAddress 0x1000000 -"} - -if [ -n "$GUILE" ]; then +if [ -n "$GUILE" -a "$GUILE" != true ]; then sh build-aux/build-guile.sh fi if [ -n "$CC" ]; then sh build-aux/build-cc.sh - cp src/mes.gcc-out src/mes + cp ${top_builddest}src/mes.gcc-out ${top_builddest}src/mes fi if [ -n "$CC32" ]; then sh build-aux/build-cc32.sh - cp src/mes.mes-gcc-out src/mes + cp ${top_builddest}src/mes.mes-gcc-out ${top_builddest}src/mes fi if [ -n "$TCC" ]; then CC32=$TCC sh build-aux/build-cc32.sh - cp src/mes.mes-tcc-out src/mes + cp ${top_builddest}src/mes.mes-tcc-out ${top_builddest}src/mes fi sh build-aux/build-mes.sh diff --git a/check.sh b/check.sh index 75f6d5fd..60df21f7 100755 --- a/check.sh +++ b/check.sh @@ -18,9 +18,10 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see . -export CC32 -export GUILE MES MES_ARENA -export BUILD_DEBUG +set -e + +. build-aux/config.sh +. build-aux/trace.sh GUILE=${GUILE-guile} MES=${MES-src/mes} @@ -33,6 +34,6 @@ fi set -e [ "$GUILE" != true ] && MES=guile bash build-aux/check-mes.sh -bash build-aux/check-mes.sh +[ "$MES" != guile ] && bash build-aux/check-mes.sh bash build-aux/check-boot.sh bash build-aux/check-mescc.sh diff --git a/configure b/configure index 74e2f4b8..48c425d4 100755 --- a/configure +++ b/configure @@ -2,7 +2,8 @@ # -*- scheme -*- unset LANG LC_ALL guile=$(command -v ${GUILE-guile}) -if $(command -v ${GUIX-guix}); then +guix=$(command -v ${GUIX-guix}) +if [ -n "$guix" ] ; then install="guix environment -l guix.scm" else install="sudo apt-get install guile-2.2-dev" @@ -134,7 +135,9 @@ exec ${guile} -L . --no-auto-compile -e '(configure)' -s "$0" ${1+"$@"} (define* (make-dep name #:optional (version '(0)) #:key optional? (version-option "--version") (commands (list name)) file-name) - (make-depedency name version optional? version-option commands file-name)) + (let* ((env-var (getenv (name->shell-name name))) + (commands (if env-var (cons env-var commands) commands))) + (make-depedency name version optional? version-option commands file-name))) (define (find-dep name deps) (find (compose (cut equal? <> name) dependency-name) deps)) @@ -145,7 +148,10 @@ exec ${guile} -L . --no-auto-compile -e '(configure)' -s "$0" ${1+"$@"} (define (variable-name dependency) (and=> (dependency-name dependency) - (compose string-upcase (cut string-replace-char <> #\- #\_)))) + name->shell-name)) + +(define (name->shell-name name) + (string-upcase (string-replace-char name #\- #\_))) (define (version->string version) ((->string '.) version)) @@ -278,16 +284,6 @@ Some influential environment variables: TINYCC_SEED location of tinycc-seed " 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) (let* ((prefix "/usr/local") (infodir "${prefix}/share/info") @@ -296,9 +292,11 @@ Some influential environment variables: (srcdir (dirname (car (command-line)))) (abs-top-srcdir (canonicalize-path srcdir)) - (builddir (getcwd)) - (abs-top-builddir (canonicalize-path builddir)) - + (abs-top-builddir (canonicalize-path (getcwd))) + (top-builddir (if (equal? srcdir ".") "." + abs-top-builddir)) + (top-builddest (if (equal? srcdir ".") "" + (string-append abs-top-builddir "/"))) (options (parse-opts args)) @@ -320,14 +318,20 @@ Some influential environment variables: (disable-silent-rules? (option-ref options 'disable-silent-rules #f)) (vars (filter (cut string-index <> #\=) (option-ref options '() '()))) (help? (option-ref options 'help #f))) + (define (srcdir-relative file-name) + (if (equal? srcdir ".") file-name + (string-append srcdir "/" file-name))) (when help? (print-help) (exit 0)) (set! %verbose? (option-ref options 'verbose #f)) (for-each (lambda (v) (apply setenv (string-split v #\=))) vars) - (let* ((mes-seed (or (getenv "MES_SEED") "../mes-seed")) - (tinycc-seed (or (getenv "TINYCC_SEED") "../tinycc-seed")) - (mescc-tools-seed (or (getenv "MESCC_TOOLS_SEED") "../mescc-tools-seed")) + (let* ((mes-seed (or (getenv "MES_SEED") + (srcdir-relative "../mes-seed"))) + (tinycc-seed (or (getenv "TINYCC_SEED") + (srcdir-relative "../tinycc-seed"))) + (mescc-tools-seed (or (getenv "MESCC_TOOLS_SEED") + (srcdir-relative "../mescc-tools-seed"))) (deps (fold (lambda (program results) (cons (check-program-version program) results)) '() @@ -348,7 +352,7 @@ Some influential environment variables: (make-dep "M1" '(0 3)) (make-dep "blood-elf" '(0 1)) (make-dep "hex2" '(0 3)) - (make-dep "tcc" '(0 9 26) #:optional? #t) + (make-dep "tcc" '(0 9 26) #:optional? #t #:version-option "-v") (make-dep "makeinfo" '(5) #:optional? #t) (make-dep "help2man" '(1 47) #:optional? #t) (make-dep "perl" '(5) #:optional? #t) @@ -365,6 +369,18 @@ Some influential environment variables: deps)) (missing (filter (conjoin (negate dependency-file-name) (negate dependency-optional?)) deps))) + + (define* (substitute file-name pairs + #:key (target (if (string-suffix? ".in" file-name) + (string-drop-right file-name 3) file-name))) + (system* "mkdir" "-p" (dirname 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))))) + (when (and (not (member arch '("i686" "x86_64"))) (not with-courage?)) (stderr "platform not supported: ~a, try --with-courage\n" arch) (exit 1)) @@ -377,7 +393,7 @@ Some influential environment variables: ;; Debian wants to run `make clean' from a tarball (and (zero? (system* "git" "init")) (zero? (system* "git" "add" ".")) - (zero? (system* "git" "commit" "-m" "Import mes"))))) + (zero? (system* "git" "commit" "--allow-empty" "-m" "Import mes"))))) (with-output-to-file ".config.make" (lambda _ (stdout "PACKAGE:=~a\n" PACKAGE) @@ -385,7 +401,12 @@ Some influential environment variables: (stdout "build:=~a\n" build-type) (stdout "host:=~a\n" host-type) - (stdout "srcdir:=.\n") + (stdout "srcdir:=~a\n" srcdir) + (stdout "top_builddest:=~a\n" top-builddest) + (stdout "top_builddir:=~a\n" top-builddir) + (stdout "abs_top_builddir:=~a\n" abs-top-builddir) + (stdout "abs_top_srcdir:=~a\n" abs-top-srcdir) + (stdout "srcdir:=~a\n" srcdir) (stdout "prefix:=~a\n" (gulp-pipe (string-append "echo " prefix))) (stdout "infodir:=~a\n" infodir) (stdout "mandir:=~a\n" mandir) @@ -417,8 +438,11 @@ Some influential environment variables: "MES_CFLAGS" )))) - (let ((pairs `(("@abs_top_srcdir@" . ,abs-top-srcdir) + (let ((pairs `(("@srcdir@" . ,abs-top-srcdir) + ("@abs_top_srcdir@" . ,abs-top-srcdir) ("@abs_top_builddir@" . ,abs-top-builddir) + ("@top_builddir@" . ,top-builddir) + ("@top_builddest@" . ,top-builddest) ("@BASH@" . ,(file-name "bash" deps)) ("@GUILE@" . ,(file-name "guile" deps)) ("@guile_site_dir@" . ,guile-site-dir) @@ -426,20 +450,27 @@ Some influential environment variables: ("@VERSION@" . ,VERSION) ("mes/module/" . ,(string-append moduledir "/"))))) (for-each (lambda (o) - (substitute o pairs) - (chmod (string-drop-right o 3) #o755)) + (let* ((src (srcdir-relative o)) + (target (string-drop-right o 3)) + (target (if (not (string-prefix? "build-aux/" target)) target + (string-drop target (string-length "build-aux/"))))) + (substitute src pairs #:target target))) '( "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") + )) + (when (not (equal? srcdir ".")) + (substitute (string-append srcdir "/build-aux/GNUmakefile.in") + pairs + #:target "GNUmakefile") + (system (string-append "cd mes/module/mes && ln -sf " abs-top-srcdir "/mes/module/mes/*.mes .")))) + (chmod "pre-inst-env" #o755) (chmod "scripts/mescc" #o755) (let ((make (and=> (file-name "make" deps) basename))) (format (current-output-port) - "\nRun: + "\nRun: ~a to build mes ~a help for help on other targets\n" - (or make "./build.sh") - (or make "./build.sh")))))) + (or make "./build.sh") + (or make "./build.sh")))))) diff --git a/configure.sh b/configure.sh new file mode 100755 index 00000000..bcefb121 --- /dev/null +++ b/configure.sh @@ -0,0 +1,100 @@ +#! /bin/sh + +set -e + +VERSION=0.17 + +# parse --prefix=prefix +cmdline=$(echo "$@") +p=${cmdline##*--prefix=} +p=${p% *} +p=${p% -*} +prefix=${p-${prefix}} +if [ -z "$prefix" ]; then + prefix=/usr/local +fi + +. build-aux/trace.sh + +BASH=${BASH-$(command -v bash)} +GUILE=${GUILE-$(command -v guile)} || true + +srcdir=${srcdir-.} +top_builddest=${top_builddest-} +top_builddir=${top_builddest-.} +abs_top_srcdir=${abs_top_srcdir-$PWD} +abs_top_builddir=${abs_top_srcdir-$abs_top_builddir} + +if [ -z "$GUILE" -o "$GUILE" = true ]; then + GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-2.2} +else + GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')} +fi +datadir=${datadir-$prefix/share} +docdir=${docdir-$datadir/doc/mes-$VERSION} +infodir=${infodir-$datadir/info} +mandir=${mandir-$datadir/man} +moduledir=${moduledir-$datadir/mes/module} +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} + +sed \ + -e s,"@srcdir@,$srcdir,"\ + -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\ + -e s,"@abs_top_builddir@,$abs_top_builddir,"\ + -e s,"@top_builddir@,$top_builddir,"\ + -e s,"@top_builddest@,$top_builddest,"\ + -e s,"@BASH@,$BASH,"\ + -e s,"@GUILE@,$GUILE,"\ + -e s,"@guile_site_dir@,$guile_site_dir,"\ + -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\ + -e s,"@VERSION@,$VERSION,"\ + -e s,"mes/module/,$moduledir,"\ + build-aux/pre-inst-env.in\ + > pre-inst-env + +chmod +x pre-inst-env + +sed \ + -e s,"@srcdir@,$srcdir,"\ + -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\ + -e s,"@abs_top_builddir@,$abs_top_builddir,"\ + -e s,"@top_builddir@,$top_builddir,"\ + -e s,"@top_builddest@,$top_builddest,"\ + -e s,"@BASH@,$BASH,"\ + -e s,"@GUILE@,$GUILE,"\ + -e s,"@guile_site_dir@,$guile_site_dir,"\ + -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\ + -e s,"@VERSION@,$VERSION,"\ + -e s,"mes/module/,$moduledir,"\ + mes/module/mes/boot-0.scm.in\ + > mes/module/mes/boot-0.scm + +sed \ + -e s,"@srcdir@,$srcdir,"\ + -e s,"@abs_top_srcdir@,$abs_top_srcdir,"\ + -e s,"@abs_top_builddir@,$abs_top_builddir,"\ + -e s,"@top_builddir@,$top_builddir,"\ + -e s,"@top_builddest@,$top_builddest,"\ + -e s,"@BASH@,$BASH,"\ + -e s,"@GUILE@,$GUILE,"\ + -e s,"@guile_site_dir@,$guile_site_dir,"\ + -e s,"@guile_site_ccache_dir@,$guile_site_ccache_dir,"\ + -e s,"@VERSION@,$VERSION,"\ + -e s,"mes/module/,$moduledir,"\ + scripts/mescc.in\ + > scripts/mescc + +chmod +x scripts/mescc + +if [ "$srcdir" != . ]; then + mkdir -p mes/module/mes + { cd mes/module/mes; ln -sf $abs_top_srcdir/mes/module/mes/*.mes .; } +fi + +cat < $DESTDIR$bindir/diff.scm chmod -w+x $DESTDIR$bindir/diff.scm - mkdir -p $docdir if [ -n "$PERL" -a -n "$GIT" ]\ && $PERL -v > /dev/null\ && $GIT --status > /dev/null; then - $PERL build-aux/gitlog-to-changelog --srcdir=. > ChangeLog + $PERL build-aux/gitlog-to-changelog --srcdir=. > ${top_builddest}ChangeLog fi cp\ AUTHORS\ BOOTSTRAP\ COPYING\ - ChangeLog\ HACKING\ INSTALL\ NEWS\ @@ -60,28 +66,36 @@ else cp ChangeLog $DESTDIR$docdir fi +if [ -f ${top_builddest}ChangeLog ]; then + cp ${top_builddest}ChangeLog $docdir +else + cp ChangeLog $docdir +fi + +mkdir -p $DESTDIR$MES_PREFIX 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- ${top_builddest}lib | 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 mkdir -p $DESTDIR$guile_site_dir 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='*.scm' . | tar -xf- -C $DESTDIR$guile_site_ccache_dir +tar -cf- -C ${top_builddest}module --exclude='*.scm' . | tar -xf- -C $DESTDIR$guile_site_ccache_dir -if [ -f doc/mes.info ]; then - mkdir -p $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 +if [ -f ${top_builddest}doc/mes.info ]; then + mkdir -p $DESTDIR$infodir + tar -cf- ${top_builddest}doc/mes.info* doc/images | tar -xf- --strip-components=1 -C $DESTDIR$infodir + install-info --info-dir=$DESTDIR$infodir ${top_builddest}doc/mes.info fi -if [ -f doc/mes.1 ]; then +if [ -f ${top_builddest}doc/mes.1 ]; then mkdir -p $DESTDIR$mandir/man1 - cp doc/mes.1 $DESTDIR$mandir/man1/ + cp ${top_builddest}doc/mes.1 $DESTDIR$mandir/man1/ fi -if [ -f doc/mescc.1 ]; then +if [ -f ${top_builddest}doc/mescc.1 ]; then mkdir -p $DESTDIR$mandir/man1 - cp doc/mescc.1 $DESTDIR$mandir/man1/ + cp ${top_builddest}doc/mescc.1 $DESTDIR$mandir/man1/ fi diff --git a/mes/module/mes/boot-0.scm.in b/mes/module/mes/boot-0.scm.in index a27566e4..96bf72d7 100644 --- a/mes/module/mes/boot-0.scm.in +++ b/mes/module/mes/boot-0.scm.in @@ -219,7 +219,7 @@ (mes-use-module (mes posix)) (define-macro (include-from-path file) - (let loop ((path (cons* %moduledir "module" (string-split (or (getenv "GUILE_LOAD_PATH")) #\:)))) + (let loop ((path (cons* %moduledir "@srcdir@/module" (string-split (or (getenv "GUILE_LOAD_PATH")) #\:)))) (cond ((and=> (getenv "MES_DEBUG") (compose (lambda (o) (> o 2)) string->number)) (core:display-error (string-append "include-from-path: " file " [PATH:" (string-join path ":") "]\n"))) ((and=> (getenv "MES_DEBUG") (compose (lambda (o) (> o 1)) string->number)) diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index b384b90e..711bac6d 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -212,8 +212,11 @@ (arch-find options (string-append "lib" o ext))) (define* (arch-find options file-name) - (let* ((path (cons (prefix-file options "lib") - (filter-map (multi-opt 'library-dir) options))) + (let* ((top-builddest (or (getenv "top_builddest") "")) + (builddir-lib (string-append top-builddest "lib")) + (path (cons* builddir-lib + (prefix-file options "lib") + (filter-map (multi-opt 'library-dir) options))) (arch-file-name (string-append "x86-mes/" file-name)) (verbose? (option-ref options 'verbose #f))) (when verbose? diff --git a/scripts/mescc.in b/scripts/mescc.in index aa876329..bfeb2e4e 100755 --- a/scripts/mescc.in +++ b/scripts/mescc.in @@ -1,12 +1,13 @@ #! @BASH@ # -*-scheme-*- -if [ -n "$BUILD_DEBUG" ]; then +if [ "$V" = 2 ]; then set -x fi prefix=${prefix-@prefix@} MES_PREFIX=${MES_PREFIX-$prefix/share/mes} export MES_PREFIX mes_p=$(command -v mes) +mescc=$(command -v $0) guile_site_dir=${guile_site_dir-@guile_site_dir@} GUILE_LOAD_PATH=$guile_site_dir:$GUILE_LOAD_PATH @@ -16,10 +17,10 @@ if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile GUILE_LOAD_COMPILED_PATH=$guile_site_ccache_dir:$GUILE_LOAD_COMPILED_PATH GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0} export GUILE_AUTO_COMPILE - exec ${GUILE-guile} -L $guile_site_dir -e '(mescc)' -s "$0" "$@" + exec ${GUILE-guile} -L $guile_site_dir -e '(mescc)' -s "$mescc" "$@" else MES=${MES-$(dirname $0)/mes} - exec ${MES-mes} -e '(mescc)' -s $0 "$@" + exec ${MES-${top_builddest}mes} -e '(mescc)' -s "$mescc" "$@" fi !# @@ -66,7 +67,8 @@ fi (guile (define-macro (mes-use-module . rest) #t))) -(format (current-error-port) "mescc[~a]...\n" %scheme) +(when (and=> (getenv "V") (lambda (v) (> (string->number v) 1))) + (format (current-error-port) "mescc[~a]...\n" %scheme)) (define (parse-opts args) (let* ((option-spec diff --git a/src/mes.c b/src/mes.c index 0eef233a..9059122b 100644 --- a/src/mes.c +++ b/src/mes.c @@ -2268,9 +2268,10 @@ load_env (SCM a) ///((internal)) strcpy (prefix, p); g_stdin = load_boot (prefix, boot, "MODULEDIR"); } - if (g_stdin < 0) + if (g_stdin < 0 && getenv ("top_builddest")) { - strcpy (prefix, "mes/module/mes/"); + strcpy (prefix, getenv ("top_builddest")); + strcpy (prefix + strlen (prefix), "mes/module/mes/"); g_stdin = load_boot (prefix, boot, "."); } if (g_stdin < 0)