Up to [cvs.NetBSD.org] / pkgsrc / doc
Request diff between arbitrary revisions
Keyword substitution: kv
Default branch: MAIN
doc/HOWTO-use-crosscompile: Fix default $PACKAGES.
doc/HOWTO-use-crosscompile: Nix obsolete note about ABI. CROSS_ABI has obsoleted it. Should maybe document that too but it's such a niche thing that I didn't feel inclined to work out all the details of its semantics and intended use-cases.
doc/HOWTO-use-crosscompile: Note CROSS_OBJECT_FMT.
doc/HOWTO-use-crosscompile: Fix confusing comment in example mk.conf.
doc/HOWTO-use-crosscompile: `make USE_CROSS_COMPILE=yes' works now. At least, it seems to! Not sure what symptom I saw ages ago when I warned users against it.
bsd.prefs.mk: New CROSS_VARBASE and CROSS_SYSCONFBASE. These default to /var and /etc, respectively. When cross-building packages, VARBASE and SYSCONFBASE are set to these instead of whatever they were set to in mk.conf. No change to native builds because use of these variables is conditional on USE_CROSS_COMPILE = yes.
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.
Split native and cross LOCALBASE for cross-compilation.
This way, you can use an unprivileged prefix of ~/cross/pkg to
cross-compile packages that, when installed, will go in /usr/pkg.
In mk.conf:
- Set CROSS_LOCALBASE to determine the installation prefix of
packages that you cross-compile.
- Set LOCALBASE to determine the installation prefix of native
packages needed for cross compilation.
Both default to /usr/pkg. Note: CROSS_LOCALBASE defaults to /usr/pkg
even if you set LOCALBASE. Of course, if you're not cross-compiling,
this has no effect.
When cross-compiling a package:
- LOCALBASE is where cross-compiled packages will be installed.
(`make install' will put it in ${CROSS_DESTDIR}${LOCALBASE}, of
course, but when you later use pkg_add to install the binary
package on the system you're compiling it for, it will go in
${LOCALBASE}. And you can still set PREFIX for an individual
package, but LOCALBASE refers to where cross-compiled packages are
generally installed, other than the specific ones that override
PREFIX.)
- TOOLBASE is where tool dependencies are installed and available to
be executed at build-time.
For example, if you have TOOL_DEPENDS on a program that is
installed in (say) foo/bin/xyz which is not in PATH so you have to
refer ot its full pathname, you can execute ${TOOLBASE}/foo/bin/xyz
instead of ${LOCALBASE}/foo/bin/xyz.
I chose this split, rather than the other way around, because I
expect that references that are baked into installed packages to be
more common than references that are executed at build-time, but I
didn't do an extensive study of the matter. I chose the name
TOOLBASE because it's where TOOL_DEPENDS go.
mk: Use CWRAPPERS_PREPEND for --sysroot. Looks like maybe the -Wl,-rpath-link business isn't necessary after all -- will leave this as is until I find evidence otherwise. (joerg says it was a workaround for NetBSD toolchain parts that weren't properly adapted to use sysroot.) With this, revert cwrappers version dependency to what it was before. But keep it as TOOL_DEPENDS, not BUILD_DEPENDS.
mk: For cross-builds, use work.$ARCH and packages.$ARCH by default. Otherwise it is mandatory to set these in mk.conf anyway, so let's save the trouble.
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.
cwrappers: Add cross-compilation support.
- New option `sysroot=<dir>':
. Wrapper will add `--sysroot=<dir>' as first argument.
. For every rpath argument, e.g. -Wl,-R<path> to cc, wrapper will
pass `-rpath-link <dir><path>' to the linker.
This matches the old mk/wrapper/cmd-sink-cross-* logic.
- Create wrappers for the ${MACHINE_GNU_PLATFORM}-cc style of command,
as in ${CC}, ${CXX}, ${LD} for cross-builds.
- Bump version.
- Use TOOL_DEPENDS, not BUILD_DEPENDS, for cwrappers.
Note that USE_CWRAPPERS=no is needed for now in cross-compiling. This is a bug, just need to teach cwrappers about passing sysroot.
Sync cross-libtool-base with libtool-base. Eliminate CROSSBASE. cross-libtool-base now installs into $PREFIX/cross-$TARGET_ARCH unconditionally.
Fix path to cross-libtool-base in HOWTO
Fix two more tooldir punctuations.
Fix tooldir name punctuation to match NetBSD build.sh default.
Add $NetBSD$ tags to HOWTO-use-crosscompile & HOWTO-dev-crosscompile.
Add some notes on how to use and develop cross-compiled packages. ok agc