diff --git a/.gitignore b/.gitignore index 04fd279..301bb29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.go *~ /bin/gash +/.config.make \ No newline at end of file diff --git a/bin/gash.in b/bin/gash.in index 40b5f04..4321d28 100644 --- a/bin/gash.in +++ b/bin/gash.in @@ -1,5 +1,13 @@ -#!@GUILE@ \ --L . --no-auto-compile -s +#! /bin/sh +# -*-scheme-*- +exec ${GUILE-guile} -L $(pwd)/bin -L $(pwd) -C $(pwd)/bin -C $(pwd) --no-auto-compile -e '(gash)' -s $0 $@ !# -(setenv "SHELL" ((compose canonicalize-path car command-line))) -((@ (gash gash) main) (command-line)) +(define-module (gash) + #:export (main)) + +(set! %load-path (append '("@GUILE_SITE_DIR@") %load-path)) +(set! %load-compiled-path (append '("@GUILE_SITE_CCACHE_DIR@") %load-compiled-path)) + +(define (main args) + (setenv "SHELL" ((compose canonicalize-path car command-line))) + ((@ (gash gash) main) (command-line))) diff --git a/build-aux/build-guile.sh b/build-aux/build-guile.sh new file mode 100755 index 0000000..d499bfc --- /dev/null +++ b/build-aux/build-guile.sh @@ -0,0 +1,68 @@ +#! /bin/sh + +# Gash --- Guile As SHell +# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# +# This file is part of Gash. +# +# Gash 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. +# +# Gash 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 Gash. If not, see . + +if [ -n "$BUILD_DEBUG" ]; then + set -x +fi + +export GUILE +export GUILE_AUTO_COMPILE +export GUILE_LOAD_PATH +export GUILE_LOAD_COMPILED_PATH + +GUILE_LOAD_PATH=$(pwd):$GUILE_LOAD_PATH +GUILE_LOAD_COMPILED_PATH=$(pwd):$GUILE_LOAD_COMPILED_PATH +GUILE=${GUILE-$(command -v guile)} +GUILE_TOOLS=${GUILE_TOOLS-$(command -v guile-tools)} +GUILE_AUTO_COMPILE=0 + +set -e + +SCM_FILES=" +gash/gash.scm +gash/io.scm +gash/job.scm +gash/peg.scm +gash/pipe.scm +gash/util.scm +" + +export srcdir=. +export host=$($GUILE -c "(display %host-type)") + +for i in $SCM_FILES; do + go=${i%%.scm}.go + if [ $i -nt $go ]; then + echo " GUILEC $i" + $GUILE_TOOLS compile -L bin -L gash -o $go $i + fi +done + +SCRIPTS=" +bin/gash +" + +for i in $SCRIPTS; do + go=${i%%.scm}.go + if [ $i -nt $go ]; then + echo " GUILEC $i" + $GUILE_TOOLS compile -L guile -L scripts -o $go $i + fi +done diff --git a/configure b/configure new file mode 100755 index 0000000..5c038d6 --- /dev/null +++ b/configure @@ -0,0 +1,39 @@ +#! /bin/sh + +# parse --prefix=PREFIX, mainly for GuixSD/Debian +cmdline=$(echo "$@") +PREFIX=${cmdline##*--prefix=} +PREFIX=${PREFIX% *} +PREFIX=${PREFIX% -*} +if [ -z "$PREFIX" ]; then + PREFIX=/usr/local +fi + +GUILE=$(command -v guile) +GUILE_TOOLS=$(command -v guile-tools) +GUILE_SITE_DIR=$PREFIX/share/guile/site/$GUILE_EFFECTIVE_VERSION +GUILE_SITE_CCACHE_DIR=$PREFIX/lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache +GUILE_EFFECTIVE_VERSION=$(guile -c '(display (effective-version))') + +sed \ + -e s,@GUILE@,$GUILE,\ + -e s,@GUILE_SITE_DIR@,$GUILE_SITE_DIR,\ + -e s,@GUILE_SITE_CCACHE_DIR@,$GUILE_SITE_CCACHE_DIR,\ + bin/gash.in > bin/gash +chmod +x bin/gash +cat > .config.make < $@ - chmod +x $@ + ./configure --prefix=$(PREFIX) + +all: all-go bin/gash + +all-go: + build-aux/build-guile.sh clean: - rm -f bin/gash + git clean -fdx + +clean-go: + rm -f $(shell find . -name '*.go') + +check: all + echo TODO + +install: all + mkdir -p $(DESTDIR)$(BINDIR) + cp bin/gash $(DESTDIR)$(BINDIR)/gash + mkdir -p $(DESTDIR)$(GUILE_SITE_DIR) + tar -cf- gash/*.scm | tar -C $(DESTDIR)$(GUILE_SITE_DIR) -xf- + mkdir -p $(DESTDIR)$(GUILE_SITE_CCACHE_DIR) + cp bin/gash.go $(DESTDIR)$(GUILE_SITE_CCACHE_DIR) + tar -cf- gash/*.go | tar -C $(DESTDIR)$(GUILE_SITE_CCACHE_DIR) -xf- + mkdir -p $(DESTDIR)$(DOCDIR) + cp -f COPYING README TODO $(DOCDIR) + +define HELP_TOP +Usage: make [OPTION]... [TARGET]... + +Targets: + all update everything + all-go update .go files + clean run git clean -dfx + clean-go clean .go files + install install in $(PREFIX) +endef +export HELP_TOP +help: + @echo "$$HELP_TOP" + +export GUILE +export GUILE_TOOLS +export GUILE_LOAD_PATH +export GUILE_LOAD_COMPILED_PATH +