2013-01-05 16:08:07 +01:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2014-02-22 00:34:49 +01:00
|
|
|
|
;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
|
2012-06-13 17:03:34 +02:00
|
|
|
|
;;;
|
2013-01-05 16:08:07 +01:00
|
|
|
|
;;; This file is part of GNU Guix.
|
2012-06-13 17:03:34 +02:00
|
|
|
|
;;;
|
2013-01-05 16:08:07 +01:00
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
2012-06-13 17:03:34 +02:00
|
|
|
|
;;; 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.
|
|
|
|
|
;;;
|
2013-01-05 16:08:07 +01:00
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
2012-06-13 17:03:34 +02:00
|
|
|
|
;;; 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
|
2013-01-05 16:08:07 +01:00
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
2012-06-13 17:03:34 +02:00
|
|
|
|
|
|
|
|
|
(define-module (guix build gnu-build-system)
|
|
|
|
|
#:use-module (guix build utils)
|
|
|
|
|
#:use-module (ice-9 ftw)
|
2012-06-16 16:56:47 +02:00
|
|
|
|
#:use-module (ice-9 match)
|
2012-12-20 22:31:08 +01:00
|
|
|
|
#:use-module (ice-9 format)
|
2012-06-16 16:56:47 +02:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2012-08-19 17:54:54 +02:00
|
|
|
|
#:use-module (srfi srfi-26)
|
2012-06-16 16:56:47 +02:00
|
|
|
|
#:export (%standard-phases
|
|
|
|
|
gnu-build))
|
2012-06-13 17:03:34 +02:00
|
|
|
|
|
|
|
|
|
;; Commentary:
|
|
|
|
|
;;
|
|
|
|
|
;; Standard build procedure for packages using the GNU Build System or
|
|
|
|
|
;; something compatible ("./configure && make && make install"). This is the
|
|
|
|
|
;; builder-side code.
|
|
|
|
|
;;
|
|
|
|
|
;; Code:
|
|
|
|
|
|
|
|
|
|
(define (first-subdirectory dir)
|
|
|
|
|
"Return the path of the first sub-directory of DIR."
|
|
|
|
|
(file-system-fold (lambda (path stat result)
|
|
|
|
|
(string=? path dir))
|
|
|
|
|
(lambda (path stat result) result) ; leaf
|
|
|
|
|
(lambda (path stat result) result) ; down
|
|
|
|
|
(lambda (path stat result) result) ; up
|
|
|
|
|
(lambda (path stat result) ; skip
|
|
|
|
|
(or result path))
|
|
|
|
|
(lambda (path stat errno result) ; error
|
|
|
|
|
(error "first-subdirectory" (strerror errno)))
|
|
|
|
|
#f
|
|
|
|
|
dir))
|
|
|
|
|
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(define* (set-paths #:key target inputs native-inputs
|
|
|
|
|
(search-paths '()) (native-search-paths '())
|
2012-09-01 01:14:31 +02:00
|
|
|
|
#:allow-other-keys)
|
2013-03-30 11:31:50 +01:00
|
|
|
|
(define input-directories
|
|
|
|
|
(match inputs
|
|
|
|
|
(((_ . dir) ...)
|
|
|
|
|
dir)))
|
2012-07-06 00:50:07 +02:00
|
|
|
|
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(define native-input-directories
|
|
|
|
|
(match native-inputs
|
|
|
|
|
(((_ . dir) ...)
|
|
|
|
|
dir)
|
|
|
|
|
(#f ; not cross compiling
|
|
|
|
|
'())))
|
|
|
|
|
|
|
|
|
|
;; When cross building, $PATH must refer only to native (host) inputs since
|
|
|
|
|
;; target inputs are not executable.
|
2013-03-30 22:56:38 +01:00
|
|
|
|
(set-path-environment-variable "PATH" '("bin" "sbin")
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(append native-input-directories
|
|
|
|
|
(if target
|
|
|
|
|
'()
|
|
|
|
|
input-directories)))
|
2012-07-07 18:40:39 +02:00
|
|
|
|
|
2013-03-30 22:56:38 +01:00
|
|
|
|
(for-each (match-lambda
|
|
|
|
|
((env-var (directories ...) separator)
|
|
|
|
|
(set-path-environment-variable env-var directories
|
|
|
|
|
input-directories
|
|
|
|
|
#:separator separator)))
|
|
|
|
|
search-paths)
|
2012-09-06 22:58:43 +02:00
|
|
|
|
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(when native-search-paths
|
|
|
|
|
;; Search paths for native inputs, when cross building.
|
|
|
|
|
(for-each (match-lambda
|
|
|
|
|
((env-var (directories ...) separator)
|
|
|
|
|
(set-path-environment-variable env-var directories
|
|
|
|
|
native-input-directories
|
|
|
|
|
#:separator separator)))
|
|
|
|
|
native-search-paths))
|
|
|
|
|
|
2013-06-21 00:32:07 +02:00
|
|
|
|
#t)
|
2012-06-13 17:03:34 +02:00
|
|
|
|
|
2012-06-16 16:56:47 +02:00
|
|
|
|
(define* (unpack #:key source #:allow-other-keys)
|
2014-02-22 00:34:49 +01:00
|
|
|
|
"Unpack SOURCE in the working directory, and change directory within the
|
|
|
|
|
source. When SOURCE is a directory, copy it in a sub-directory of the current
|
|
|
|
|
working directory."
|
|
|
|
|
(if (file-is-directory? source)
|
|
|
|
|
(begin
|
|
|
|
|
(mkdir "source")
|
|
|
|
|
(chdir "source")
|
|
|
|
|
(copy-recursively source ".")
|
|
|
|
|
#t)
|
|
|
|
|
(and (zero? (system* "tar" "xvf" source))
|
|
|
|
|
(chdir (first-subdirectory ".")))))
|
2012-06-16 16:56:47 +02:00
|
|
|
|
|
2012-12-15 16:35:26 +01:00
|
|
|
|
(define* (patch-source-shebangs #:key source #:allow-other-keys)
|
2012-12-21 22:31:25 +01:00
|
|
|
|
"Patch shebangs in all source files; this includes non-executable
|
|
|
|
|
files such as `.in' templates. Most scripts honor $SHELL and
|
|
|
|
|
$CONFIG_SHELL, but some don't, such as `mkinstalldirs' or Automake's
|
|
|
|
|
`missing' script."
|
|
|
|
|
(for-each patch-shebang
|
|
|
|
|
(remove file-is-directory? (find-files "." ".*"))))
|
|
|
|
|
|
|
|
|
|
(define (patch-generated-file-shebangs . rest)
|
|
|
|
|
"Patch shebangs in generated files, including `SHELL' variables in
|
|
|
|
|
makefiles."
|
|
|
|
|
;; Patch executable files, some of which might have been generated by
|
|
|
|
|
;; `configure'.
|
2012-12-15 16:35:26 +01:00
|
|
|
|
(for-each patch-shebang
|
|
|
|
|
(filter (lambda (file)
|
|
|
|
|
(and (executable-file? file)
|
|
|
|
|
(not (file-is-directory? file))))
|
|
|
|
|
(find-files "." ".*")))
|
|
|
|
|
|
2012-12-21 22:31:25 +01:00
|
|
|
|
;; Patch `SHELL' in generated makefiles.
|
|
|
|
|
(for-each patch-makefile-SHELL (find-files "." "^(GNU)?[mM]akefile$")))
|
2012-12-20 23:06:34 +01:00
|
|
|
|
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(define* (configure #:key target native-inputs inputs outputs
|
|
|
|
|
(configure-flags '()) out-of-source?
|
2012-08-23 23:13:41 +02:00
|
|
|
|
#:allow-other-keys)
|
2013-01-10 00:08:40 +01:00
|
|
|
|
(define (package-name)
|
|
|
|
|
(let* ((out (assoc-ref outputs "out"))
|
|
|
|
|
(base (basename out))
|
|
|
|
|
(dash (string-rindex base #\-)))
|
|
|
|
|
;; XXX: We'd rather use `package-name->name+version' or similar.
|
2013-04-27 17:27:16 +02:00
|
|
|
|
(string-drop (if dash
|
|
|
|
|
(substring base 0 dash)
|
|
|
|
|
base)
|
|
|
|
|
(+ 1 (string-index base #\-)))))
|
2013-01-10 00:08:40 +01:00
|
|
|
|
|
2012-07-01 17:32:03 +02:00
|
|
|
|
(let* ((prefix (assoc-ref outputs "out"))
|
2013-01-01 16:52:27 +01:00
|
|
|
|
(bindir (assoc-ref outputs "bin"))
|
2012-07-01 17:32:03 +02:00
|
|
|
|
(libdir (assoc-ref outputs "lib"))
|
|
|
|
|
(includedir (assoc-ref outputs "include"))
|
2013-01-10 00:08:40 +01:00
|
|
|
|
(docdir (assoc-ref outputs "doc"))
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(bash (or (and=> (assoc-ref (or native-inputs inputs) "bash")
|
2012-12-13 23:38:32 +01:00
|
|
|
|
(cut string-append <> "/bin/bash"))
|
|
|
|
|
"/bin/sh"))
|
2013-12-17 20:33:26 +01:00
|
|
|
|
(flags `(,@(if target ; cross building
|
|
|
|
|
'("CC_FOR_BUILD=gcc")
|
|
|
|
|
'())
|
|
|
|
|
,(string-append "CONFIG_SHELL=" bash)
|
2012-12-13 23:38:32 +01:00
|
|
|
|
,(string-append "SHELL=" bash)
|
|
|
|
|
,(string-append "--prefix=" prefix)
|
2012-07-01 17:32:03 +02:00
|
|
|
|
"--enable-fast-install" ; when using Libtool
|
|
|
|
|
|
|
|
|
|
;; Produce multiple outputs when specific output names
|
|
|
|
|
;; are recognized.
|
2013-01-01 16:52:27 +01:00
|
|
|
|
,@(if bindir
|
|
|
|
|
(list (string-append "--bindir=" bindir "/bin"))
|
|
|
|
|
'())
|
2012-07-01 17:32:03 +02:00
|
|
|
|
,@(if libdir
|
2013-01-10 00:08:40 +01:00
|
|
|
|
(cons (string-append "--libdir=" libdir "/lib")
|
|
|
|
|
(if includedir
|
|
|
|
|
'()
|
|
|
|
|
(list
|
|
|
|
|
(string-append "--includedir="
|
|
|
|
|
libdir "/include"))))
|
2012-07-01 17:32:03 +02:00
|
|
|
|
'())
|
|
|
|
|
,@(if includedir
|
|
|
|
|
(list (string-append "--includedir="
|
|
|
|
|
includedir "/include"))
|
|
|
|
|
'())
|
2013-01-10 00:08:40 +01:00
|
|
|
|
,@(if docdir
|
|
|
|
|
(list (string-append "--docdir=" docdir
|
2014-02-10 21:35:30 +01:00
|
|
|
|
"/share/doc/" (package-name)))
|
2013-01-10 00:08:40 +01:00
|
|
|
|
'())
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
,@(if target ; cross building
|
|
|
|
|
(list (string-append "--host=" target))
|
|
|
|
|
'())
|
2012-08-23 23:13:41 +02:00
|
|
|
|
,@configure-flags))
|
2012-08-30 23:30:42 +02:00
|
|
|
|
(abs-srcdir (getcwd))
|
|
|
|
|
(srcdir (if out-of-source?
|
|
|
|
|
(string-append "../" (basename abs-srcdir))
|
|
|
|
|
".")))
|
|
|
|
|
(format #t "source directory: ~s (relative from build: ~s)~%"
|
|
|
|
|
abs-srcdir srcdir)
|
2012-08-23 23:13:41 +02:00
|
|
|
|
(if out-of-source?
|
|
|
|
|
(begin
|
|
|
|
|
(mkdir "../build")
|
|
|
|
|
(chdir "../build")))
|
|
|
|
|
(format #t "build directory: ~s~%" (getcwd))
|
2012-07-01 17:32:03 +02:00
|
|
|
|
(format #t "configure flags: ~s~%" flags)
|
2012-08-30 23:30:42 +02:00
|
|
|
|
|
2012-12-13 23:38:32 +01:00
|
|
|
|
;; Use BASH to reduce reliance on /bin/sh since it may not always be
|
|
|
|
|
;; reliable (see
|
|
|
|
|
;; <http://thread.gmane.org/gmane.linux.distributions.nixos/9748>
|
|
|
|
|
;; for a summary of the situation.)
|
|
|
|
|
;;
|
2012-08-30 23:30:42 +02:00
|
|
|
|
;; Call `configure' with a relative path. Otherwise, GCC's build system
|
|
|
|
|
;; (for instance) records absolute source file names, which typically
|
|
|
|
|
;; contain the hash part of the `.drv' file, leading to a reference leak.
|
2012-12-13 23:38:32 +01:00
|
|
|
|
(zero? (apply system* bash
|
2012-08-30 23:30:42 +02:00
|
|
|
|
(string-append srcdir "/configure")
|
2012-08-23 23:13:41 +02:00
|
|
|
|
flags))))
|
2012-06-13 17:03:34 +02:00
|
|
|
|
|
2012-10-05 23:21:09 +02:00
|
|
|
|
(define %parallel-job-count
|
|
|
|
|
;; String to be passed next to GNU Make's `-j' argument.
|
|
|
|
|
(match (getenv "NIX_BUILD_CORES")
|
|
|
|
|
(#f "1")
|
|
|
|
|
("0" (number->string (current-processor-count)))
|
|
|
|
|
(x x)))
|
|
|
|
|
|
2012-07-07 16:49:23 +02:00
|
|
|
|
(define* (build #:key (make-flags '()) (parallel-build? #t)
|
|
|
|
|
#:allow-other-keys)
|
|
|
|
|
(zero? (apply system* "make"
|
|
|
|
|
`(,@(if parallel-build?
|
2012-10-05 23:21:09 +02:00
|
|
|
|
`("-j" ,%parallel-job-count)
|
2012-07-07 16:49:23 +02:00
|
|
|
|
'())
|
|
|
|
|
,@make-flags))))
|
2012-06-16 16:56:47 +02:00
|
|
|
|
|
2013-06-22 16:15:23 +02:00
|
|
|
|
(define* (check #:key target (make-flags '()) (tests? (not target))
|
|
|
|
|
(test-target "check") (parallel-tests? #t)
|
2012-07-01 17:32:03 +02:00
|
|
|
|
#:allow-other-keys)
|
|
|
|
|
(if tests?
|
2012-07-07 16:49:23 +02:00
|
|
|
|
(zero? (apply system* "make" test-target
|
|
|
|
|
`(,@(if parallel-tests?
|
2012-10-05 23:21:09 +02:00
|
|
|
|
`("-j" ,%parallel-job-count)
|
2012-07-07 16:49:23 +02:00
|
|
|
|
'())
|
|
|
|
|
,@make-flags)))
|
2012-07-01 17:32:03 +02:00
|
|
|
|
(begin
|
|
|
|
|
(format #t "test suite not run~%")
|
|
|
|
|
#t)))
|
2012-06-16 16:56:47 +02:00
|
|
|
|
|
|
|
|
|
(define* (install #:key (make-flags '()) #:allow-other-keys)
|
|
|
|
|
(zero? (apply system* "make" "install" make-flags)))
|
|
|
|
|
|
2012-08-19 17:54:54 +02:00
|
|
|
|
(define* (patch-shebangs #:key outputs (patch-shebangs? #t)
|
|
|
|
|
#:allow-other-keys)
|
|
|
|
|
(define (list-of-files dir)
|
|
|
|
|
(map (cut string-append dir "/" <>)
|
|
|
|
|
(or (scandir dir (lambda (f)
|
|
|
|
|
(let ((s (stat (string-append dir "/" f))))
|
|
|
|
|
(eq? 'regular (stat:type s)))))
|
|
|
|
|
'())))
|
|
|
|
|
|
|
|
|
|
(define bindirs
|
|
|
|
|
(append-map (match-lambda
|
|
|
|
|
((_ . dir)
|
|
|
|
|
(list (string-append dir "/bin")
|
|
|
|
|
(string-append dir "/sbin"))))
|
|
|
|
|
outputs))
|
|
|
|
|
|
2012-08-31 23:58:21 +02:00
|
|
|
|
(when patch-shebangs?
|
|
|
|
|
(let ((path (append bindirs
|
|
|
|
|
(search-path-as-string->list (getenv "PATH")))))
|
|
|
|
|
(for-each (lambda (dir)
|
|
|
|
|
(let ((files (list-of-files dir)))
|
|
|
|
|
(for-each (cut patch-shebang <> path) files)))
|
|
|
|
|
bindirs)))
|
|
|
|
|
#t)
|
2012-08-19 17:54:54 +02:00
|
|
|
|
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(define* (strip #:key target outputs (strip-binaries? #t)
|
|
|
|
|
(strip-command (if target
|
|
|
|
|
(string-append target "-strip")
|
|
|
|
|
"strip"))
|
2013-07-03 23:53:31 +02:00
|
|
|
|
(objcopy-command (if target
|
|
|
|
|
(string-append target "-objcopy")
|
|
|
|
|
"objcopy"))
|
2012-08-31 17:04:53 +02:00
|
|
|
|
(strip-flags '("--strip-debug"))
|
|
|
|
|
(strip-directories '("lib" "lib64" "libexec"
|
|
|
|
|
"bin" "sbin"))
|
|
|
|
|
#:allow-other-keys)
|
2013-07-03 23:53:31 +02:00
|
|
|
|
(define debug-output
|
|
|
|
|
;; If an output is called "debug", then that's where debugging information
|
|
|
|
|
;; will be stored instead of being discarded.
|
|
|
|
|
(assoc-ref outputs "debug"))
|
|
|
|
|
|
|
|
|
|
(define debug-file-extension
|
|
|
|
|
;; File name extension for debugging information.
|
|
|
|
|
".debug")
|
|
|
|
|
|
|
|
|
|
(define (debug-file file)
|
|
|
|
|
;; Return the name of the debug file for FILE, an absolute file name.
|
|
|
|
|
;; Once installed in the user's profile, it is in $PROFILE/lib/debug/FILE,
|
|
|
|
|
;; which is where GDB looks for it (info "(gdb) Separate Debug Files").
|
|
|
|
|
(string-append debug-output "/lib/debug/"
|
|
|
|
|
file debug-file-extension))
|
|
|
|
|
|
|
|
|
|
(define (make-debug-file file)
|
|
|
|
|
;; Create a file in DEBUG-OUTPUT containing the debugging info of FILE.
|
|
|
|
|
(let ((debug (debug-file file)))
|
|
|
|
|
(mkdir-p (dirname debug))
|
|
|
|
|
(copy-file file debug)
|
|
|
|
|
(and (zero? (system* strip-command "--only-keep-debug" debug))
|
|
|
|
|
(begin
|
|
|
|
|
(chmod debug #o400)
|
|
|
|
|
#t))))
|
|
|
|
|
|
|
|
|
|
(define (add-debug-link file)
|
|
|
|
|
;; Add a debug link in FILE (info "(binutils) strip").
|
|
|
|
|
|
|
|
|
|
;; `objcopy --add-gnu-debuglink' wants to have the target of the debug
|
|
|
|
|
;; link around so it can compute a CRC of that file (see the
|
|
|
|
|
;; `bfd_fill_in_gnu_debuglink_section' function.) No reference to
|
|
|
|
|
;; DEBUG-OUTPUT is kept because bfd keeps only the basename of the debug
|
|
|
|
|
;; file.
|
|
|
|
|
(zero? (system* objcopy-command
|
|
|
|
|
(string-append "--add-gnu-debuglink="
|
|
|
|
|
(debug-file file))
|
|
|
|
|
file)))
|
|
|
|
|
|
2012-08-31 17:04:53 +02:00
|
|
|
|
(define (strip-dir dir)
|
build-system/gnu: Unify with (guix build-system gnu-cross-build).
* guix/build/gnu-build-system.scm (set-paths): Add `native-inputs' and
`native-search-paths' keyword parameters. Honor them.
(configure): Add `target' and `native-inputs' keyword parameters.
Look for Bash in NATIVE-INPUTS or INPUTS. Pass `--host' when TARGET
is true.
(strip): Add `strip-command' keyword parameter. Use it.
* guix/build/gnu-cross-build.scm: Remove.
* Makefile.am (MODULES): Adjust accordingly.
* gnu/packages/acl.scm, gnu/packages/attr.scm, gnu/packages/base.scm,
gnu/packages/bash.scm, gnu/packages/gawk.scm,
gnu/packages/gettext.scm, gnu/packages/guile.scm,
gnu/packages/libffi.scm, gnu/packages/libsigsegv.scm,
gnu/packages/linux.scm, gnu/packages/ncurses.scm,
gnu/packages/readline.scm, guix/build-system/gnu.scm: Replace
`%standard-cross-phases' by `%standard-phases'. Remove references
to (guix build gnu-cross-build).
2013-06-21 00:25:54 +02:00
|
|
|
|
(format #t "stripping binaries in ~s with ~s and flags ~s~%"
|
|
|
|
|
dir strip-command strip-flags)
|
2013-07-03 23:53:31 +02:00
|
|
|
|
(when debug-output
|
|
|
|
|
(format #t "debugging output written to ~s using ~s~%"
|
|
|
|
|
debug-output objcopy-command))
|
2012-08-31 17:04:53 +02:00
|
|
|
|
(file-system-fold (const #t)
|
|
|
|
|
(lambda (path stat result) ; leaf
|
2013-07-03 23:53:31 +02:00
|
|
|
|
(and (or (not debug-output)
|
|
|
|
|
(make-debug-file path))
|
|
|
|
|
(zero? (apply system* strip-command
|
|
|
|
|
(append strip-flags (list path))))
|
|
|
|
|
(or (not debug-output)
|
|
|
|
|
(add-debug-link path))))
|
2012-08-31 17:04:53 +02:00
|
|
|
|
(const #t) ; down
|
|
|
|
|
(const #t) ; up
|
|
|
|
|
(const #t) ; skip
|
|
|
|
|
(lambda (path stat errno result)
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"strip: failed to access `~a': ~a~%"
|
|
|
|
|
path (strerror errno))
|
|
|
|
|
#f)
|
|
|
|
|
#t
|
|
|
|
|
dir))
|
|
|
|
|
|
2012-08-31 23:58:21 +02:00
|
|
|
|
(or (not strip-binaries?)
|
|
|
|
|
(every strip-dir
|
|
|
|
|
(append-map (match-lambda
|
|
|
|
|
((_ . dir)
|
|
|
|
|
(filter-map (lambda (d)
|
|
|
|
|
(let ((sub (string-append dir "/" d)))
|
|
|
|
|
(and (directory-exists? sub) sub)))
|
|
|
|
|
strip-directories)))
|
|
|
|
|
outputs))))
|
2012-08-31 17:04:53 +02:00
|
|
|
|
|
2012-06-16 16:56:47 +02:00
|
|
|
|
(define %standard-phases
|
|
|
|
|
;; Standard build phases, as a list of symbol/procedure pairs.
|
|
|
|
|
(let-syntax ((phases (syntax-rules ()
|
|
|
|
|
((_ p ...) `((p . ,p) ...)))))
|
2013-10-10 23:15:57 +02:00
|
|
|
|
(phases set-paths unpack
|
2012-12-21 22:31:25 +01:00
|
|
|
|
patch-source-shebangs configure patch-generated-file-shebangs
|
2012-12-15 16:35:26 +01:00
|
|
|
|
build check install
|
2012-08-31 17:04:53 +02:00
|
|
|
|
patch-shebangs strip)))
|
2012-06-16 16:56:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define* (gnu-build #:key (source #f) (outputs #f) (inputs #f)
|
|
|
|
|
(phases %standard-phases)
|
|
|
|
|
#:allow-other-keys
|
|
|
|
|
#:rest args)
|
|
|
|
|
"Build from SOURCE to OUTPUTS, using INPUTS, and by running all of PHASES
|
|
|
|
|
in order. Return #t if all the PHASES succeeded, #f otherwise."
|
|
|
|
|
(setvbuf (current-output-port) _IOLBF)
|
2012-12-15 16:01:52 +01:00
|
|
|
|
(setvbuf (current-error-port) _IOLBF)
|
2012-06-16 16:56:47 +02:00
|
|
|
|
|
|
|
|
|
;; The trick is to #:allow-other-keys everywhere, so that each procedure in
|
|
|
|
|
;; PHASES can pick the keyword arguments it's interested in.
|
|
|
|
|
(every (match-lambda
|
|
|
|
|
((name . proc)
|
2012-12-20 22:31:08 +01:00
|
|
|
|
(let ((start (gettimeofday)))
|
2013-06-21 00:32:07 +02:00
|
|
|
|
(format #t "starting phase `~a'~%" name)
|
|
|
|
|
(let ((result (apply proc args))
|
|
|
|
|
(end (gettimeofday)))
|
|
|
|
|
(format #t "phase `~a' ~:[failed~;succeeded~] after ~a seconds~%"
|
|
|
|
|
name result (- (car end) (car start)))
|
|
|
|
|
|
|
|
|
|
;; Dump the environment variables as a shell script, for handy debugging.
|
|
|
|
|
(system "export > $NIX_BUILD_TOP/environment-variables")
|
|
|
|
|
result))))
|
2012-06-16 16:56:47 +02:00
|
|
|
|
phases))
|