pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc



Module Name:    pkgsrc
Committed By:   riastradh
Date:           Fri Apr 12 19:53:25 UTC 2024

Modified Files:
        pkgsrc/doc: HOWTO-use-crosscompile
        pkgsrc/mk: bsd.prefs.mk
        pkgsrc/mk/tools: defaults.mk tools.NetBSD.mk
Added Files:
        pkgsrc/mk/tools: cross.NetBSD.mk

Log Message:
mk: New CROSS_* variable scheme for cross-compilation.

This change brings in support for cross-OS-compilation.

Caveat: Existing mk.conf files used for cross-compilation no longer
work; they must be adapted to the new scheme.

Under this new scheme, if an mk.conf variable X can be different for
native and cross builds like OPSYS, MACHINE_ARCH, LOCALBASE, &c., you
just define X in mk.conf to set it for native builds, and CROSS_X in
mk.conf to set it for cross builds.

Example:

    LOCALBASE=          /home/riastradh/pkgsrc/cross/pkg
    CROSS_LOCALBASE=    /opt/pkg
    CROSS_MACHINE_ARCH= powerpc

For now, _all_ OS-related variables must be defined in cross-builds;
none are filled in automatically.  For NetBSD, this means:

    CROSS_OPSYS=                NetBSD
    CROSS_OS_VERSION=           10.0
    CROSS_OPSYS_VERSION=        100000
    CROSS_LOWER_OPSYS=          netbsd
    CROSS_LOWER_OPSYS_VERSUFFIX=# empty
    CROSS_LOWER_OS_VARIANT=     # empty
    CROSS_LOWER_VARIANT_VERSION=# empty
    CROSS_LOWER_VENDOR=         # empty

This new scheme may raise make(1) costs by making a lot of variables
like OPSYS expand to conditionals rather than fixed strings.  It is
difficult to make these fixed strings because:

- they can only be committed _after_ mk.conf is loaded, before which
  USE_CROSS_COMPILE isn't yet determined, but

- the conditionals must be applied _before_ the rest of bsd.own.mk
  which uses these variables.

So we can't just have conditionals in bsd.prefs.mk after loading
bsd.own.mk -- we would need to put the conditionals in the middle of
bsd.own.mk between loading mk.conf and everything else.

