2016-10-15 22:34:23 +00:00
|
|
|
#! /bin/sh
|
|
|
|
# -*- scheme -*-
|
|
|
|
unset LANG LC_ALL
|
|
|
|
echo -n "checking for guile..."
|
|
|
|
GUILE=$(type -p ${GUILE-guile} 2>/dev/null|tail -n 1|sed 's,^.* ,,')
|
|
|
|
export GUILE
|
|
|
|
if [ -x "$GUILE" ]; then
|
|
|
|
echo " $GUILE"
|
|
|
|
else
|
|
|
|
pm=$({ guix --help || dpkg --help; }|head -n 1|sed 's,.*Usage: \([^ ]*\).*,\1,g')
|
|
|
|
#-paredit:'})(
|
2017-06-19 10:01:19 +00:00
|
|
|
case "$pm" in dpkg) message="sudo apt-get install guile-2.0";; *) message="guix environment guix.scm";; esac
|
2016-10-15 22:34:23 +00:00
|
|
|
cat <<EOF
|
|
|
|
Missing dependencies, run
|
|
|
|
|
|
|
|
$pm
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-06-19 10:01:19 +00:00
|
|
|
exec ${GUILE} --no-auto-compile -L $(pwd) -C $(pwd) -e 'main' -s "$0" ${1+"$@"}
|
2016-10-15 22:34:23 +00:00
|
|
|
!#
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
2017-04-12 19:27:59 +00:00
|
|
|
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
2016-10-15 22:34:23 +00:00
|
|
|
;;;
|
|
|
|
;;; configure: This file is part of Mes.
|
|
|
|
;;;
|
|
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
|
|
;;; 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.
|
|
|
|
;;;
|
|
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
|
|
;;; 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
|
|
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-06-19 10:01:19 +00:00
|
|
|
(define (main args)
|
|
|
|
((@@ (configure) main) args))
|
2016-10-15 22:34:23 +00:00
|
|
|
|
|
|
|
(define-module (configure)
|
|
|
|
#:use-module (ice-9 and-let-star)
|
|
|
|
#:use-module (ice-9 curried-definitions)
|
|
|
|
#:use-module (ice-9 getopt-long)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (ice-9 optargs)
|
|
|
|
#:use-module (ice-9 popen)
|
|
|
|
#:use-module (ice-9 rdelim))
|
|
|
|
|
|
|
|
(define *shell* "sh")
|
|
|
|
(define PACKAGE "mes")
|
2017-06-25 16:36:25 +00:00
|
|
|
(define VERSION "0.8")
|
2016-10-15 22:34:23 +00:00
|
|
|
(define PREFIX "/usr/local")
|
2017-04-12 19:27:59 +00:00
|
|
|
(define GUILE_EFFECTIVE_VERSION (effective-version))
|
2016-10-15 22:34:23 +00:00
|
|
|
(define GUILE (or (getenv "guile") "guile"))
|
|
|
|
(define SYSCONFDIR "$(PREFIX)/etc")
|
|
|
|
|
|
|
|
;;; Utility
|
|
|
|
(define (logf port string . rest)
|
|
|
|
(apply format (cons* port string rest))
|
|
|
|
(force-output port)
|
|
|
|
#t)
|
|
|
|
|
|
|
|
(define (stderr string . rest)
|
|
|
|
(apply logf (cons* (current-error-port) string rest)))
|
|
|
|
|
|
|
|
(define (stdout string . rest)
|
|
|
|
(apply logf (cons* (current-output-port) string rest)))
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
(define *verbose?* #f)
|
|
|
|
|
|
|
|
(define (verbose string . rest)
|
|
|
|
(if *verbose?* (apply stderr (cons string rest))))
|
|
|
|
|
|
|
|
(define (gulp-pipe command)
|
|
|
|
(let* ((port (open-pipe* OPEN_READ *shell* "-c" command))
|
|
|
|
(output (read-string port))
|
|
|
|
(status (close-pipe port)))
|
|
|
|
(verbose "command[~a]: ~s => ~a\n" status command output)
|
|
|
|
(if (not (zero? status)) "" (string-trim-right output #\newline))))
|
|
|
|
|
2016-10-15 22:34:23 +00:00
|
|
|
(define* ((->string #:optional (infix "")) h . t)
|
|
|
|
(let ((o (if (pair? t) (cons h t) h)))
|
|
|
|
(match o
|
|
|
|
((? char?) (make-string 1 o))
|
|
|
|
((? number?) (number->string o))
|
|
|
|
((? string?) o)
|
|
|
|
((? symbol?) (symbol->string o))
|
|
|
|
((h ... t) (string-join (map (->string) o) ((->string) infix)))
|
|
|
|
(_ ""))))
|
|
|
|
|
|
|
|
(define (tuple< a b)
|
|
|
|
(cond
|
|
|
|
((and (null? a) (null? b)) #t)
|
|
|
|
((null? a) (not (null? b)))
|
|
|
|
((null? b) #f)
|
|
|
|
((and (not (< (car a) (car b)))
|
|
|
|
(not (< (car b) (car a))))
|
|
|
|
(tuple< (cdr a) (cdr b)))
|
|
|
|
(else (< (car a) (car b)))))
|
|
|
|
|
|
|
|
(define (tuple<= a b)
|
|
|
|
(or (equal? a b) (tuple< a b)))
|
|
|
|
|
|
|
|
;;; Configure
|
|
|
|
(define (version->string version)
|
|
|
|
((->string '.) version))
|
|
|
|
|
|
|
|
(define (string->version string)
|
|
|
|
(and-let* ((version (string-tokenize string
|
|
|
|
(char-set-adjoin char-set:digit #\.)))
|
|
|
|
((pair? version))
|
2017-04-02 16:50:07 +00:00
|
|
|
(version (sort version (lambda (a b) (> (string-length a) (string-length b)))))
|
2016-10-15 22:34:23 +00:00
|
|
|
(version (car version))
|
|
|
|
(version (string-tokenize version
|
|
|
|
(char-set-complement (char-set #\.)))))
|
|
|
|
(map string->number version)))
|
|
|
|
|
2017-06-19 10:01:19 +00:00
|
|
|
(define optional '())
|
2016-10-15 22:34:23 +00:00
|
|
|
(define required '())
|
2017-05-07 08:04:32 +00:00
|
|
|
(define* (check-version name expected
|
|
|
|
#:key
|
2017-06-19 10:01:19 +00:00
|
|
|
optional?
|
2016-10-15 22:34:23 +00:00
|
|
|
(deb #f)
|
|
|
|
(version-option '--version)
|
2017-05-07 08:04:32 +00:00
|
|
|
(compare tuple<=)
|
|
|
|
(command name))
|
|
|
|
(stderr "checking for ~a~a..." name
|
2016-10-15 22:34:23 +00:00
|
|
|
(if (null? expected) ""
|
|
|
|
(format #f " [~a]" (version->string expected))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(let* ((output (gulp-pipe (format #f "~a ~a 2>&1" command version-option)))
|
|
|
|
(actual (string->version output))
|
2016-10-15 22:34:23 +00:00
|
|
|
(pass? (and actual (compare expected actual))))
|
|
|
|
(stderr "~a ~a\n" (if pass? (if (pair? actual) "" " yes")
|
|
|
|
(if actual " no, found" "")) (version->string actual))
|
2017-04-12 19:27:59 +00:00
|
|
|
(or pass?
|
2017-06-19 10:01:19 +00:00
|
|
|
(if (not (pair? name)) (begin (if optional? (set! optional (cons (or deb name) optional))
|
|
|
|
(set! required (cons (or deb name) required)))
|
|
|
|
pass?)
|
2017-05-07 08:04:32 +00:00
|
|
|
(check-version (cdr name) expected deb version-option compare)))))
|
2016-10-15 22:34:23 +00:00
|
|
|
|
|
|
|
(define* (check-pkg-config package expected #:optional (deb #f))
|
|
|
|
(check-version (format #f "pkg-config --modversion ~a" package) expected deb))
|
|
|
|
|
2017-05-14 07:03:06 +00:00
|
|
|
(define (check-compile-header-c header)
|
|
|
|
(and (= 0 (system (format #f "echo '#include ~s' | gcc -E - > /dev/null 2>&1" header)))
|
|
|
|
'yes))
|
|
|
|
|
2016-10-15 22:34:23 +00:00
|
|
|
(define (check-compile-header-c++ header)
|
2017-05-14 07:03:06 +00:00
|
|
|
(and (= 0 (system (format #f "echo '#include ~s' | gcc --language=c++ --std=c++11 -E - > /dev/null 2>&1" header)))
|
2016-10-15 22:34:23 +00:00
|
|
|
'yes))
|
|
|
|
|
2017-05-14 07:03:06 +00:00
|
|
|
(define* (check-header-c header deb #:optional (check check-compile-header-c))
|
2016-10-15 22:34:23 +00:00
|
|
|
(stderr "checking for ~a..." header)
|
|
|
|
(let ((result (check header)))
|
|
|
|
(stderr " ~a\n" (if result result "no"))
|
|
|
|
(if (not result)
|
|
|
|
(set! required (cons deb required)))))
|
|
|
|
|
2017-05-14 07:03:06 +00:00
|
|
|
(define* (check-header-c++ header deb #:optional (check check-compile-header-c++))
|
|
|
|
(check-header-c header deb check))
|
|
|
|
|
2016-10-15 22:34:23 +00:00
|
|
|
(define guix?
|
2017-05-14 07:03:06 +00:00
|
|
|
(and (zero? (system "guix --version 1>/dev/null 2>/dev/null")) 1))
|
2016-10-15 22:34:23 +00:00
|
|
|
;;;
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
(define CC (or (getenv "CC") "gcc"))
|
2017-06-19 10:01:19 +00:00
|
|
|
(define BUILD_TRIPLET %host-type)
|
2017-04-12 19:27:59 +00:00
|
|
|
(define ARCH (car (string-split BUILD_TRIPLET #\-)))
|
|
|
|
(define CC32 (or (getenv "CC32")
|
2017-05-14 07:03:06 +00:00
|
|
|
(if (member ARCH '("i686" "arm")) (string-append BUILD_TRIPLET "-" CC)
|
2017-04-12 19:27:59 +00:00
|
|
|
"i686-unknown-linux-gnu-gcc")))
|
2017-06-23 18:18:09 +00:00
|
|
|
(define HEX2 (or (getenv "HEX2") "hex2"))
|
2017-04-12 19:27:59 +00:00
|
|
|
|
2016-10-15 22:34:23 +00:00
|
|
|
(define (parse-opts args)
|
|
|
|
(let* ((option-spec
|
|
|
|
'((build (value #t))
|
2017-04-12 19:27:59 +00:00
|
|
|
(host (value #t))
|
2016-10-15 22:34:23 +00:00
|
|
|
(help (single-char #\h))
|
|
|
|
(prefix (value #t))
|
|
|
|
(sysconfdir (value #t))
|
2017-04-12 19:27:59 +00:00
|
|
|
(verbose (single-char #\v))
|
2017-05-14 07:03:06 +00:00
|
|
|
(with-courage)
|
2016-10-15 22:34:23 +00:00
|
|
|
;;ignore
|
|
|
|
(enable-fast-install)))
|
|
|
|
(options (getopt-long args option-spec))
|
|
|
|
(help? (option-ref options 'help #f))
|
|
|
|
(files (option-ref options '() '()))
|
|
|
|
(prefix (option-ref options '() PREFIX))
|
|
|
|
(usage? (and (not help?) #f)))
|
|
|
|
(if (pair? files)
|
|
|
|
(stderr "ignoring files: ~a\n" files))
|
|
|
|
(or (and (or help? usage?)
|
|
|
|
((or (and usage? stderr) stdout) "\
|
|
|
|
Usage: ./configure [OPTION]...
|
|
|
|
-h, --help display this help
|
2017-04-12 19:27:59 +00:00
|
|
|
--build=BUILD configure for building on BUILD [guessed]
|
|
|
|
--host=HOST cross-compile to build programs to run on HOST [BUILD]
|
2016-10-15 22:34:23 +00:00
|
|
|
--prefix=DIR install in PREFIX [~a]
|
|
|
|
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
2017-04-12 19:27:59 +00:00
|
|
|
-v, --verbose be verbose
|
2017-05-14 07:03:06 +00:00
|
|
|
--with-courage assert being courageous to configure for unsupported platform
|
2016-10-15 22:34:23 +00:00
|
|
|
" PREFIX)
|
|
|
|
(exit (or (and usage? 2) 0)))
|
|
|
|
options)))
|
|
|
|
|
|
|
|
(define (main args)
|
|
|
|
(let* ((options (parse-opts args))
|
|
|
|
(build-triplet (option-ref options 'build BUILD_TRIPLET))
|
2017-04-12 19:27:59 +00:00
|
|
|
(host-triplet (option-ref options 'host BUILD_TRIPLET))
|
2016-10-15 22:34:23 +00:00
|
|
|
(prefix (option-ref options 'prefix PREFIX))
|
2017-04-12 19:27:59 +00:00
|
|
|
(sysconfdir (option-ref options 'sysconfdir SYSCONFDIR))
|
2017-05-14 07:03:06 +00:00
|
|
|
(verbose? (option-ref options 'verbose #f))
|
2017-07-02 14:25:14 +00:00
|
|
|
(with-courage? (option-ref options 'with-courage #f))
|
|
|
|
(make? #f))
|
2017-04-12 19:27:59 +00:00
|
|
|
(set! *verbose?* verbose?)
|
2017-06-25 15:40:38 +00:00
|
|
|
(check-version 'guile '(2 0))
|
|
|
|
(check-version HEX2 '(0 0))
|
|
|
|
(check-version 'nyacc '(0 78 0) #:command (string-append GUILE " -c '(use-modules (nyacc lalr)) (display *nyacc-version*)'"))
|
|
|
|
|
2016-10-15 22:34:23 +00:00
|
|
|
(check-version 'bash '(4 0))
|
2017-05-14 07:03:06 +00:00
|
|
|
(when (and (not (member ARCH '("i686" "x86_64"))) (not with-courage?))
|
|
|
|
(stderr "platform not supported: ~a, try --with-courage\n" ARCH)
|
|
|
|
(exit 1))
|
2017-06-19 10:01:19 +00:00
|
|
|
(if (not (check-version CC '(4 8) #:optional? #t))
|
|
|
|
(set! CC #f))
|
|
|
|
(when CC
|
|
|
|
(check-header-c "stdio.h" "libc-dev")
|
|
|
|
(check-header-c "limits.h" "linux-headers"))
|
|
|
|
(if (not (check-version CC32 '(4 8) #:optional? #t))
|
|
|
|
(set! CC32 #f))
|
2017-07-02 14:25:14 +00:00
|
|
|
(set! make? (check-version 'make '(4 0) #:optional? #t))
|
2016-10-15 22:34:23 +00:00
|
|
|
(check-version 'perl '(5))
|
|
|
|
|
|
|
|
(when (pair? required)
|
2017-04-12 19:27:59 +00:00
|
|
|
(stderr "\nMissing dependencies [~a], run\n\n" ((->string ", ") required))
|
|
|
|
(if guix?
|
|
|
|
(stderr " guix environment -l guix.scm\n")
|
|
|
|
(stderr " sudo apt-get install ~a\n" ((->string " ") required)))
|
|
|
|
(exit 1))
|
2016-10-15 22:34:23 +00:00
|
|
|
(with-output-to-file ".config.make"
|
|
|
|
(lambda ()
|
2017-04-12 19:27:59 +00:00
|
|
|
(stdout "build:=~a\n" build-triplet)
|
|
|
|
(stdout "host:=~a\n" host-triplet)
|
|
|
|
(stdout "srcdir:=.\n")
|
|
|
|
(stdout "ARCH:=~a\n" ARCH)
|
2017-06-19 10:01:19 +00:00
|
|
|
(stdout "CC:=~a\n" (or CC ""))
|
|
|
|
(stdout "CC32:=~a\n" (or CC32 ""))
|
2016-10-15 22:34:23 +00:00
|
|
|
(stdout "GUILE:=~a\n" GUILE)
|
2017-05-28 16:32:53 +00:00
|
|
|
(stdout "GUILE_FOR_BUILD:=~a\n" GUILE)
|
2017-04-12 19:27:59 +00:00
|
|
|
(stdout "GUILE_EFFECTIVE_VERSION:=~a\n" GUILE_EFFECTIVE_VERSION)
|
2017-04-02 16:50:07 +00:00
|
|
|
(stdout "GUIX_P:=~a\n" (if guix? guix? ""))
|
2017-06-23 18:18:09 +00:00
|
|
|
(stdout "HEX2:=~a\n" (or HEX2 ""))
|
2016-10-15 22:34:23 +00:00
|
|
|
(stdout "PACKAGE:=~a\n" PACKAGE)
|
|
|
|
(stdout "VERSION:=~a\n" VERSION)
|
2016-12-07 19:26:41 +00:00
|
|
|
(stdout "PREFIX:=~a\n" (gulp-pipe (string-append "echo " prefix)))
|
2016-10-15 22:34:23 +00:00
|
|
|
(stdout "SYSCONFDIR:=~a\n" sysconfdir)))
|
2017-07-02 14:25:14 +00:00
|
|
|
(format (current-output-port)
|
|
|
|
"\nRun:
|
|
|
|
~a to build mes
|
|
|
|
~a help for help on other targets\n"
|
|
|
|
(if make? "make" "./make.scm")
|
|
|
|
(if make? "make" "./make.scm"))))
|