4 echo -n "checking for guile..."
5 GUILE=$(type -p ${GUILE-guile} 2>/dev/null|tail -n 1|sed 's,^.* ,,')
7 if [ -x "$GUILE" ]; then
10 pm=$({ guix --help || dpkg --help; }|head -n 1|sed 's,.*Usage: \([^ ]*\).*,\1,g')
12 case "$pm" in dpkg) message="sudo apt-get install guile-2.0";; *) message="guix package -i guile";; esac
14 Missing dependencies, run
20 unset GUILE_AUTO_COMPILE GUILE_LOAD_COMPILED_PATH
21 exec ${GUILE} --no-auto-compile -L $(pwd) -e '(@@ (configure) main)' -s "$0" ${1+"$@"}
24 ;;; Mes --- Maxwell Equations of Software
25 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
27 ;;; configure: This file is part of Mes.
29 ;;; Mes is free software; you can redistribute it and/or modify it
30 ;;; under the terms of the GNU General Public License as published by
31 ;;; the Free Software Foundation; either version 3 of the License, or (at
32 ;;; your option) any later version.
34 ;;; Mes is distributed in the hope that it will be useful, but
35 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;;; GNU General Public License for more details.
39 ;;; You should have received a copy of the GNU General Public License
40 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
43 (define-module (configure)
44 #:use-module (ice-9 and-let-star)
45 #:use-module (ice-9 curried-definitions)
46 #:use-module (ice-9 getopt-long)
47 #:use-module (ice-9 match)
48 #:use-module (ice-9 optargs)
49 #:use-module (ice-9 popen)
50 #:use-module (ice-9 rdelim))
53 (define PACKAGE "mes")
54 (define VERSION "0.0")
55 (define PREFIX "/usr/local")
56 (define GUILE_EV (effective-version))
57 (define CC (or (getenv "CC") "gcc"))
58 (define GUILE (or (getenv "guile") "guile"))
59 (define SYSCONFDIR "$(PREFIX)/etc")
62 (define (gulp-pipe command)
63 (let* ((port (open-pipe* OPEN_READ *shell* "-c" command))
64 (output (read-string port)))
66 (string-trim-right output #\newline)))
68 (define (logf port string . rest)
69 (apply format (cons* port string rest))
73 (define (stderr string . rest)
74 (apply logf (cons* (current-error-port) string rest)))
76 (define (stdout string . rest)
77 (apply logf (cons* (current-output-port) string rest)))
79 (define* ((->string #:optional (infix "")) h . t)
80 (let ((o (if (pair? t) (cons h t) h)))
82 ((? char?) (make-string 1 o))
83 ((? number?) (number->string o))
85 ((? symbol?) (symbol->string o))
86 ((h ... t) (string-join (map (->string) o) ((->string) infix)))
91 ((and (null? a) (null? b)) #t)
92 ((null? a) (not (null? b)))
94 ((and (not (< (car a) (car b)))
95 (not (< (car b) (car a))))
96 (tuple< (cdr a) (cdr b)))
97 (else (< (car a) (car b)))))
100 (or (equal? a b) (tuple< a b)))
103 (define (version->string version)
104 ((->string '.) version))
106 (define (string->version string)
107 (and-let* ((version (string-tokenize string
108 (char-set-adjoin char-set:digit #\.)))
110 (version (car version))
111 (version (string-tokenize version
112 (char-set-complement (char-set #\.)))))
113 (map string->number version)))
115 (define required '())
116 (define* (check-version command expected
119 (version-option '--version)
121 (stderr "checking for ~a~a..." command
122 (if (null? expected) ""
123 (format #f " [~a]" (version->string expected))))
124 (let* ((actual (gulp-pipe (format #f "~a ~a 2>&1" command version-option)))
125 (actual (string->version actual))
126 (pass? (and actual (compare expected actual))))
127 (stderr "~a ~a\n" (if pass? (if (pair? actual) "" " yes")
128 (if actual " no, found" "")) (version->string actual))
130 (set! required (cons (or deb command) required)))
133 (define* (check-pkg-config package expected #:optional (deb #f))
134 (check-version (format #f "pkg-config --modversion ~a" package) expected deb))
136 (define (check-compile-header-c++ header)
137 (and (= 0 (system (format #f "echo '#include \"~a\"' | gcc --language=c++ --std=c++11 -E - > /dev/null 2>&1" header)))
140 (define* (check-header-c++ header deb #:optional (check check-compile-header-c++))
141 (stderr "checking for ~a..." header)
142 (let ((result (check header)))
143 (stderr " ~a\n" (if result result "no"))
145 (set! required (cons deb required)))))
148 (system "guix --version &>/dev/null"))
151 (define (parse-opts args)
154 (help (single-char #\h))
156 (sysconfdir (value #t))
158 (enable-fast-install)))
159 (options (getopt-long args option-spec))
160 (help? (option-ref options 'help #f))
161 (files (option-ref options '() '()))
162 (prefix (option-ref options '() PREFIX))
163 (usage? (and (not help?) #f)))
165 (stderr "ignoring files: ~a\n" files))
166 (or (and (or help? usage?)
167 ((or (and usage? stderr) stdout) "\
168 Usage: ./configure [OPTION]...
169 -h, --help display this help
170 --prefix=DIR install in PREFIX [~a]
171 --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
173 (exit (or (and usage? 2) 0)))
176 (define BUILD_TRIPLET (gulp-pipe "gcc -dumpmachine 2>/dev/null"))
179 (let* ((options (parse-opts args))
180 (build-triplet (option-ref options 'build BUILD_TRIPLET))
181 (prefix (option-ref options 'prefix PREFIX))
182 (sysconfdir (option-ref options 'sysconfdir SYSCONFDIR)))
183 (check-version 'bash '(4 0))
184 (check-version 'gcc '(4 8))
185 (check-version 'guile '(2 0))
186 (check-version 'make '(4 0))
187 (check-version 'perl '(5))
189 (when (pair? required)
190 (stderr "\nMissing dependencies, run\n\n")
192 (stderr " guix environment -l guix.scm\n")
193 (stderr " sudo apt-get install ~a\n" ((->string " ") required)))
195 (with-output-to-file ".config.make"
197 (stdout "CC:=~a\n" CC)
198 (stdout "GUILE:=~a\n" GUILE)
199 (stdout "GUILE_EV:=~a\n" GUILE_EV)
200 (stdout "PACKAGE:=~a\n" PACKAGE)
201 (stdout "VERSION:=~a\n" VERSION)
202 (stdout "PREFIX:=~a\n" prefix)
203 (stdout "SYSCONFDIR:=~a\n" sysconfdir)))
206 make help for help on other targets\n")))