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,2017 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.5")
55 (define PREFIX "/usr/local")
56 (define GUILE_EFFECTIVE_VERSION (effective-version))
57 (define GUILE (or (getenv "guile") "guile"))
58 (define SYSCONFDIR "$(PREFIX)/etc")
61 (define (logf port string . rest)
62 (apply format (cons* port string rest))
66 (define (stderr string . rest)
67 (apply logf (cons* (current-error-port) string rest)))
69 (define (stdout string . rest)
70 (apply logf (cons* (current-output-port) string rest)))
72 (define *verbose?* #f)
74 (define (verbose string . rest)
75 (if *verbose?* (apply stderr (cons string rest))))
77 (define (gulp-pipe command)
78 (let* ((port (open-pipe* OPEN_READ *shell* "-c" command))
79 (output (read-string port))
80 (status (close-pipe port)))
81 (verbose "command[~a]: ~s => ~a\n" status command output)
82 (if (not (zero? status)) "" (string-trim-right output #\newline))))
84 (define* ((->string #:optional (infix "")) h . t)
85 (let ((o (if (pair? t) (cons h t) h)))
87 ((? char?) (make-string 1 o))
88 ((? number?) (number->string o))
90 ((? symbol?) (symbol->string o))
91 ((h ... t) (string-join (map (->string) o) ((->string) infix)))
96 ((and (null? a) (null? b)) #t)
97 ((null? a) (not (null? b)))
99 ((and (not (< (car a) (car b)))
100 (not (< (car b) (car a))))
101 (tuple< (cdr a) (cdr b)))
102 (else (< (car a) (car b)))))
104 (define (tuple<= a b)
105 (or (equal? a b) (tuple< a b)))
108 (define (version->string version)
109 ((->string '.) version))
111 (define (string->version string)
112 (and-let* ((version (string-tokenize string
113 (char-set-adjoin char-set:digit #\.)))
115 (version (sort version (lambda (a b) (> (string-length a) (string-length b)))))
116 (version (car version))
117 (version (string-tokenize version
118 (char-set-complement (char-set #\.)))))
119 (map string->number version)))
121 (define required '())
122 (define* (check-version command expected
125 (version-option '--version)
127 (stderr "checking for ~a~a..." command
128 (if (null? expected) ""
129 (format #f " [~a]" (version->string expected))))
130 (let* ((output (gulp-pipe (format #f "~a ~a 2>&1" command version-option)))
131 (actual (string->version output))
132 (pass? (and actual (compare expected actual))))
133 (stderr "~a ~a\n" (if pass? (if (pair? actual) "" " yes")
134 (if actual " no, found" "")) (version->string actual))
136 (if (not (pair? command)) (begin (set! required (cons (or deb command) required)) pass?)
137 (check-version (cdr command) expected deb version-option compare)))))
139 (define* (check-pkg-config package expected #:optional (deb #f))
140 (check-version (format #f "pkg-config --modversion ~a" package) expected deb))
142 (define (check-compile-header-c++ header)
143 (and (= 0 (system (format #f "echo '#include \"~a\"' | gcc --language=c++ --std=c++11 -E - > /dev/null 2>&1" header)))
146 (define* (check-header-c++ header deb #:optional (check check-compile-header-c++))
147 (stderr "checking for ~a..." header)
148 (let ((result (check header)))
149 (stderr " ~a\n" (if result result "no"))
151 (set! required (cons deb required)))))
154 (and (zero? (system "guix --version &>/dev/null")) 1))
157 (define CC (or (getenv "CC") "gcc"))
158 (define BUILD_TRIPLET (gulp-pipe (string-append CC " -dumpmachine 2>/dev/null")))
159 (define ARCH (car (string-split BUILD_TRIPLET #\-)))
160 (define CC32 (or (getenv "CC32")
161 (if (equal? ARCH "i686") CC
162 "i686-unknown-linux-gnu-gcc")))
164 (define (parse-opts args)
168 (help (single-char #\h))
170 (sysconfdir (value #t))
171 (verbose (single-char #\v))
173 (enable-fast-install)))
174 (options (getopt-long args option-spec))
175 (help? (option-ref options 'help #f))
176 (files (option-ref options '() '()))
177 (prefix (option-ref options '() PREFIX))
178 (usage? (and (not help?) #f)))
180 (stderr "ignoring files: ~a\n" files))
181 (or (and (or help? usage?)
182 ((or (and usage? stderr) stdout) "\
183 Usage: ./configure [OPTION]...
184 -h, --help display this help
185 --build=BUILD configure for building on BUILD [guessed]
186 --host=HOST cross-compile to build programs to run on HOST [BUILD]
187 --prefix=DIR install in PREFIX [~a]
188 --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
189 -v, --verbose be verbose
191 (exit (or (and usage? 2) 0)))
195 (let* ((options (parse-opts args))
196 (build-triplet (option-ref options 'build BUILD_TRIPLET))
197 (host-triplet (option-ref options 'host BUILD_TRIPLET))
198 (prefix (option-ref options 'prefix PREFIX))
199 (sysconfdir (option-ref options 'sysconfdir SYSCONFDIR))
200 (verbose? (option-ref options 'verbose #f)))
201 (set! *verbose?* verbose?)
202 (check-version 'bash '(4 0))
203 (check-version CC '(4 8))
204 (check-version CC32 '(4 8))
205 (check-version 'guile '(2 0))
206 (check-version 'make '(4 0))
207 (check-version 'perl '(5))
209 (when (pair? required)
210 (stderr "\nMissing dependencies [~a], run\n\n" ((->string ", ") required))
212 (stderr " guix environment -l guix.scm\n")
213 (stderr " sudo apt-get install ~a\n" ((->string " ") required)))
215 (with-output-to-file ".config.make"
217 (stdout "build:=~a\n" build-triplet)
218 (stdout "host:=~a\n" host-triplet)
219 (stdout "srcdir:=.\n")
220 (stdout "ARCH:=~a\n" ARCH)
221 (stdout "CC:=~a\n" CC)
222 (stdout "CC32:=~a\n" CC32)
223 (stdout "GUILE:=~a\n" GUILE)
224 (stdout "GUILE_EFFECTIVE_VERSION:=~a\n" GUILE_EFFECTIVE_VERSION)
225 (stdout "GUIX_P:=~a\n" (if guix? guix? ""))
226 (stdout "PACKAGE:=~a\n" PACKAGE)
227 (stdout "VERSION:=~a\n" VERSION)
228 (stdout "PREFIX:=~a\n" (gulp-pipe (string-append "echo " prefix)))
229 (stdout "SYSCONFDIR:=~a\n" sysconfdir)))
232 make help for help on other targets\n")))