1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
3 ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (use-modules (system base target)
26 "Create directory DIR and all its ancestors."
28 (string-prefix? "/" dir))
31 (char-set-complement (char-set #\/)))
33 (let loop ((components (string-tokenize dir not-slash))
39 (let ((path (string-append root "/" head)))
45 (if (= EEXIST (system-error-errno args))
47 (apply throw args))))))
51 '(unsupported-warning format unbound-variable arity-mismatch))
53 (define host (getenv "host"))
55 (define srcdir (getenv "srcdir"))
57 (define (relative-file file)
58 (if (string-prefix? (string-append srcdir "/") file)
59 (string-drop file (+ 1 (string-length srcdir)))
62 (define (file-mtime<? f1 f2)
63 (< (stat:mtime (stat f1))
64 (stat:mtime (stat f2))))
66 (define (scm->go file)
67 (let* ((relative (relative-file file))
68 (without-extension (string-drop-right relative 4)))
69 (string-append without-extension ".go")))
71 (define (scm->mes file)
72 (let* ((relative (relative-file file))
73 (without-extension (string-drop-right relative 4)))
74 (string-append without-extension ".mes")))
76 (define (file-needs-compilation? file)
77 (let ((go (scm->go file)))
78 (or (not (file-exists? go))
79 (file-mtime<? go file)
80 (let ((mes (scm->mes file))) ; FIXME: try to respect (include-from-path ".mes")
81 (and (file-exists? mes)
82 (file-mtime<? go mes))))))
84 (define (file->module file)
85 (let* ((relative (relative-file file))
86 (module-path (string-drop-right relative 4)))
88 (string-split module-path #\/))))
90 ;;; To work around <http://bugs.gnu.org/15602> (FIXME), we want to load all
91 ;;; files to be compiled first. We do this via resolve-interface so that the
92 ;;; top-level of each file (module) is only executed once.
93 (define (load-module-file file)
94 (let ((module (file->module file)))
95 (format #t " LOAD ~a~%" module)
96 (resolve-interface module)))
99 (guile-2.2 (use-modules (language tree-il optimize)
100 (language cps optimize)))
103 (define %default-optimizations
104 ;; Default optimization options (equivalent to -O2 on Guile 2.2).
106 (guile-2.2 (append (tree-il-default-optimization-options)
107 (cps-default-optimization-options)))
110 (define %lightweight-optimizations
111 ;; Lightweight optimizations (like -O0, but with partial evaluation).
112 (let loop ((opts %default-optimizations)
115 (() (reverse result))
116 ((#:partial-eval? _ rest ...)
117 (loop rest `(#t #:partial-eval? ,@result)))
119 (loop rest `(#f ,kw ,@result))))))
121 (define (optimization-options file)
122 (if (string-contains file "gnu/packages/")
123 %lightweight-optimizations ;build faster
126 (define (compile-file* file output-mutex)
127 (let ((go (scm->go file)))
128 (with-mutex output-mutex
129 (format #t " GUILEC ~a~%" go)
131 (mkdir-p (dirname go))
132 (with-fluids ((*current-warning-prefix* ""))
137 #:opts `(#:warnings ,warnings
138 ,@(optimization-options file))))))))
140 ;; Install a SIGINT handler to give unwind handlers in 'compile-file' an
141 ;; opportunity to run upon SIGINT and to remove temporary output files.
146 (match (command-line)
148 (let ((files (filter file-needs-compilation? files)))
149 (for-each load-module-file files)
150 (let ((mutex (make-mutex)))
151 ;; Make sure compilation related modules are loaded before starting to
152 ;; compile files in parallel.
154 (par-for-each (lambda (file)
155 (compile-file* file mutex))
159 ;;; eval: (put 'with-target 'scheme-indent-function 1)