| 1 | #!/bin/sh |
| 2 | |
| 3 | # GNU Guix --- Functional package management for GNU |
| 4 | # Copyright © 2012, 2013, 2014, 2015, 2017, 2018, 2019, 2020 Ludovic Courtès <[email protected]> |
| 5 | # Copyright © 2017 Eric Bavier <[email protected]> |
| 6 | # |
| 7 | # This file is part of GNU Guix. |
| 8 | # |
| 9 | # GNU Guix is free software; you can redistribute it and/or modify it |
| 10 | # under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; either version 3 of the License, or (at |
| 12 | # your option) any later version. |
| 13 | # |
| 14 | # GNU Guix is distributed in the hope that it will be useful, but |
| 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | # Usage: ./pre-inst-env COMMAND ARG... |
| 23 | # |
| 24 | # Run COMMAND in a pre-installation environment. Typical use is |
| 25 | # "./pre-inst-env guix build hello". |
| 26 | |
| 27 | # By default we may end up with absolute directory names that contain '..', |
| 28 | # which get into $GUILE_LOAD_PATH, leading to '..' in the module file names |
| 29 | # recorded by Guile. To avoid that, make sure we get a real absolute |
| 30 | # directory name. Additionally, use '-P' to get the canonical directory name |
| 31 | # so that Guile's 'relative' %file-port-name-canonicalization can actually |
| 32 | # work (see <http://bugs.gnu.org/17935>.) |
| 33 | abs_top_srcdir="`cd "@abs_top_srcdir@" > /dev/null; pwd -P`" |
| 34 | abs_top_builddir="`cd "@abs_top_builddir@" > /dev/null; pwd -P`" |
| 35 | |
| 36 | GUILE_LOAD_COMPILED_PATH="$abs_top_builddir${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH" |
| 37 | GUILE_LOAD_PATH="$abs_top_builddir:$abs_top_srcdir${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH" |
| 38 | export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH |
| 39 | |
| 40 | # Define $PATH so that `guix' and friends are easily found. |
| 41 | |
| 42 | PATH="$abs_top_builddir/scripts:$abs_top_builddir:$PATH" |
| 43 | export PATH |
| 44 | |
| 45 | # The daemon invokes 'guix'; tell it which one to use. |
| 46 | GUIX="$abs_top_builddir/scripts/guix" |
| 47 | export GUIX |
| 48 | |
| 49 | # Sanity check. |
| 50 | if [ "$1" = "guix" ] && [ ! -f "$GUIX" ]; then |
| 51 | echo "$GUIX is not built. Please run 'make scripts/guix'." |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | # Define $GUIX_UNINSTALLED to prevent `guix' from |
| 56 | # prepending @guilemoduledir@ to the Guile load paths. |
| 57 | |
| 58 | GUIX_UNINSTALLED=1 |
| 59 | export GUIX_UNINSTALLED |
| 60 | |
| 61 | exec "$@" |