From 82c85c24dad61b7c8fd88b8491554a690474a65c Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 7 Dec 2019 14:39:19 +0100 Subject: [PATCH] build: Support mescc-tools 0.5.2. * configure: Remove version check for mescc-tools. Check for stage0 architecture flag type. * configure.sh: Likewise. * build-aux/build-scaffold.sh: Add stage0 flag type indirection. * module/mescc/mescc.scm (arch-get-architecture): Likewise. --- build-aux/build-scaffold.sh | 30 ++++++++++++++++++++++-------- build-aux/build.sh.in | 2 +- build-aux/config.sh.in | 1 + configure | 16 ++++++++++++---- configure.sh | 10 ++++++++++ module/mescc.scm | 5 +++++ module/mescc/mescc.scm | 15 +++++++++------ scripts/mescc.in | 2 ++ scripts/mescc.scm.in | 6 ++++++ 9 files changed, 68 insertions(+), 19 deletions(-) diff --git a/build-aux/build-scaffold.sh b/build-aux/build-scaffold.sh index dc07f432..42c62f46 100755 --- a/build-aux/build-scaffold.sh +++ b/build-aux/build-scaffold.sh @@ -44,13 +44,21 @@ fi case "$mes_cpu" in arm) - stage0_cpu=armv7l;; + stage0_arch=40 + stage0_cpu=armv7l + ;; x86_64) - stage0_cpu=amd64;; + stage0_arch=2 + stage0_cpu=amd64 + ;; x86) - stage0_cpu=x86;; + stage0_arch=1 + stage0_cpu=x86 + ;; *) - stage0_cpu=$mes_cpu;; + stage0_arch=1 + stage0_cpu=$mes_cpu + ;; esac trace "CCLD ${srcdest}lib/$mes_cpu-mes-$compiler/exit-42.S" $CC\ @@ -64,9 +72,15 @@ trace "TEST exit-42" [ $r != 42 ] && echo " => $r" [ $r = 42 ] +if $numbered_arch; then + stage0_cpu_flag="--Architecture $stage0_arch"; +else + stage0_cpu_flag="--architecture $stage0_cpu"; +fi + trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0exit-42.hex2" $HEX2\ --LittleEndian\ - --architecture $stage0_cpu\ + $stage0_cpu_flag\ --BaseAddress 0x1000000\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0header.hex2\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0exit-42.hex2\ @@ -80,7 +94,7 @@ trace "TEST 0exit-42" trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2" $HEX2\ --LittleEndian\ - --architecture $stage0_cpu\ + $stage0_cpu_flag\ --BaseAddress 0x1000000\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-header.hex2\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2\ @@ -107,7 +121,7 @@ trace "TEST hello-mes" trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0hello-mes.hex2" $HEX2\ --LittleEndian\ - --architecture $stage0_cpu\ + $stage0_cpu_flag\ --BaseAddress 0x1000000\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0header.hex2\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-0hello-mes.hex2\ @@ -121,7 +135,7 @@ trace "TEST 0hello-mes" trace "HEX2 ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-hello-mes.hex2" $HEX2\ --LittleEndian\ - --architecture $stage0_cpu\ + $stage0_cpu_flag\ --BaseAddress 0x1000000\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-header.hex2\ -f ${srcdest}lib/$mes_cpu-mes/elf$mes_bits-body-hello-mes.hex2\ diff --git a/build-aux/build.sh.in b/build-aux/build.sh.in index a7d81b62..24b417ef 100644 --- a/build-aux/build.sh.in +++ b/build-aux/build.sh.in @@ -116,7 +116,7 @@ fi LDFLAGS= ${SHELL} ${srcdest}build-aux/build-lib.sh ${SHELL} ${srcdest}build-aux/build-source-lib.sh - if bootstrap; then + if $bootstrap; then ${SHELL} ${srcdest}build-aux/build-mes.sh fi ) diff --git a/build-aux/config.sh.in b/build-aux/config.sh.in index 29006499..0f3783f2 100644 --- a/build-aux/config.sh.in +++ b/build-aux/config.sh.in @@ -54,6 +54,7 @@ abs_top_srcdir="@abs_top_srcdir@" arch="@arch@" build="@build@" host="@host@" +numbered_arch=${numbered_arch-"@numbered_arch@"} bootstrap=${bootstrap-@bootstrap@} compiler=${compiler-@compiler@} diff --git a/configure b/configure index f7ce1347..fe005f68 100755 --- a/configure +++ b/configure @@ -448,9 +448,9 @@ Some influential environment variables: (deps (fold (lambda (program results) (cons (check-program-version program) results)) '() - (list (make-dep "hex2" #:version '(0 6)) - (make-dep "M1" #:version '(0 6)) - (make-dep "blood-elf" #:version '(0 6)) + (list (make-dep "hex2") + (make-dep "M1") + (make-dep "blood-elf") (make-dep "diff" #:optional? #t) (make-dep "guile" #:version '(2 0) #:commands '("guile-2.2" "guile-2.0" "guile-2" "guile") #:optional? #t) (make-dep "mes" #:version '(0 20) #:optional? #t) @@ -534,7 +534,13 @@ Some influential environment variables: (file-name "bash" deps) (and (file-exists? "/bin/sh") "/bin/sh") (file-name "sh" deps) - "sh"))) + "sh")) + (hex2 (file-name "hex2" deps)) + (numbered-arch? (begin + (stdout "checking for stage0 architecture flag... ") + (let ((numbered? (and hex2 (string-contains (gulp-pipe (string-append hex2 " --help 2>&1" )) "--Architecture 12345")))) + (stdout (if numbered? "numbered\n" "named\n")) + numbered?)))) (define* (substitute file-name pairs #:key (target (if (string-suffix? ".in" file-name) @@ -625,6 +631,7 @@ See \"Porting GNU Mes\" in the manual, or try --with-courage\n" mes-system) ("@LDFLAGS@" . ,(or (getenv "LDFLAGS") "-static -g")) ("@HEX2FLAGS@" . ,(or (getenv "HEX2FLAGS") "")) ("@M1FLAGS@" . ,(or (getenv "M1FLAGS") "")) + ("@numbered_arch@" . ,(if numbered-arch? "true" "false")) ,@(map (lambda (o) @@ -687,6 +694,7 @@ GNU Mes is configured for libc: " mes-libc " kernel: " mes-kernel " system: " mes-system " + tools: " (if numbered-arch? "numbered" "named") " arch Run: " (or make "./build.sh") " to build mes diff --git a/configure.sh b/configure.sh index 704be03c..8971406f 100755 --- a/configure.sh +++ b/configure.sh @@ -99,6 +99,14 @@ if test -z "$GUILE" -o "$GUILE" = true; then else GUILE_EFFECTIVE_VERSION=${GUILE_EFFECTIVE_VERSION-$(guile -c '(display (effective-version))')} fi + +numbered_arch=false +mes_tools=named +if ( $HEX2 --help 2>&1 ) | grep -q "\-\-Architecture 12345"; then + numbered_arch=true + mes_tools=numbered +fi + bindir=$(eval echo ${bindir-$prefix/bin}) datadir=$(eval echo ${datadir-$prefix/share}) docdir=$(eval echo ${docdir-$datadir/doc/mes}) @@ -164,6 +172,7 @@ subst () { -e s,"@MES_FOR_BUILD@,$MES_FOR_BUILD,"\ -e s,"@MES_SEED@,$MES_SEED,"\ -e s,"@MES_SEED@,$MES_SEED,"\ + -e s,"@numbered_arch@,$numbered_arch,"\ -e s,"@SHELL@,$SHELL,"\ $1 > $2 } @@ -259,6 +268,7 @@ GNU Mes is configured for libc: $mes_libc kernel: $mes_kernel system: $mes_system + tools: $mes_tools arch Run: sh build.sh to build mes diff --git a/module/mescc.scm b/module/mescc.scm index d3231206..cf4db42c 100644 --- a/module/mescc.scm +++ b/module/mescc.scm @@ -41,6 +41,7 @@ (define %includedir (getenv "%includedir")) (define %libdir (getenv "%libdir")) (define %version (getenv "%version")) +(define %numbered-arch? (and=> (getenv "%numbered_arch") (lambda (x) (equal? x "true")))) (when (and=> (getenv "V") (lambda (v) (and (= (string-length v) 1) (> (string->number v) 1)))) (format (current-error-port) "mescc[~a]...\n" %scheme)) @@ -75,6 +76,7 @@ (nostartfiles) (nostdinc) (nostdlib) + (numbered-arch?) (preprocess (single-char #\E)) (static) (std (value #t)) @@ -103,6 +105,7 @@ Options: -dumpmachine display the compiler's target machine --base-address=ADRRESS use BaseAddress ADDRESS [0x1000000] + --numbered-arch mescc-tools use numbered arch -D DEFINE[=VALUE] define DEFINE [VALUE=1] -E preprocess only; do not compile, assemble or link -g add debug info [GDB, objdump] TODO: hex2 footer @@ -164,6 +167,8 @@ General help using GNU software: (options (acons 'libdir %libdir options)) (arch (option-ref options 'arch %host-arch)) (options (if arch (acons 'arch arch options) options)) + (numbered-arch? (option-ref options 'numbered-arch? %numbered-arch?)) + (options (acons 'numbered-arch? numbered-arch? options)) (dumpmachine? (option-ref options 'dumpmachine #f)) (preprocess? (option-ref options 'preprocess #f)) (compile? (option-ref options 'compile #f)) diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index 94a7380f..3c13f704 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -186,7 +186,7 @@ (M1 (or (getenv "M1") "M1")) (command `(,M1 "--LittleEndian" - "--architecture" ,(arch-get-architecture options) + ,@(arch-get-architecture options) "-f" ,(arch-find options (arch-get-m1-macros options)) ,@(append-map (cut list "-f" <>) M1-files) "-o" ,hex2-file-name))) @@ -211,7 +211,7 @@ `("-f" ,(arch-find options "crt1.o")))) (command `(,hex2 "--LittleEndian" - "--architecture" ,(arch-get-architecture options) + ,@(arch-get-architecture options) "--BaseAddress" ,base-address "-f" ,(arch-find options (string-append "elf" machine "-header.hex2")) ,@start-files @@ -322,10 +322,13 @@ ((equal? arch "x86_64") "x86_64.M1")))) (define (arch-get-architecture options) - (let ((arch (arch-get options))) - (cond ((equal? arch "arm") "armv7l") - ((equal? arch "x86") "x86") - ((equal? arch "x86_64") "amd64")))) + (let* ((arch (arch-get options)) + (numbered-arch? (option-ref options 'numbered-arch? #f)) + (flag (if numbered-arch? "--Architecture" "--architecture"))) + (list flag + (cond ((equal? arch "arm") (if numbered-arch? "40" "armv7l")) + ((equal? arch "x86") (if numbered-arch? "1" "x86")) + ((equal? arch "x86_64") (if numbered-arch? "2" "amd64")))))) (define (multi-opt option-name) (lambda (o) (and (eq? (car o) option-name) (cdr o)))) (define (count-opt options option-name) diff --git a/scripts/mescc.in b/scripts/mescc.in index 777d3dbd..0780968a 100644 --- a/scripts/mescc.in +++ b/scripts/mescc.in @@ -43,6 +43,8 @@ includedir=${includedir-@includedir@} export includedir libdir=${libdir-@libdir@} export libdir +numbered_arch=${numbered_arch=@numbered_arch@} +export numbered_arch if [ ! -f $bindir/mescc.scm ]; then bindir=$(dirname $0) diff --git a/scripts/mescc.scm.in b/scripts/mescc.scm.in index c4719d22..e1d91eac 100644 --- a/scripts/mescc.scm.in +++ b/scripts/mescc.scm.in @@ -41,11 +41,17 @@ (define %arch (if (string-prefix? "@mes_cpu" "@mes_cpu@") %arch "@mes_cpu@")) +(define %numbered-arch? (if (getenv "numbered_arch") (and=> (getenv "numbered_arch") + (lambda (x) (equal? x "true"))) + (if (string-prefix? "@numbered_arch" "@numbered_arch@") #f + (equal? "@numbered_arch@" "true")))) + (setenv "%prefix" %prefix) (setenv "%includedir" %includedir) (setenv "%libdir" %libdir) (setenv "%version" %version) (setenv "%arch" %arch) +(setenv "%numbered_arch" (if %numbered-arch? "true" "false")) (cond-expand (mes