pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc mk: Cross-eyed hacks to support cross-libtool.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/2a5a30b56388
branches:  trunk
changeset: 376281:2a5a30b56388
user:      riastradh <riastradh%pkgsrc.org@localhost>
date:      Mon Apr 04 11:23:06 2022 +0000

description:
mk: Cross-eyed hacks to support cross-libtool.

For a long time, when cross-building, say from native=amd64 to
target=powerpc, it was necessary to:

1. cross-build a _powerpc_ package called cross-libtool-base-powerpc,
   and then

2. install the powerpc package _natively_ with `pkg_add -m x86_64' to
   override the architecture check that normally forbids this kind of
   shenanigans,

in order to cross-build anything that uses libtool as a tool.

This is partly because libtool doesn't follow the normal GNU
convention of `./configure --build=<native platform> --host=<platform
package will run on> --target=<platform package is configured to
operate on>' -- in this example, build=amd64, host=amd64,
target=powerpc.

Instead, libtool expects to be cross-built itself, even if it's going
to run as a tool.  It's not as bonkers as it sounds at first: libtool
is just a shell script, and it caches various information about the
(cross-building!) toolchain it is built with so it can use that
information later when it is run as a tool itself to cross-compile
other software.

To make this work, we need to create the toolchain wrappers for
libtool _as if_ we were cross-building even if we are building a
native package.  So mk/tools uses a new flag TOOLS_USE_CROSS_COMPILE
instead of USE_CROSS_COMPILE, and libtool internally sets
MACHINE_ARCH=${TARGET_ARCH} (in the example above, powerpc) to make
it look like we're cross-building.  The new TOOLS_CROSS_DESTDIR is an
alias for the (defaulted) CROSS_DESTDIR, which must now be set
unconditionally in mk.conf in order for libtool to know where the
cross-destdir will be; _CROSS_DESTDIR remains empty when building any
native packages (including the native cross-libtool package).

Finally, we need to make the resulting package be a native package,
with MACHINE_ARCH set to the one that it will be installed on (in the
example above, amd64), so I added an indirection _BUILD_DEFS.${var}
to replace var on its own in the build definitions that get baked
into the package, shown by `pkg_info -B'.  Setting
_BUILD_DEFS.MACHINE_ARCH=${NATIVE_MACHINE_ARCH} ensures that this
mutant hybrid cross-built libtool still produces a native package.

All of this logic is gated on setting USE_CROSS_COMPILE in mk.conf or
LIBTOOL_CROSS_COMPILE in the package makefile, so it should be safe
for non-cross-builds -- when USE_CROSS_COMPILE=no and you're not
building cross-libtool, everything is as before.

diffstat:

 cross/cross-libtool-base/Makefile |   6 ++++--
 doc/HOWTO-use-crosscompile        |  35 ++++++++++-------------------------
 mk/bsd.prefs.mk                   |  34 +++++++++++++++++++++++++++++++++-
 mk/compiler/gcc.mk                |   4 ++--
 mk/configure/gnu-configure.mk     |   4 ++--
 mk/cwrappers.mk                   |   8 ++++----
 mk/pkgformat/pkg/metadata.mk      |   4 ++--
 mk/tools/tools.FreeMiNT.mk        |  10 +++++-----
 mk/tools/tools.Minix.mk           |  10 +++++-----
 mk/tools/tools.NetBSD.mk          |  10 +++++-----
 mk/tools/tools.QNX.mk             |   8 ++++----
 mk/wrapper/bsd.wrapper.mk         |   8 ++++----
 x11/libdrm/Makefile               |   4 ++--
 13 files changed, 82 insertions(+), 63 deletions(-)

diffs (truncated from 448 to 300 lines):

diff -r 3b8309209242 -r 2a5a30b56388 cross/cross-libtool-base/Makefile
--- a/cross/cross-libtool-base/Makefile Mon Apr 04 11:22:50 2022 +0000
+++ b/cross/cross-libtool-base/Makefile Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.5 2021/05/24 19:49:26 wiz Exp $
+# $NetBSD: Makefile,v 1.6 2022/04/04 11:23:06 riastradh Exp $
 
 # XXX This is kludgerific copypasta of devel/libtool-base/Makefile for
 # cross-compilation.  Please make it go away!
@@ -31,12 +31,14 @@
 ###########################################################################
 ###########################################################################
 
+LIBTOOL_CROSS_COMPILE= yes
+
 .include "../../devel/libtool/Makefile.common"
 
 # XXX Tweaked for cross-compilation.
 #PKGNAME=      ${DISTNAME:S/-/-base-/}
 PKGNAME=       ${DISTNAME:S/^libtool-/cross-libtool-base-${MACHINE_ARCH}-/}
-PKGREVISION=   6
+PKGREVISION=   7
 
 COMMENT=       Generic shared library support script (the script itself)
 
diff -r 3b8309209242 -r 2a5a30b56388 doc/HOWTO-use-crosscompile
--- a/doc/HOWTO-use-crosscompile        Mon Apr 04 11:22:50 2022 +0000
+++ b/doc/HOWTO-use-crosscompile        Mon Apr 04 11:23:06 2022 +0000
@@ -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.8 2022/04/04 11:22:50 riastradh Exp $
+$NetBSD: HOWTO-use-crosscompile,v 1.9 2022/04/04 11:23:06 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
@@ -40,14 +40,8 @@
    # which is a bug.
    USE_CROSS_COMPILE?=  yes
 
-   .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
-   # Specify the machine architecture of target packages.
-   #
-   # XXX This currently can't be set on the command line, which is a
-   # bug.
-   MACHINE_ARCH=        powerpc
-
-   # Point pkgsrc at the NetBSD tooldir and destdir.
+   # 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
@@ -59,6 +53,13 @@
    TOOLDIR=             /usr/obj/tooldir.NetBSD-6.1-amd64
    CROSS_DESTDIR=       /usr/obj/destdir.evbppc
 
+   .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+   # Specify the machine architecture of target packages.
+   #
+   # XXX This currently can't be set on the command line, which is a
+   # bug.
+   MACHINE_ARCH=        powerpc
+
    # Put target work and packages in separate directories.  (You might
    # use OBJMACHINE=yes or WRKOBJDIR=/tmp/work.${MACHINE_ARCH} instead
    # for the work directories.)
@@ -76,22 +77,6 @@
 into packages, cannot currently be set differently for native and
 target packages.
 
-* Work around libtool
-
-Libtool's build system is broken -- it misuses the GNU build system
-build/host/target settings.  For now we need to kludge around it
-manually:
-
-   $ cd /usr/pkgsrc/cross/cross-libtool-base
-   $ make package
-   $ pkg_add -m powerpc /usr/pkgsrc/packages.powerpc/All/cross-libtool-base-powerpc-2.4.2.tgz
-
-(This builds a libtool package for the target, and then installs the
-target package natively.  This *shouldn't* work, and pkg_add normally
-refuses this, but it does work because libtool is a shell script, and
-`pkg_add -m powerpc' makes pkg_add pretend we are powerpc to suppress
-its refusal.)
-
 * Make some packages
 
 Now packages you build normally will be cross-compiled for the target:
