build: Have configure prefer $CC over gcc; tcc over gcc, gcc over cc.

Reported by Vagrant Cascadian.

* configure (string->version): Prefer for most-dotted string.  Fixes
makeinfo version.
(check-program-version): Prefer displaying of command, if single word.
(main): Check for $CC --version, $CC -v.  Prefer $CC over gcc; tcc over
gcc, gcc over cc.
This commit is contained in:
Jan Nieuwenhuizen 2019-12-13 17:21:53 +01:00
parent 36b2857d5b
commit e984f7213f
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

56
configure vendored
View file

@ -155,7 +155,7 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)'
(data dependency-data) (data dependency-data)
(version-found dependency-version-found)) (version-found dependency-version-found))
(define* (make-dep name #:key (version '(0)) optional? (version-option "--version") (commands (list name)) file-name data) (define* (make-dep name #:key (version '()) optional? (version-option "--version") (commands (list name)) file-name data)
(let* ((env-var (getenv (name->shell-name name))) (let* ((env-var (getenv (name->shell-name name)))
(commands (if env-var (cons env-var commands) commands))) (commands (if env-var (cons env-var commands) commands)))
(make-dependency name version optional? version-option commands file-name data #f))) (make-dependency name version optional? version-option commands file-name data #f)))
@ -186,7 +186,12 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)'
(let ((split (string-tokenize string (let ((split (string-tokenize string
(char-set-adjoin char-set:digit #\.)))) (char-set-adjoin char-set:digit #\.))))
(and (pair? split) (and (pair? split)
(let* ((version (sort split (lambda (a b) (> (string-length a) (string-length b))))) (let* ((version (sort split (lambda (a b)
(let ((len-a (length (string-split a #\.)))
(len-b (length (string-split b #\.))))
(cond ((> len-a len-b) #t)
((< len-a len-b) #f)
(else (> (string-length a) (string-length b))))))))
(version (car version)) (version (car version))
(version (string-tokenize version (version (string-tokenize version
(char-set-complement (char-set #\.))))) (char-set-complement (char-set #\.)))))
@ -198,16 +203,17 @@ MES_ARENA=100000000 exec ${SCHEME-guile} -L . --no-auto-compile -e '(configure)'
(version-option (dependency-version-option dependency)) (version-option (dependency-version-option dependency))
(commands (dependency-commands dependency))) (commands (dependency-commands dependency)))
(let loop ((commands commands)) (let loop ((commands commands))
(if (null? commands) dependency (if (or (null? commands)
(not (car commands))) dependency
(let ((command (car commands))) (let ((command (car commands)))
(stdout "checking for ~a~a... " name (stdout "checking for ~a~a... " (if (string-index command #\space) name command)
(if (null? expected) "" (if (null? expected) ""
(format #f " [~a]" (version->string expected)))) (format #f " [~a]" (version->string expected))))
(let* ((output (gulp-pipe (string-append command " " (if version-option version-option "")))) (let* ((output (gulp-pipe (string-append command " " (if version-option version-option ""))))
(actual (string->version output)) (actual (string->version output))
(pass? (and actual (tuple< expected actual))) (pass? (and actual (tuple< expected actual)))
(dependency (set-field dependency (dependency-version-found) actual))) (dependency (set-field dependency (dependency-version-found) actual)))
(stdout "~a ~a\n" (if pass? (if (pair? actual) "" " yes") (stdout "~a ~a\n" (if pass? (if (pair? actual) "" "yes")
(if actual " no, found" "no")) (if actual " no, found" "no"))
(or (version->string actual) "")) (or (version->string actual) ""))
(if pass? (let ((file-name (or (PATH-search-path command) (if pass? (let ((file-name (or (PATH-search-path command)
@ -437,9 +443,9 @@ Some influential environment variables:
(stderr "configure args=~s\n" args)) (stderr "configure args=~s\n" args))
(for-each (lambda (v) (apply setenv (string-split v #\=))) vars) (for-each (lambda (v) (apply setenv (string-split v #\=))) vars)
(let* ((cross? (not (equal? host-type build-type))) (let* ((cross? (not (equal? host-type build-type)))
(gcc (or (getenv "CC") (if cross? (string-append host-type "-" "gcc") "gcc"))) (gcc (if cross? (string-append host-type "-" "gcc") "gcc"))
(tcc (or (getenv "TCC") "tcc")) (tcc (if cross? (string-append host-type "-" "tcc") "tcc"))
(mescc (or (getenv "MESCC") "mescc")) (mescc (if cross? (string-append host-type "-" "mescc") "mescc"))
(deps (fold (lambda (program results) (deps (fold (lambda (program results)
(cons (check-program-version program) results)) (cons (check-program-version program) results))
'() '()
@ -451,14 +457,18 @@ Some influential environment variables:
(make-dep "mes" #:version '(0 20) #:optional? #t) (make-dep "mes" #:version '(0 20) #:optional? #t)
(make-dep "guix" #:version '(0 13) #:optional? #t) (make-dep "guix" #:version '(0 13) #:optional? #t)
(make-dep "ar" #:version '(2 10) #:optional? #t) (make-dep "ar" #:version '(2 10) #:optional? #t)
(make-dep "sh" #:version '(0) #:optional? #t) (make-dep "sh" #:optional? #t)
(make-dep "bash" #:version '(2 0) #:optional? #t) (make-dep "bash" #:version '(2 0) #:optional? #t)
(make-dep "guild" #:version '(2 0) #:commands '("guild" "guile-tools" "true")) (make-dep "guild" #:version '(2 0) #:commands '("guild" "guile-tools" "true"))
(make-dep "cc" #:commands (list gcc "cc" tcc mescc) #:optional? #t) (make-dep "CC" #:commands `(,(getenv "CC")) #:optional? #t)
(make-dep "tcc" #:commands (list tcc "tcc") #:optional? #t #:version-option "-v") (make-dep "CC-v" #:commands `(,(getenv "CC")) #:optional? #t #:version-option "-v")
(make-dep "mescc" #:commands (list mescc "mescc") #:optional? #t) (make-dep "cc" #:commands '("cc") #:optional? #t)
(make-dep "gcc" #:commands `(,gcc "gcc") #:optional? #t)
(make-dep "mescc" #:commands `(,mescc "mescc") #:optional? #t)
(make-dep "tcc" #:commands `(,tcc "tcc") #:optional? #t #:version-option "-v")
(make-dep "cc-v" #:commands '("cc") #:optional? #t #:version-option "-v")
(make-dep "make" #:optional? #t #:commands '("gmake" "make")) (make-dep "make" #:optional? #t #:commands '("gmake" "make"))
(make-dep "makeinfo" #:optional? #t) (make-dep "makeinfo" #:version '(6) #:optional? #t)
(make-dep "dot" #:version-option "-V" #:optional? #t) (make-dep "dot" #:version-option "-V" #:optional? #t)
(make-dep "help2man" #:version '(1 47) #:optional? #t) (make-dep "help2man" #:version '(1 47) #:optional? #t)
(make-dep "perl" #:version '(5) #:optional? #t)))) (make-dep "perl" #:version '(5) #:optional? #t))))
@ -467,8 +477,12 @@ Some influential environment variables:
deps) deps)
deps)) deps))
(guile (or guile "guile")) (guile (or guile "guile"))
(cc (or (file-name "cc" deps) (cc (or (file-name "CC" deps)
(file-name "CC-v" deps)
(file-name "tcc" deps) (file-name "tcc" deps)
(file-name "gcc" deps)
(file-name "cc" deps)
(file-name "cc-v" deps)
(file-name "mescc" deps))) (file-name "mescc" deps)))
(deps (if cc (deps (if cc
(cons* (check-header-c cc (make-dep "limits.h")) (cons* (check-header-c cc (make-dep "limits.h"))
@ -494,15 +508,15 @@ Some influential environment variables:
deps)) deps))
(mesc? (file-name "cc is MES C" deps)) (mesc? (file-name "cc is MES C" deps))
(deps (if cc (deps (if cc
(cons (check-compile-c cc (make-dep "cc is Tiny CC" #:data "#if !defined (__TINYC__) (cons (check-compile-c cc (make-dep "cc is Tiny C" #:data "#if !defined (__TINYC__)
#error no tinycc #error no tinycc
#endif #endif
")) "))
deps) deps)
deps)) deps))
(tcc? (file-name "cc is Tiny CC" deps)) (tcc? (file-name "cc is Tiny C" deps))
(deps (if cc (deps (if cc
(cons (check-link-c cc (make-dep "if cc can create executables" #:data "int main () {return 0;}")) (cons (check-link-c cc (make-dep "whether cc can create executables" #:data "int main () {return 0;}"))
deps) deps)
deps)) deps))
(system-libc? (and with-system-libc? (file-name "if cc can create executables" deps))) (system-libc? (and with-system-libc? (file-name "if cc can create executables" deps)))
@ -521,7 +535,7 @@ Some influential environment variables:
(cut member <> '("pc" "portbld" "unknown"))) (cut member <> '("pc" "portbld" "unknown")))
(cdr host-type-list)))) (cdr host-type-list))))
(mes-kernel (if (string-prefix? "freebsd" mes-kernel) "freebsd" mes-kernel)) (mes-kernel (if (string-prefix? "freebsd" mes-kernel) "freebsd" mes-kernel))
(compiler (cond (gcc? "gcc") (tcc? "gcc") (else "mescc"))) (mes-compiler (cond (gcc? "gcc") (tcc? "gcc") (else "mescc")))
(mes-system (string-join (list mes-cpu mes-kernel "mes") "-")) (mes-system (string-join (list mes-cpu mes-kernel "mes") "-"))
(bash (or (and (file-exists? "/bin/bash") "/bin/bash") (bash (or (and (file-exists? "/bin/bash") "/bin/bash")
(file-name "bash" deps) (file-name "bash" deps)
@ -572,7 +586,7 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system)
("@bootstrap@" . ,(if with-bootstrap? "true" "false")) ("@bootstrap@" . ,(if with-bootstrap? "true" "false"))
("@courageous@" . ,(if with-courage? "true" "false")) ("@courageous@" . ,(if with-courage? "true" "false"))
("@compiler@" . ,compiler) ("@compiler@" . ,mes-compiler)
("@mes_bits@" . ,mes-bits) ("@mes_bits@" . ,mes-bits)
("@mes_kernel@" . ,mes-kernel) ("@mes_kernel@" . ,mes-kernel)
("@mes_cpu@" . ,mes-cpu) ("@mes_cpu@" . ,mes-cpu)
@ -606,7 +620,7 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system)
("@AR@" . ,(or (file-name "ar" deps) "")) ("@AR@" . ,(or (file-name "ar" deps) ""))
("@BASH@" . ,bash) ("@BASH@" . ,bash)
("@CC@" . ,(or (file-name "cc" deps) (file-name "tcc" deps) "")) ("@CC@" . ,cc)
("@DIFF@" . ,(or (file-name "diff" deps) (string-append abs-top-builddir "/pre-inst-env diff.scm"))) ("@DIFF@" . ,(or (file-name "diff" deps) (string-append abs-top-builddir "/pre-inst-env diff.scm")))
("@DOT@" . ,(or (file-name "dot" deps) "")) ("@DOT@" . ,(or (file-name "dot" deps) ""))
("@GIT@" . ,(or (file-name "git" deps) "")) ("@GIT@" . ,(or (file-name "git" deps) ""))
@ -682,7 +696,7 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system)
(let ((make (and=> (file-name "make" deps) basename))) (let ((make (and=> (file-name "make" deps) basename)))
(display (string-append " (display (string-append "
GNU Mes is configured for GNU Mes is configured for
compiler: " compiler " compiler: " mes-compiler "
cpu: " mes-cpu " cpu: " mes-cpu "
bits: " mes-bits " bits: " mes-bits "
libc: " mes-libc " libc: " mes-libc "