As a followup commit, we can consider committing the variables after
bsd.own.mk as an optimization so that the conditional expansions are
only used inside bsd.own.mk and not in any other infrastructure.  Or
we can consider putting a hook inside bsd.own.mk for committing the
variables there too.  But let's see how this works out in practice
first.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 pkgsrc/doc/HOWTO-use-crosscompile
cvs rdiff -u -r1.439 -r1.440 pkgsrc/mk/bsd.prefs.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/mk/tools/cross.NetBSD.mk
cvs rdiff -u -r1.64 -r1.65 pkgsrc/mk/tools/defaults.mk
cvs rdiff -u -r1.74 -r1.75 pkgsrc/mk/tools/tools.NetBSD.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/doc/HOWTO-use-crosscompile
diff -u pkgsrc/doc/HOWTO-use-crosscompile:1.12 pkgsrc/doc/HOWTO-use-crosscompile:1.13
--- pkgsrc/doc/HOWTO-use-crosscompile:1.12      Tue Jun 27 10:27:20 2023
+++ pkgsrc/doc/HOWTO-use-crosscompile   Fri Apr 12 19:53:25 2024
@@ -1,7 +1,7 @@
 Cross-compilation in pkgsrc (user's guide)              -*- outline -*-
 Taylor R. Campbell <riastradh%NetBSD.org@localhost>
 
-$NetBSD: HOWTO-use-crosscompile,v 1.12 2023/06/27 10:27:20 riastradh Exp $
+$NetBSD: HOWTO-use-crosscompile,v 1.13 2024/04/12 19:53:25 riastradh Exp $
 
 The following steps enable you to build binary packages for a machine
 architecture other than the one you are building on.  For example, you
@@ -37,29 +37,27 @@ In addition to whatever else you want in
    # Cross-compile by default.
    #
    # XXX This currently can't be set to `yes' on the command line,
-   # which is a bug.
+   # which is a bug.  But it can be set to `no' to build native
+   # packages.
    USE_CROSS_COMPILE?=  yes
 
    # Point pkgsrc at the NetBSD tooldir and destdir.  These are used
    # only for cross-builds.
-   #
-   # XXX There is no obvious variable that is set to amd64 so that we
-   # could use
-   #
-   #    TOOLDIR=        /usr/obj/tooldir.${OPSYS}-${OS_VERSION}-${NATIVE_xyz}
-   #
-   # MACHINE is amd64 but, since it's not NATIVE_xyz, it's wrong.
-   # NATIVE_MACHINE_ARCH is x86_64, not amd64.
    TOOLDIR=             /usr/obj/tooldir.NetBSD-6.1-amd64
    CROSS_DESTDIR=       /usr/obj/destdir.evbppc
 
    # Specify the machine architecture of target packages.
-   #
-   # XXX This currently can't be set on the command line, which is a
-   # bug.
-   .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
-   MACHINE_ARCH=        powerpc
-   .endif
+   CROSS_MACHINE_ARCH=  powerpc
+
+   # Specify the OS of target packages.
+   CROSS_OPSYS=                NetBSD
+   CROSS_OS_VERSION=   10.0
+   CROSS_OPSYS_VERSION=        100000
+   CROSS_LOWER_OPSYS=   netbsd
+   CROSS_LOWER_OPSYS_VERSUFFIX= # empty
+   CROSS_LOWER_OS_VARIANT=      # empty
+   CROSS_LOWER_VARIANT_VERSION= # empty
+   CROSS_LOWER_VENDOR=          # empty
 
 Optionally, you can set CROSS_LOCALBASE for cross-compiled packages
 separately from LOCALBASE for natively compiled packages.  For example,
@@ -69,6 +67,9 @@ will create packages which install to /o
    LOCALBASE=          /home/user/cross/pkg
    CROSS_LOCALBASE=    /opt/pkg
 
+By default, CROSS_LOCALBASE will be /usr/pkg, meaning packages that are
+being cross-compiled will see LOCALBASE=/usr/pkg.
+
 ** Bootstrapped pkgsrc
 
 You can bootstrap pkgsrc or not; it shouldn't make a difference for
@@ -83,7 +84,7 @@ cross-compilation.  If you do:
    be left empty or undefined for earmv7hf cross-builds.  So you might
    need:
 
-      .if empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+      .if ${USE_CROSS_COMPILE:tl} != "yes"
       ABI=    64 # set for native amd64 build
       .else
       ABI=    # empty for earmv7hf cross-build

Index: pkgsrc/mk/bsd.prefs.mk
diff -u pkgsrc/mk/bsd.prefs.mk:1.439 pkgsrc/mk/bsd.prefs.mk:1.440
--- pkgsrc/mk/bsd.prefs.mk:1.439        Fri Jan 26 03:25:47 2024
+++ pkgsrc/mk/bsd.prefs.mk      Fri Apr 12 19:53:25 2024
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.prefs.mk,v 1.439 2024/01/26 03:25:47 riastradh Exp $
+# $NetBSD: bsd.prefs.mk,v 1.440 2024/04/12 19:53:25 riastradh Exp $
 #
 # This file includes the mk.conf file, which contains the user settings.
 #
@@ -87,23 +87,23 @@ UNAME=/run/current-system/sw/bin/uname
 UNAME=echo Unknown
 .endif
 
-.if !defined(OPSYS)
-OPSYS:=                        ${:!${UNAME} -s!:S/-//g:S/\///g:C/^CYGWIN_.*$/Cygwin/}
-MAKEFLAGS+=            OPSYS=${OPSYS:Q}
+.if !defined(NATIVE_OPSYS)
+NATIVE_OPSYS:=         ${:!${UNAME} -s!:S/-//g:S/\///g:C/^CYGWIN_.*$/Cygwin/}
+MAKEFLAGS+=            NATIVE_OPSYS=${NATIVE_OPSYS:Q}
 .endif
 
 # OS_VARIANT is used to differentiate operating systems which have a common
 # basis but offer contrasting environments, for example Linux distributions
 # or illumos forks.
-OS_VARIANT?=           # empty
+NATIVE_OS_VARIANT?=    # empty
 
 # The _CMD indirection allows code below to modify these values
 # without executing the commands at all.  Later, recursed make
 # invocations will skip these blocks entirely thanks to MAKEFLAGS.
-.if !defined(OS_VERSION)
-_OS_VERSION_CMD=       ${UNAME} -r
-OS_VERSION=            ${_OS_VERSION_CMD:sh}
-MAKEFLAGS+=            OS_VERSION=${OS_VERSION:Q}
+.if !defined(NATIVE_OS_VERSION)
+_NATIVE_OS_VERSION_CMD=        ${UNAME} -r
+NATIVE_OS_VERSION=     ${_NATIVE_OS_VERSION_CMD:sh}
+MAKEFLAGS+=            NATIVE_OS_VERSION=${NATIVE_OS_VERSION:Q}
 .endif
 
 #
@@ -112,11 +112,11 @@ MAKEFLAGS+=               OS_VERSION=${OS_VERSION:Q}
 # default command is likely correct for most OS, those that need to can set
 # it to a custom command in the later OPSYS-specific section.
 #
-.if !defined(OPSYS_VERSION)
-_OPSYS_VERSION_CMD=    ${UNAME} -r | \
+.if !defined(NATIVE_OPSYS_VERSION)
+_NATIVE_OPSYS_VERSION_CMD=     ${UNAME} -r | \
                        awk -F. '{major=int($$1); minor=int($$2); if (minor>=100) minor=99; patch=int($$3); if (patch>=100) patch=99; printf "%02d%02d%02d", major, minor, patch}'
-OPSYS_VERSION=         ${_OPSYS_VERSION_CMD:sh}
-MAKEFLAGS+=            OPSYS_VERSION=${OPSYS_VERSION:Q}
+NATIVE_OPSYS_VERSION=  ${_NATIVE_OPSYS_VERSION_CMD:sh}
+MAKEFLAGS+=            NATIVE_OPSYS_VERSION=${NATIVE_OPSYS_VERSION:Q}
 .endif
 
 # Preload these for architectures not in all variations of bsd.own.mk,
@@ -155,194 +155,244 @@ MACHINE_GNU_ARCH?=              ${GNU_ARCH.${MACHINE
 
 ## If changes are made to how OS_VERSION is set below please keep
 ## "pkgsrc/pkgtools/osabi/INSTALL" in-sync.
-.if ${OPSYS} == "NetBSD"
-LOWER_OPSYS?=          netbsd
+.if ${NATIVE_OPSYS} == "NetBSD"
+NATIVE_LOWER_OPSYS?=   netbsd
 
-.elif ${OPSYS} == "AIX"
+.elif ${NATIVE_OPSYS} == "AIX"
 .  if exists(/usr/bin/oslevel)
-_OS_VERSION!=          /usr/bin/oslevel
+_NATIVE_OS_VERSION!=   /usr/bin/oslevel
 .  else
-_OS_VERSION!=          echo `${UNAME} -v`.`${UNAME} -r`
+_NATIVE_OS_VERSION!=   echo `${UNAME} -v`.`${UNAME} -r`
 .  endif
-OS_VERSION=            ${_OS_VERSION:C/([0-9]*\.[0-9]*).*/\1/}
-LOWER_OPSYS_VERSUFFIX= ${_OS_VERSION}
-LOWER_OPSYS?=          aix
-LOWER_VENDOR?=         ibm
-
-.elif ${OPSYS} == "BSDOS"
-LOWER_OPSYS?=          bsdi
-
-.elif ${OPSYS} == "Cygwin"
-LOWER_OPSYS?=          cygwin
-LOWER_VENDOR?=         pc
-_OS_VERSION!=          ${UNAME} -r
-OS_VERSION=            ${_OS_VERSION:C/\(.*\)//}
-OS_VARIANT!=           ${UNAME} -s
-
-.elif ${OPSYS} == "Darwin"
-LOWER_OPSYS?=          darwin
-LOWER_OPSYS_VERSUFFIX= ${OS_VERSION:C/([0-9]*).*/\1/}
-LOWER_VENDOR?=         apple
-_OPSYS_VERSION_CMD=    sw_vers -productVersion | \
+NATIVE_OS_VERSION=             ${_NATIVE_OS_VERSION:C/([0-9]*\.[0-9]*).*/\1/}
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${_NATIVE_OS_VERSION}
+NATIVE_LOWER_OPSYS?=           aix
+NATIVE_LOWER_VENDOR?=          ibm
+
+.elif ${NATIVE_OPSYS} == "BSDOS"
+NATIVE_LOWER_OPSYS?=   bsdi
+
+.elif ${NATIVE_OPSYS} == "Cygwin"
+NATIVE_LOWER_OPSYS?=   cygwin
+NATIVE_LOWER_VENDOR?=  pc
+_NATIVE_OS_VERSION!=   ${UNAME} -r
+NATIVE_OS_VERSION=     ${_NATIVE_OS_VERSION:C/\(.*\)//}
+NATIVE_OS_VARIANT!=    ${UNAME} -s
+
+.elif ${NATIVE_OPSYS} == "Darwin"
+NATIVE_LOWER_OPSYS?=           darwin
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${NATIVE_OS_VERSION:C/([0-9]*).*/\1/}
+NATIVE_LOWER_VENDOR?=          apple
+_NATIVE_OPSYS_VERSION_CMD=     sw_vers -productVersion | \
                        awk -F. '{major=int($$1); minor=int($$2); if (minor>=100) minor=99; patch=int($$3); if (patch>=100) patch=99; printf "%02d%02d%02d", major, minor, patch}'
 
-.elif ${OPSYS} == "DragonFly"
-OS_VERSION:=           ${OS_VERSION:C/-.*$//}
-LOWER_OPSYS?=          dragonfly
-LOWER_VENDOR?=         pc
-
-.elif ${OPSYS} == "FreeBSD"
-OS_VERSION:=           ${OS_VERSION:C/-.*$//}
-LOWER_OPSYS?=          freebsd
-LOWER_OPSYS_VERSUFFIX= ${OS_VERSION:C/([0-9]*).*/\1/}
+.elif ${NATIVE_OPSYS} == "DragonFly"
+NATIVE_OS_VERSION:=    ${NATIVE_OS_VERSION:C/-.*$//}
+NATIVE_LOWER_OPSYS?=   dragonfly
+NATIVE_LOWER_VENDOR?=  pc
+
+.elif ${NATIVE_OPSYS} == "FreeBSD"
+NATIVE_OS_VERSION:=            ${OS_VERSION:C/-.*$//}
+NATIVE_LOWER_OPSYS?=           freebsd
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${OS_VERSION:C/([0-9]*).*/\1/}
 .  if ${MACHINE_ARCH} == "i386"
-LOWER_VENDOR?=         pc
+NATIVE_LOWER_VENDOR?=          pc
 .  endif
-LOWER_VENDOR?=         unknown
+NATIVE_LOWER_VENDOR?=          unknown
 
-.elif ${OPSYS} == "Haiku"
-LOWER_OPSYS?=          haiku
-.  if ${MACHINE_ARCH} == "i386"
-LOWER_VENDOR?=         pc
+.elif ${NATIVE_OPSYS} == "Haiku"
+NATIVE_LOWER_OPSYS?=           haiku
+.  if ${NATIVE_MACHINE_ARCH} == "i386"
+NATIVE_LOWER_VENDOR?=          pc
 .  endif
 
-.elif ${OPSYS} == "Interix"
-LOWER_OPSYS?=          interix
-LOWER_VENDOR?=         pc
+.elif ${NATIVE_OPSYS} == "Interix"
+NATIVE_LOWER_OPSYS?=           interix
+NATIVE_LOWER_VENDOR?=          pc
 .  if exists(/usr/lib/libc.so.5.2) || exists(/usr/lib/x86/libc.so.5.2)
-LOWER_OPSYS_VERSUFFIX= ${OS_VERSION:C/([0-9]*).*/\1/}
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${NATIVE_OS_VERSION:C/([0-9]*).*/\1/}
 .  else
-LOWER_OPSYS_VERSUFFIX?=        3
+NATIVE_LOWER_OPSYS_VERSUFFIX?= 3
 .    if exists(/usr/lib/libc.so.3.5)
-OS_VERSION=            3.5
+NATIVE_OS_VERSION=             3.5
 .    elif exists(/usr/lib/libc.so.3.1)
-OS_VERSION=            3.1
+NATIVE_OS_VERSION=             3.1
 .    else
-OS_VERSION=            3.0
+NATIVE_OS_VERSION=             3.0
 .    endif
 .  endif
 
-.elif ${OPSYS} == "MirBSD"
-LOWER_OPSYS?=          mirbsd
-LOWER_OPSYS_VERSUFFIX= ${OS_VERSION}
-LOWER_VENDOR?=         unknown
-
-.elif !empty(OPSYS:MIRIX*)
-LOWER_OPSYS?=          irix
-LOWER_OPSYS_VERSUFFIX?=        ${OS_VERSION}
-LOWER_VENDOR?=         sgi
-
-.elif ${OPSYS} == "Linux"
-OS_VERSION:=           ${OS_VERSION:C/-.*$//}
-LOWER_OPSYS?=          linux
+.elif ${NATIVE_OPSYS} == "MirBSD"
+NATIVE_LOWER_OPSYS?=           mirbsd
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${NATIVE_OS_VERSION}
+NATIVE_LOWER_VENDOR?=          unknown
+
+.elif !empty(NATIVE_OPSYS:MIRIX*)
+NATIVE_LOWER_OPSYS?=           irix
+NATIVE_LOWER_OPSYS_VERSUFFIX?= ${NATIVE_OS_VERSION}
+NATIVE_LOWER_VENDOR?=          sgi
+
+.elif ${NATIVE_OPSYS} == "Linux"
+NATIVE_OS_VERSION:=            ${NATIVE_OS_VERSION:C/-.*$//}
+NATIVE_LOWER_OPSYS?=           linux
 .  if exists(/etc/lsb-release)
 CHROMEOS_RELEASE_NAME!=        awk -F = '$$1 == "CHROMEOS_RELEASE_NAME" { print $$2 }' /etc/lsb-release
 .  endif
 .  if exists(/etc/debian_version)
-LOWER_VENDOR?=         debian
+NATIVE_LOWER_VENDOR?=          debian
 .  elif exists(/etc/mandrake-release)
-LOWER_VENDOR?=         mandrake
+NATIVE_LOWER_VENDOR?=          mandrake
 .  elif exists(/etc/redhat-version) || exists(/etc/redhat-release)
-LOWER_VENDOR?=         redhat
+NATIVE_LOWER_VENDOR?=          redhat
 .  elif exists(/etc/slackware-version)
-LOWER_VENDOR?=         slackware
+NATIVE_LOWER_VENDOR?=          slackware
 .  elif exists(/etc/ssdlinux_version)
-LOWER_VENDOR?=         ssd
+NATIVE_LOWER_VENDOR?=          ssd
 .  elif !empty(CHROMEOS_RELEASE_NAME)
-LOWER_VENDOR?=         chromeos
-.  elif ${MACHINE_ARCH} == "i386"
-LOWER_VENDOR?=          pc
-.  endif
-LOWER_VENDOR?=          unknown
-OS_VARIANT!=           ${UNAME} -r
-OS_VARIANT:=           ${OS_VARIANT:C/^.*-//}
-.  if ${OS_VARIANT} != "Microsoft"
-OS_VARIANT=            ${LOWER_VENDOR}
+NATIVE_LOWER_VENDOR?=          chromeos
+.  elif ${NATIVE_MACHINE_ARCH} == "i386"
+NATIVE_LOWER_VENDOR?=          pc
+.  endif
+NATIVE_LOWER_VENDOR?=          unknown
+NATIVE_OS_VARIANT!=            ${UNAME} -r
+NATIVE_OS_VARIANT:=            ${NATIVE_OS_VARIANT:C/^.*-//}
+.  if ${NATIVE_OS_VARIANT} != "Microsoft"
+NATIVE_OS_VARIANT=             ${NATIVE_LOWER_VENDOR}
 .  endif
+# XXX NATIVE_HOST_MACHINE_ARCH?  ???
 .  if !defined(HOST_MACHINE_ARCH)
 HOST_MACHINE_ARCH!=    ${UNAME} -m
 MAKEFLAGS+=            HOST_MACHINE_ARCH=${HOST_MACHINE_ARCH:Q}
 .  endif
 
-.elif ${OPSYS} == "OpenBSD"
-LOWER_OPSYS?=          openbsd
+.elif ${NATIVE_OPSYS} == "OpenBSD"
+NATIVE_LOWER_OPSYS?=           openbsd
 
-.elif ${OPSYS} == "OSF1"
-OS_VERSION:=           ${OS_VERSION:C/^V//}
-LOWER_OPSYS?=          osf1
-LOWER_OPSYS_VERSUFFIX?=        ${OS_VERSION}
-LOWER_VENDOR?=         dec
-
-.elif ${OPSYS} == "HPUX"
-OS_VERSION:=           ${OS_VERSION:C/^B.//}
-LOWER_OPSYS?=          hpux
-LOWER_OPSYS_VERSUFFIX?=        ${OS_VERSION}
-LOWER_VENDOR?=         hp
-
-.elif ${OPSYS} == "SunOS"
-LOWER_VENDOR?=         sun
-LOWER_OPSYS?=          solaris
-LOWER_OPSYS_VERSUFFIX= 2.${OS_VERSION:C/5.//}
+.elif ${NATIVE_OPSYS} == "OSF1"
+NATIVE_OS_VERSION:=            ${NATIVE_OS_VERSION:C/^V//}
+NATIVE_LOWER_OPSYS?=           osf1
+NATIVE_LOWER_OPSYS_VERSUFFIX?= ${NATIVE_OS_VERSION}
+NATIVE_LOWER_VENDOR?=          dec
+
+.elif ${NATIVE_OPSYS} == "HPUX"
+NATIVE_OS_VERSION:=            ${NATIVE_OS_VERSION:C/^B.//}
+NATIVE_LOWER_OPSYS?=           hpux
+NATIVE_LOWER_OPSYS_VERSUFFIX?= ${NATIVE_OS_VERSION}
+NATIVE_LOWER_VENDOR?=          hp
+
+.elif ${NATIVE_OPSYS} == "SunOS"
+NATIVE_LOWER_VENDOR?=          sun
+NATIVE_LOWER_OPSYS?=           solaris
+NATIVE_LOWER_OPSYS_VERSUFFIX=  2.${NATIVE_OS_VERSION:C/5.//}
 .  if !defined(_UNAME_V)
 _UNAME_V!=             ${UNAME} -v
 MAKEFLAGS+=            _UNAME_V=${_UNAME_V:Q}
 .  endif
 .  if !empty(_UNAME_V:Mjoyent_*)
-OS_VARIANT=            SmartOS
-LOWER_VARIANT_VERSION= ${_UNAME_V:C/joyent_//}
+NATIVE_OS_VARIANT=             SmartOS
+NATIVE_LOWER_VARIANT_VERSION=  ${_UNAME_V:C/joyent_//}
 .  elif !empty(_UNAME_V:Momnios-*)
-OS_VARIANT=            OmniOS
-LOWER_VARIANT_VERSION!=        /usr/bin/awk '{ print $$3; exit 0; }' /etc/release
+NATIVE_OS_VARIANT=             OmniOS
+NATIVE_LOWER_VARIANT_VERSION!= /usr/bin/awk '{ print $$3; exit 0; }' /etc/release
 .  elif !empty(_UNAME_V:Mtribblix-*)
-OS_VARIANT=            Tribblix
-LOWER_VARIANT_VERSION!=        /usr/bin/awk '{ print $$2; exit 0; }' /etc/release
+NATIVE_OS_VARIANT=             Tribblix
+NATIVE_LOWER_VARIANT_VERSION!= /usr/bin/awk '{ print $$2; exit 0; }' /etc/release
 .  else
-OS_VARIANT=            Solaris
-LOWER_VARIANT_VERSION= ${_UNAME_V}
+NATIVE_OS_VARIANT=             Solaris
+NATIVE_LOWER_VARIANT_VERSION=  ${_UNAME_V}
 .  endif
 
 .elif ${OPSYS} == "SCO_SV"
-SCO_RELEASE!=          ${UNAME} -r
-SCO_VERSION!=          ${UNAME} -v
-LOWER_VENDOR?=         pc
-LOWER_OPSYS?=          sco
-LOWER_OPSYS_VERSUFFIX= ${SCO_RELEASE}v${SCO_VERSION}
-_UNAME_V!=             ${UNAME} -v
+SCO_RELEASE!=                  ${UNAME} -r
+SCO_VERSION!=                  ${UNAME} -v
+NATIVE_LOWER_VENDOR?=          pc
+NATIVE_LOWER_OPSYS?=           sco
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${SCO_RELEASE}v${SCO_VERSION}
+_UNAME_V!=                     ${UNAME} -v
 .  if !empty(_UNAME_V:M5.0*)
-OS_VARIANT=            SCOOSR5
+NATIVE_OS_VARIANT=             SCOOSR5
 .  elif !empty(_UNAME_V:M6.0*)
-OS_VARIANT=            SCOOSR6
+NATIVE_OS_VARIANT=             SCOOSR6
 .  endif
 
-.elif ${OPSYS} == "UnixWare"
-SCO_RELEASE?=          sysv5${OPSYS}
-SCO_VERSION!=          ${UNAME} -v
-LOWER_VENDOR?=         unknown
-LOWER_OPSYS_VERSUFFIX= ${SCO_RELEASE}${SCO_VERSION}
+.elif ${NATIVE_OPSYS} == "UnixWare"
+SCO_RELEASE?=                  sysv5${NATIVE_OPSYS}
+SCO_VERSION!=                  ${UNAME} -v
+NATIVE_LOWER_VENDOR?=          unknown
+NATIVE_LOWER_OPSYS_VERSUFFIX=  ${SCO_RELEASE}${SCO_VERSION}
 
-.elif ${OPSYS} == "Minix"
-LOWER_VENDOR?=         unknown
-LOWER_OPSYS:=          ${OPSYS:tl}
+.elif ${NATIVE_OPSYS} == "Minix"
+NATIVE_LOWER_VENDOR?=          unknown
+NATIVE_LOWER_OPSYS:=           ${NATIVE_OPSYS:tl}
 
-.elif !defined(LOWER_OPSYS)
-LOWER_OPSYS:=          ${OPSYS:tl}
+.elif !defined(NATIVE_LOWER_OPSYS)
+NATIVE_LOWER_OPSYS:=           ${NATIVE_OPSYS:tl}
 .endif
 
 # Now commit the version values computed above, eliding the :sh
-OS_VERSION:=           ${OS_VERSION}
+NATIVE_OS_VERSION:=    ${NATIVE_OS_VERSION}
 
-MAKEFLAGS+=            LOWER_OPSYS=${LOWER_OPSYS:Q}
+MAKEFLAGS+=            NATIVE_LOWER_OPSYS=${NATIVE_LOWER_OPSYS:Q}
 
-LOWER_VENDOR?=                 # empty ("arch--opsys")
+NATIVE_LOWER_VENDOR?=  # empty ("arch--opsys")
 
+# List of variables that must be set to determine a cross-compilation
+# target.
+CROSSVARS?=    # empty
+
+# Cross-compilation target settings.
+#
+# We set these to have conditional expansions so that when <bsd.own.mk>
+# includes mk.conf, and mk.conf sets USE_CROSS_COMPILE, the _rest_ of
+# <bsd.own.mk> gets the right cross vs native versions of the
+# variables.
+#
+# As soon as <bsd.own.mk> is done we can commit the switcheroo without
+# the conditional expansions -- but there's no hook to do that inside
+# <bsd.own.mk> between inclusion of mk.conf and the rest of
+# <bsdf.own.mk>.  And there's no way to know, before we include
+# mk.conf, whether the user _might_ be doing cross-builds.  So we have
+# to use this massive kludge.
+#
+CROSSVARS+=    OPSYS
+OPSYS=                 \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_OPSYS}:${NATIVE_OPSYS}}
+CROSSVARS+=    OS_VERSION
+OS_VERSION=            \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_OS_VERSION}:${NATIVE_OS_VERSION}}
+CROSSVARS+=    OPSYS_VERSION
+OPSYS_VERSION=         \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_OPSYS_VERSION}:${NATIVE_OPSYS_VERSION}}
+CROSSVARS+=    LOWER_OPSYS
+LOWER_OPSYS=           \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_LOWER_OPSYS}:${NATIVE_LOWER_OPSYS}}
+CROSSVARS+=    LOWER_OPSYS_VERSUFFIX
+LOWER_OPSYS_VERSUFFIX= \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_LOWER_OPSYS_VERSUFFIX}:${NATIVE_LOWER_OPSYS_VERSUFFIX}}
+CROSSVARS+=    LOWER_VARIANT_VERSION
+LOWER_VARIANT_VERSION= \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_LOWER_VARIANT_VERSION}:${NATIVE_LOWER_VARIANT_VERSION}}
+CROSSVARS+=    LOWER_VENDOR
+LOWER_VENDOR=          \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_LOWER_VENDOR}:${NATIVE_LOWER_VENDOR}}
+CROSSVARS+=    LOWER_OS_VARIANT
+OS_VARIANT=            \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_OS_VARIANT}:${NATIVE_OS_VARIANT}}
+
+# Remember the MACHINE_ARCH that make was built with before we override
+# it with CROSS_MACHINE_ARCH if USE_CROSS_COMPILE is enabled.
+CROSSVARS+=    MACHINE_ARCH
 NATIVE_MACHINE_ARCH:=          ${MACHINE_ARCH}
+
 NATIVE_MACHINE_PLATFORM?=      ${OPSYS}-${OS_VERSION}-${NATIVE_MACHINE_ARCH}
 MACHINE_PLATFORM?=             ${OPSYS}-${OS_VERSION}-${MACHINE_ARCH}
-NATIVE_MACHINE_GNU_PLATFORM?=  ${NATIVE_MACHINE_GNU_ARCH}-${LOWER_VENDOR}-${LOWER_OPSYS:C/[0-9]//g}${NATIVE_APPEND_ELF}${LOWER_OPSYS_VERSUFFIX}${NATIVE_APPEND_ABI}
+NATIVE_MACHINE_GNU_PLATFORM?=  ${NATIVE_MACHINE_GNU_ARCH}-${NATIVE_LOWER_VENDOR}-${NATIVE_LOWER_OPSYS:C/[0-9]//g}${NATIVE_APPEND_ELF}${NATIVE_LOWER_OPSYS_VERSUFFIX}${NATIVE_APPEND_ABI}
 MACHINE_GNU_PLATFORM?=         ${MACHINE_GNU_ARCH}-${LOWER_VENDOR}-${LOWER_OPSYS:C/[0-9]//g}${APPEND_ELF}${LOWER_OPSYS_VERSUFFIX}${APPEND_ABI}
 
 # Set this before <bsd.own.mk> does, since it doesn't know about Darwin
-.if ${OPSYS} == "Darwin"
+# We will later set OBJECT_FMT to be conditional on USE_CROSS_COMPILE.
+.if ${NATIVE_OPSYS} == "Darwin"
+NATIVE_OBJECT_FMT?=    Mach-O
 OBJECT_FMT?=           Mach-O
 .endif
 
@@ -368,6 +418,9 @@ PKG_FAIL_REASON+=   "Must set TARGET_ARCH 
 MACHINE_ARCH:=                 ${TARGET_ARCH}
 _BUILD_DEFS.MACHINE_ARCH=      ${NATIVE_MACHINE_ARCH}
 _BUILD_DEFS.MACHINE_GNU_ARCH=  ${NATIVE_MACHINE_GNU_ARCH}
+_BUILD_DEFS.OBJECT_FMT=                ${NATIVE_OBJECT_FMT}
+_BUILD_DEFS.OPSYS=             ${NATIVE_OPSYS}
+_BUILD_DEFS.OS_VERSION=                ${NATIVE_OS_VERSION}
 TOOLS_USE_CROSS_COMPILE=       yes
 .else
 TOOLS_USE_CROSS_COMPILE=       ${USE_CROSS_COMPILE:Uno}
@@ -389,9 +442,17 @@ PKGPATH?=          ${.CURDIR:C|.*/([^/]*/[^/]*)$
 # Load the settings from MAKECONF, which is /etc/mk.conf by default.
 .include <bsd.own.mk>
 
+# Save the OBJECT_FMT determined by bsd.own.mk, and turn OBJECT_FMT
+# into a cross-compilation variable so it can be overridden by
+# CROSS_OBJECT_FMT.
+NATIVE_OBJECT_FMT:=    ${OBJECT_FMT}
+CROSSVARS+=            OBJECT_FMT
+OBJECT_FMT=            \
+       ${"${USE_CROSS_COMPILE:U:tl}" == "yes":?${CROSS_OBJECT_FMT}:${NATIVE_OBJECT_FMT}}
+
 # When cross-compilation support is requested, the following options
 # must be specified as well or guessable:
-# - MACHINE_ARCH is set to TARGET_ARCH if set.
+# - Variables like MACHINE_ARCH are set to CROSS_MACHINE_ARCH.
 # - CROSS_DESTDIR is guessed from MAKEOBJDIR and MACHINE_ARCH.
 # - PKG_DBDIR is expanded and prefixed with CROSS_DESTDIR
 # - DESTDIR support is required
@@ -399,9 +460,16 @@ PKGPATH?=          ${.CURDIR:C|.*/([^/]*/[^/]*)$
 # _CROSS_DESTDIR is set for internal use to avoid conditionalising
 # the use.
 
-.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
-.  if defined(TARGET_ARCH)
-MACHINE_ARCH=  ${TARGET_ARCH}
+.if ${USE_CROSS_COMPILE:U:tl} == "yes" # defaults/mk.conf not yet loaded, so :U
+.  for _v_ in ${CROSSVARS}
+.    ifndef CROSS_${_v_}
+MISSING_CROSSVARS=     yes
+.      warning Missing CROSS_${_v_} setting
+.    endif
+${_v_}:=       ${CROSS_${_v_}}
+.  endfor
+.  ifdef MISSING_CROSSVARS
+.    error USE_CROSS_COMPILE=yes but missing cross variable settings
 .  endif
 CROSS_DESTDIR?=        ${MAKEOBJDIR}/destdir.${MACHINE_ARCH}
 .  if !exists(${CROSS_DESTDIR}/usr/include/stddef.h)
@@ -562,9 +630,6 @@ TOOLS_CROSS_DESTDIR=                # empty
 
 # Depends on MACHINE_ARCH override above
 .if ${OPSYS} == "NetBSD"
-# XXX NATIVE_OBJECT_FMT is a cop-out -- but seriously, who is going to
-# do cross-builds on a NetBSD host that still uses a.out?
-NATIVE_OBJECT_FMT?=    ${OBJECT_FMT}
 .  if ${NATIVE_OBJECT_FMT} == "ELF" && \
    (!empty(NATIVE_MACHINE_ARCH:Mearm*) || \
     ${NATIVE_MACHINE_GNU_ARCH} == "arm" || \

Index: pkgsrc/mk/tools/defaults.mk
diff -u pkgsrc/mk/tools/defaults.mk:1.64 pkgsrc/mk/tools/defaults.mk:1.65
--- pkgsrc/mk/tools/defaults.mk:1.64    Tue May  9 12:16:01 2023
+++ pkgsrc/mk/tools/defaults.mk Fri Apr 12 19:53:25 2024
@@ -1,4 +1,4 @@
-# $NetBSD: defaults.mk,v 1.64 2023/05/09 12:16:01 thor Exp $
+# $NetBSD: defaults.mk,v 1.65 2024/04/12 19:53:25 riastradh Exp $
 #
 # Copyright (c) 2005 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -34,10 +34,17 @@ TOOLS_DEFAULTS_MK=  defined
 # These are the platform-specific lists of system-supplied tools.
 #
 # XXX These should eventually just migrate over to the appropriate
-# XXX pkgsrc/mk/platform/${OPSYS}.mk file.
+# XXX pkgsrc/mk/platform/${NATIVE_OPSYS}.mk file.
 #
-.if exists(${_PKGSRC_TOPDIR}/mk/tools/tools.${OPSYS}.mk)
-.  include "${_PKGSRC_TOPDIR}/mk/tools/tools.${OPSYS}.mk"
+# XXX Use ${OPSYS} for :run tools, but ${NATIVE_OPSYS} for :build and
+# XXX :bootstrap tools.
+#
+.if ${TOOLS_USE_CROSS_COMPILE:tl} == "yes" && \
+    exists(${_PKGSRC_TOPDIR}/mk/tools/cross.${OPSYS}.mk)
+.  include "${_PKGSRC_TOPDIR}/mk/tools/cross.${OPSYS}.mk"
+.endif
+.if exists(${_PKGSRC_TOPDIR}/mk/tools/tools.${NATIVE_OPSYS}.mk)
+.  include "${_PKGSRC_TOPDIR}/mk/tools/tools.${NATIVE_OPSYS}.mk"
 .endif
 
 ######################################################################

Index: pkgsrc/mk/tools/tools.NetBSD.mk
diff -u pkgsrc/mk/tools/tools.NetBSD.mk:1.74 pkgsrc/mk/tools/tools.NetBSD.mk:1.75
--- pkgsrc/mk/tools/tools.NetBSD.mk:1.74        Tue May  9 12:16:01 2023
+++ pkgsrc/mk/tools/tools.NetBSD.mk     Fri Apr 12 19:53:25 2024
@@ -1,4 +1,4 @@
-# $NetBSD: tools.NetBSD.mk,v 1.74 2023/05/09 12:16:01 thor Exp $
+# $NetBSD: tools.NetBSD.mk,v 1.75 2024/04/12 19:53:25 riastradh Exp $
 #
 # System-supplied tools for the NetBSD operating system.
 
@@ -58,11 +58,7 @@ TOOLS_PLATFORM.head?=                /usr/bin/head
 TOOLS_PLATFORM.hostname?=      /bin/hostname
 TOOLS_PLATFORM.id?=            /usr/bin/id
 TOOLS_PLATFORM.ident?=         /usr/bin/ident
-.if ${TOOLS_USE_CROSS_COMPILE:tl} != yes
 TOOLS_PLATFORM.install?=       /usr/bin/install
-.else
-TOOLS_PLATFORM.install?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-install
-.endif
 .if exists(/usr/bin/install-info)
 TOOLS_PLATFORM.install-info?=  /usr/bin/install-info
 .endif
@@ -102,11 +98,7 @@ TOOLS_PLATFORM.paxctl?=             /usr/sbin/paxct
 .endif
 TOOLS_PLATFORM.printf?=                /usr/bin/printf
 TOOLS_PLATFORM.pwd?=           /bin/pwd
-.if ${TOOLS_USE_CROSS_COMPILE:U:tl} != yes
 TOOLS_PLATFORM.readelf?=       /usr/bin/readelf
-.else
-TOOLS_PLATFORM.readelf?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-readelf
-.endif
 TOOLS_PLATFORM.readlink?=      /usr/bin/readlink
 .if exists(/usr/bin/realpath)
 TOOLS_PLATFORM.realpath?=      /usr/bin/realpath
@@ -120,11 +112,7 @@ TOOLS_PLATFORM.shlock?=            /usr/bin/shlock
 TOOLS_PLATFORM.sleep?=         /bin/sleep
 TOOLS_PLATFORM.soelim?=                /usr/bin/soelim
 TOOLS_PLATFORM.sort?=          /usr/bin/sort
-.if ${TOOLS_USE_CROSS_COMPILE:U:tl} != yes
 TOOLS_PLATFORM.strip?=         /usr/bin/strip
-.else
-TOOLS_PLATFORM.strip?=         ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-strip
-.endif
 
 TOOLS_PLATFORM.tail?=          /usr/bin/tail
 .if exists(/bin/tar)
@@ -157,29 +145,9 @@ TOOLS_PLATFORM.xzcat?=             /usr/bin/xzcat
 TOOLS_PLATFORM.yacc?=          /usr/bin/yacc
 
 .if ${TOOLS_USE_CROSS_COMPILE:U:tl} == yes
-.  for _t_ in ar as ld nm objcopy objdump ranlib readelf strip
-TOOLS_PATH.${MACHINE_GNU_PLATFORM}-${_t_}?=    \
-       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-${_t_}
-TOOLS_CREATE+= ${MACHINE_GNU_PLATFORM}-${_t_}
-.  endfor
-
-TOOLS_PATH.ar?=                ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ar
-TOOLS_CREATE+=                 ar
-TOOLS_PATH.ranlib?=            ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ranlib
-TOOLS_CREATE+=                 ranlib
-TOOLS_PATH.readelf?=           ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-readelf
-TOOLS_CREATE+=                 readelf
-
 NATIVE_CC:=    /usr/bin/cc -B /usr/libexec -B /usr/bin
-CC=            ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-gcc
-
 NATIVE_CXX:=   /usr/bin/c++ -B /usr/libexec -B /usr/bin
-CXX=           ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-g++
-
 NATIVE_LD:=    /usr/bin/ld
-LD=            ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ld
-
 NATIVE_AR:=    /usr/bin/ar
 NATIVE_RANLIB:=        /usr/bin/ranlib
-
 .endif

Added files:

Index: pkgsrc/mk/tools/cross.NetBSD.mk
diff -u /dev/null pkgsrc/mk/tools/cross.NetBSD.mk:1.1
--- /dev/null   Fri Apr 12 19:53:25 2024
+++ pkgsrc/mk/tools/cross.NetBSD.mk     Fri Apr 12 19:53:25 2024
@@ -0,0 +1,25 @@
+# $NetBSD: cross.NetBSD.mk,v 1.1 2024/04/12 19:53:25 riastradh Exp $
+#
+# Cross-compiler toolchain for the NetBSD operating system.  Requires
+# TOOLDIR to match build.sh for a NetBSD build.
+
+TOOLS_PLATFORM.install?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-install
+TOOLS_PLATFORM.readelf?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-readelf
+TOOLS_PLATFORM.strip?=         ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-strip
+
+.for _t_ in ar as ld nm objcopy objdump ranlib readelf strip
+TOOLS_PATH.${MACHINE_GNU_PLATFORM}-${_t_}?=    \
+       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-${_t_}
+TOOLS_CREATE+= ${MACHINE_GNU_PLATFORM}-${_t_}
+.endfor
+
+TOOLS_PATH.ar?=                ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ar
+TOOLS_CREATE+=                 ar
+TOOLS_PATH.ranlib?=            ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ranlib
+TOOLS_CREATE+=                 ranlib
+TOOLS_PATH.readelf?=           ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-readelf
+TOOLS_CREATE+=                 readelf
+
+CC=            ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-gcc
+CXX=           ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-g++
+LD=            ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ld



Home | Main Index | Thread Index | Old Index