From ad064de67269f6dd06e1bd8a7ac4324ee2a6324f Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 26 Apr 2024 08:28:09 -0600 Subject: [PATCH] configure: improve inference of compiler flags for pb builds (#829) When building an pb variant like `tpb64l`, and even when building for a platform without native-code support, the "configure" script may still be able to infer suitable C compilation and linking flags for the kernel. Add an `--os=...` flag that can be used to override that inference in case it's not correct (as in the case of cross compilation). --- BUILDING | 8 ++++++ c/build.zuo | 6 ++--- configure | 72 ++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/BUILDING b/BUILDING index 9e9a268be..887c7518a 100644 --- a/BUILDING +++ b/BUILDING @@ -146,6 +146,14 @@ type of build and the installation location. For example, specifies the installation root. Run `./configure --help` for information on the supported options. +For platforms without support for native-code compilation in Chez +Scheme, use a machine specification like `-m=tpb64l`, which is a +threaded, 64-bit, little-endian build. The "configure" script will +still attept to infer compilation and linking flags for the kernel; if +you need to give it a hint, you can use the `--os` flag with something +like `--os=tXle`, which indicates a threaded configuration (due to the +leading "t") on Linux (due to the trailing "le"). + The generated makefile mostly just ensures that a `zuo` executable is built in a `bin` directory, and then it defers the actual build work to `zuo`, which uses the "main.zuo" file. If you have `zuo` installed, diff --git a/c/build.zuo b/c/build.zuo index b9b5f6d67..7a73ef2b1 100644 --- a/c/build.zuo +++ b/c/build.zuo @@ -93,7 +93,7 @@ kernel-srcs)) (define kernel-asm-files - (if (glob-match? "*nt" (or (lookup 'defaultm) m)) + (if (glob-match? "*nt" (or (lookup 'flagsm) m)) (cond [(and msvc? (string=? arch "a6")) @@ -510,7 +510,7 @@ [config (hash-set config 'LDFLAGS (if (as-runtime-dll? config) "/MD" "/MT"))] [config (hash-set config 'LIBS "rpcrt4.lib ole32.lib advapi32.lib User32.lib")]) config)] - [(and (glob-match? "*nt" (hash-ref config 'defaultm "")) + [(and (glob-match? "*nt" (hash-ref config 'flagsm "")) (glob-match? "pb*" (m->arch (hash-ref config 'm)))) (config-merge config 'CFLAGS "-DFEATURE_WINDOWS")] [else config])) @@ -554,7 +554,7 @@ (define (for-windows? config) (or (is-msvc? config) (glob-match? "*nt" (hash-ref config 'm)) - (glob-match? "*nt" (or (hash-ref config 'defaultm #f) "")))) + (glob-match? "*nt" (or (hash-ref config 'flagsm #f) "")))) (define (lib-build-suffix config) (if (is-msvc? config) diff --git a/configure b/configure index 9adae37a4..d3c91edba 100755 --- a/configure +++ b/configure @@ -49,8 +49,21 @@ else cflagsset=no fi +# Machine type to build: m="" + +# Working directory, defaults to $m w="" + +# Machine describing the OS that the kernel runs on, so it determines +# default compiler and linker flags; when $m is a pb variant, then +# this OS is inferred if not specified with `--osmachine=` +flagsm="" + +# Used to select a default $m, but in the end corresponds to +# the target machine for boot files when built via pb +defaultm="" + pb=no pbarch=no threads=yes @@ -257,6 +270,9 @@ while [ $# != 0 ] ; do --machine=*) m=`echo $1 | sed -e 's/^--machine=//'` ;; + --os=*) + flagsm=`echo $1 | sed -e 's/^--os=//'` + ;; --boot=*) mboot=`echo $1 | sed -e 's/^--boot=//'` ;; @@ -477,15 +493,6 @@ if [ $emscripten = yes ] ; then tm32=tpb32l fi -case "$m" in - pb) - echo "Don't select pb using -m or --machine, because pb prefers to use the" - echo " machine as the kernel host machine. Instead, use --pb or --pbarch" - echo " to select a pb (portable bytecode) build." - exit 1 - ;; -esac - if [ "$bits" = "" ] ; then # infer default bits; this will be irrelevant if a machine is specified if [ "$unamebits" != "" ] ; then @@ -506,7 +513,14 @@ fi # to the host platform's threadedness, and we want that to default # the same way as when `--pb` is not used if [ "$threads" = "" ] ; then - defaultthreads=yes + case "$m" in + pb*) + defaultthreads=no + ;; + *) + defaultthreads=yes + ;; + esac else defaultthreads=$threads fi @@ -542,26 +556,33 @@ if [ "$m" = "" ] ; then machine_supplied=no if [ $pb = yes ] ; then m=pb - if [ "$threads" = yes ] ; then m=t$m ; fi - if [ $bits = 64 ] ; then mpbhost=$m64 ; else mpbhost=$m32 ; fi - flagsm=$mpbhost - if [ "$mpbhost" = "" ] ; then - flagsm=unknown + if [ $bits = 64 ] ; then defaultflagsm=$m64 ; else defaultflagsm=$m32 ; fi + if [ "$defaultflagsm" = "" ] ; then + defaultflagsm=unknown + fi + if [ "$threads" = yes ] ; then + m=t$m + defaultflagsm=t$defaultflagsm fi else if [ "$unknownm" != "yes" ] ; then m=$defaultm fi - flagsm=$defaultm - # note that m (and flagsm) could still be "" at this point, in which + defaultflagsm=$defaultm + # note that m (and defaultflagsm) could still be "" at this point, in which # case "No suitable machine type" will be reported further below fi elif [ $pb = yes ] ; then - mpbhost=$m - flagsm=$m + defaultflagsm=$m m=pb else - flagsm=$m + case "${m}" in + pb*|tpb*) + defaultflagsm=$defaultm + ;; + *) + defaultflagsm=$m + esac defaultm=$m fi @@ -569,9 +590,14 @@ if [ $pbarch = yes ] ; then m=pb$bits$pbendian if [ "$defaultthreads" = yes ] ; then m=t$m + defaultflagsm=t$defaultflagsm fi fi +if [ "$flagsm" = "" ] ; then + flagsm=$defaultflagsm +fi + if [ "$mboot" = "" ] ; then mboot="$m" else @@ -623,6 +649,7 @@ if [ "$help" = "yes" ]; then echo "Options (defaults shown in parens):" echo " --machine= explicitly specify machine type ($m)" echo " -m= same as --machine= ($m)" + echo " --os= specify OS as a machine type ($flagsm)" echo " --threads specify threaded version ($threads)" echo " --nothreads specify non-threaded version ($nothreads)" echo " --32|--64 specify 32/64-bit version ($bits)" @@ -1042,6 +1069,10 @@ else configuringin=" in $w" fi +if [ "$flagsm" != "$m" ] ; then + configuringin="$configuringin to run on $flagsm" +fi + if [ "$m" = "" ] ; then enableFrompb=no forceworkarea=no @@ -1113,6 +1144,7 @@ srcdir=$srcdir upsrcdir=$upsrcdir m=$m defaultm=$defaultm +flagsm=$flagsm mboot=$mboot buildKernelOnly=$buildKernelOnly enableFrompb=$enableFrompb