diff -r 3b8309209242 -r 2a5a30b56388 mk/bsd.prefs.mk
--- a/mk/bsd.prefs.mk   Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/bsd.prefs.mk   Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.prefs.mk,v 1.416 2022/01/18 01:41:09 pho Exp $
+# $NetBSD: bsd.prefs.mk,v 1.417 2022/04/04 11:23:06 riastradh Exp $
 #
 # This file includes the mk.conf file, which contains the user settings.
 #
@@ -337,6 +337,33 @@
 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}
 MACHINE_GNU_PLATFORM?=         ${MACHINE_GNU_ARCH}-${LOWER_VENDOR}-${LOWER_OPSYS:C/[0-9]//g}${APPEND_ELF}${LOWER_OPSYS_VERSUFFIX}${APPEND_ABI}
 
+#
+# cross-libtool is special -- it is built as a native package, but it
+# needs tools set up as if for a cross-compiled package because it
+# remembers the paths for use to later assist in cross-compiling other
+# packages.
+#
+# So normally TOOLS_USE_CROSS_COMPILE is the same as USE_CROSS_COMPILE,
+# but for cross-libtool, we set TOOLS_USE_CROSS_COMPILE=yes while doing
+# the rest of the native package build with USE_CROSS_COMPILE=no.
+#
+# This can't live inside the cross-libtool makefile because the
+# TARGET_ARCH / MACHINE_ARCH / NATIVE_MACHINE_ARCH switcheroo has to
+# happen in the middle of this file -- after NATIVE_MACHINE_ARCH is
+# determined, before MACHINE_ARCH is used for anything else.
+#
+.if !empty(LIBTOOL_CROSS_COMPILE:M[yY][eE][sS])
+.  if !defined(TARGET_ARCH)
+PKG_FAIL_REASON+=      "Must set TARGET_ARCH for cross-libtool."
+.  endif
+MACHINE_ARCH:=                 ${TARGET_ARCH}
+_BUILD_DEFS.MACHINE_ARCH=      ${NATIVE_MACHINE_ARCH}
+_BUILD_DEFS.MACHINE_GNU_ARCH=  ${NATIVE_MACHINE_GNU_ARCH}
+TOOLS_USE_CROSS_COMPILE=       yes
+.else
+TOOLS_USE_CROSS_COMPILE=       ${USE_CROSS_COMPILE:Uno}
+.endif
+
 # Needed to prevent an "install:" target from being created in bsd.own.mk.
 NEED_OWN_INSTALL_TARGET=no
 
@@ -520,6 +547,11 @@
 .  endif
 .endif
 
+# TOOLS_CROSS_DESTDIR is used for the libtool build to make a wrapper
+# that points at the cross-destdir as sysroot, without setting
+# _CROSS_DESTDIR because we're actually building a native package.
+TOOLS_CROSS_DESTDIR=           ${CROSS_DESTDIR}
+
 # Depends on MACHINE_ARCH override above
 .if ${OPSYS} == "NetBSD"
 # XXX NATIVE_OBJECT_FMT is a cop-out -- but seriously, who is going to
diff -r 3b8309209242 -r 2a5a30b56388 mk/compiler/gcc.mk
--- a/mk/compiler/gcc.mk        Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/compiler/gcc.mk        Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: gcc.mk,v 1.236 2022/03/13 06:26:57 nia Exp $
+# $NetBSD: gcc.mk,v 1.237 2022/04/04 11:23:06 riastradh Exp $
 #
 # This is the compiler definition for the GNU Compiler Collection.
 #
@@ -668,7 +668,7 @@
 .elif !empty(_IS_BUILTIN_GCC:M[yY][eE][sS])
 _GCCBINDIR=    ${_CC:H}
 .endif
-.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if !empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 _GCC_BIN_PREFIX=       ${MACHINE_GNU_PLATFORM}-
 .endif
 _GCC_BIN_PREFIX?=      # empty
diff -r 3b8309209242 -r 2a5a30b56388 mk/configure/gnu-configure.mk
--- a/mk/configure/gnu-configure.mk     Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/configure/gnu-configure.mk     Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: gnu-configure.mk,v 1.28 2020/05/23 12:11:33 rillig Exp $
+# $NetBSD: gnu-configure.mk,v 1.29 2022/04/04 11:23:06 riastradh Exp $
 #
 # Package-settable variables:
 #
@@ -80,7 +80,7 @@
 
 USE_GNU_CONFIGURE_HOST?=       yes
 .if !empty(USE_GNU_CONFIGURE_HOST:M[yY][eE][sS])
-.  if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.  if !empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 CONFIGURE_ARGS+=       --build=${NATIVE_MACHINE_GNU_PLATFORM:Q}
 .  else
 CONFIGURE_ARGS+=       --build=${MACHINE_GNU_PLATFORM:Q}
diff -r 3b8309209242 -r 2a5a30b56388 mk/cwrappers.mk
--- a/mk/cwrappers.mk   Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/cwrappers.mk   Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cwrappers.mk,v 1.34 2022/04/04 11:22:50 riastradh Exp $
+# $NetBSD: cwrappers.mk,v 1.35 2022/04/04 11:23:06 riastradh Exp $
 #
 # This Makefile fragment implements integration of pkgtools/cwrappers.
 
@@ -37,7 +37,7 @@
 CWRAPPERS_ALIASES.libtool=     libtool
 CWRAPPERS_ALIASES.shlibtool=   shlibtool
 
-.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if !empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 CWRAPPERS_ALIASES.cc+=         ${CC:T}
 CWRAPPERS_ALIASES.cxx+=                ${CXX:T}
 CWRAPPERS_ALIASES.ld+=         ${LD:T}
@@ -101,8 +101,8 @@
 .    endfor
 .  endif
 . endif
-. if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
-       ${RUN}echo sysroot=${_CROSS_DESTDIR:Q} >> ${CWRAPPERS_CONFIG_DIR}/${CWRAPPERS_CONFIG.${wrappee}}
+. if !empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
+       ${RUN}echo sysroot=${TOOLS_CROSS_DESTDIR:Q} >> ${CWRAPPERS_CONFIG_DIR}/${CWRAPPERS_CONFIG.${wrappee}}
 . endif
 .endfor
 
diff -r 3b8309209242 -r 2a5a30b56388 mk/pkgformat/pkg/metadata.mk
--- a/mk/pkgformat/pkg/metadata.mk      Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/pkgformat/pkg/metadata.mk      Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: metadata.mk,v 1.32 2021/11/07 18:49:28 khorben Exp $
+# $NetBSD: metadata.mk,v 1.33 2022/04/04 11:23:07 riastradh Exp $
 
 ######################################################################
 ### The targets below are all PRIVATE.
@@ -36,7 +36,7 @@
 ${_BUILD_INFO_FILE}: ${_PLIST_NOKEYWORDS}
        ${RUN}${MKDIR} ${.TARGET:H}
        ${RUN}${RM} -f ${.TARGET}.tmp
-       ${RUN} (${_BUILD_DEFS:NPATH:@v@${ECHO} ${v}=${${v}:Q} ;@})      \
+       ${RUN} (${_BUILD_DEFS:NPATH:@v@${ECHO} ${v}=${_BUILD_DEFS.${v}:Q:U${${v}:Q}} ;@})       \
                > ${.TARGET}.tmp
 .if !empty(USE_LANGUAGES)
        ${RUN}${ECHO} "CC_VERSION=${CC_VERSION}" >> ${.TARGET}.tmp
diff -r 3b8309209242 -r 2a5a30b56388 mk/tools/tools.FreeMiNT.mk
--- a/mk/tools/tools.FreeMiNT.mk        Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/tools/tools.FreeMiNT.mk        Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: tools.FreeMiNT.mk,v 1.4 2014/03/06 07:34:20 uebayasi Exp $
+# $NetBSD: tools.FreeMiNT.mk,v 1.5 2022/04/04 11:23:07 riastradh Exp $
 #
 # System-supplied tools for the FreeMiNT operating system.
 
@@ -37,7 +37,7 @@
 TOOLS_PLATFORM.head?=          /usr/bin/head
 TOOLS_PLATFORM.hostname?=      /bin/hostname
 TOOLS_PLATFORM.id?=            /usr/bin/id
-.if empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 TOOLS_PLATFORM.install?=       /usr/bin/install
 .else
 TOOLS_PLATFORM.install?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-install
@@ -58,7 +58,7 @@
 TOOLS_PLATFORM.patch?=         /usr/bin/patch
 TOOLS_PLATFORM.printf?=                /usr/bin/printf
 TOOLS_PLATFORM.pwd?=           /bin/pwd
-.if empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 TOOLS_PLATFORM.readelf?=       /usr/bin/readelf
 .else
 TOOLS_PLATFORM.readelf?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-readelf
@@ -71,7 +71,7 @@
 TOOLS_PLATFORM.sleep?=         /bin/sleep
 TOOLS_PLATFORM.soelim?=                /usr/bin/soelim
 TOOLS_PLATFORM.sort?=          /bin/sort
-.if empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 TOOLS_PLATFORM.strip?=         /usr/bin/strip
 .else
 TOOLS_PLATFORM.strip?=         ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-strip
@@ -92,7 +92,7 @@
 TOOLS_PLATFORM.xgettext?=      /usr/bin/xgettext
 TOOLS_PLATFORM.yacc?=          /usr/bin/yacc
 
-.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if !empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 .  for _t_ in ar as ld nm objdump ranlib readelf strip
 TOOLS_PATH.${MACHINE_GNU_PLATFORM}-${_t_}?=    \
        ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-${_t_}
diff -r 3b8309209242 -r 2a5a30b56388 mk/tools/tools.Minix.mk
--- a/mk/tools/tools.Minix.mk   Mon Apr 04 11:22:50 2022 +0000
+++ b/mk/tools/tools.Minix.mk   Mon Apr 04 11:23:06 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: tools.Minix.mk,v 1.13 2018/11/12 13:34:39 jperkin Exp $
+# $NetBSD: tools.Minix.mk,v 1.14 2022/04/04 11:23:07 riastradh Exp $
 #
 # System-supplied tools for the Minix operating system.
 
@@ -43,7 +43,7 @@
 TOOLS_PLATFORM.head?=          /usr/bin/head
 TOOLS_PLATFORM.hostname?=      /bin/hostname
 TOOLS_PLATFORM.id?=            /usr/bin/id
-.if empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 TOOLS_PLATFORM.install?=       /usr/bin/install
 .else
 TOOLS_PLATFORM.install?=       ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-install
@@ -67,7 +67,7 @@
 TOOLS_PLATFORM.pax?=           /bin/pax
 TOOLS_PLATFORM.printf?=                /usr/bin/printf
 TOOLS_PLATFORM.pwd?=           /bin/pwd
-.if empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+.if empty(TOOLS_USE_CROSS_COMPILE:M[yY][eE][sS])
 TOOLS_PLATFORM.readelf?=       /usr/bin/readelf
 .else



Home | Main Index | Thread Index | Old Index