1 Cross-compilation in pkgsrc (user's guide) -*- outline -*-
2 Taylor R. Campbell <riastradh@NetBSD.org>
6 The following steps enable you to build binary packages for a machine
7 architecture other than the one you are building on. For example, you
8 might use them on your beefy umpteen-core amd64-based build machine
9 (the `native' machine) to build packages for your feeble powerpc-based
10 network appliance (the `target' machine).
12 These instructions assume you use the conventional privileged paths:
13 /usr/src for the NetBSD source tree, /usr/obj for the NetBSD object
14 tree, and /usr/pkgsrc for the pkgsrc tree. If you want to do it
15 unprivileged, see `* Unprivileged notes' below.
17 XXX This currently works only for NetBSD.
19 * Build NetBSD tools and distribution for the target system
21 Use build.sh to build NetBSD tools and a distribution, and remember
22 what the destdir and tooldir are -- you'll need them for pkgsrc's
26 $ ./build.sh -m evbppc tools
27 $ ./build.sh -m evbppc distribution
29 By default, the destdir will be /usr/obj/destdir.evbppc, and the
30 tooldir will be (say) /usr/obj/tooldir.NetBSD-6.1.amd64 if you're
31 running NetBSD 6.1 on amd64.
35 In addition to whatever else you want in your mk.conf for pkgsrc, add:
37 # Cross-compile by default.
39 # XXX This currently can't be set to `yes' on the command line,
41 USE_CROSS_COMPILE?= yes
43 # This is a kludge for cross-libtool.
45 # XXX Should not need this.
46 CROSSBASE= ${LOCALBASE}/cross-${TARGET_ARCH:U${MACHINE_ARCH}}
48 .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
49 # Specify the machine architecture of target packages.
51 # XXX This currently can't be set on the command line, which is a
55 # Point pkgsrc at the NetBSD tooldir and destdir.
57 # XXX There is no obvious variable that is set to amd64 so that we
60 # TOOLDIR= /usr/obj/tooldir.${OPSYS}-${OS_VERSION}.${NATIVE_xyz}
62 # MACHINE is amd64 but, since it's not NATIVE_xyz, it's wrong.
63 # NATIVE_MACHINE_ARCH is x86_64, not amd64.
64 TOOLDIR= /usr/obj/tooldir.NetBSD-6.1.amd64
65 CROSS_DESTDIR= /usr/obj/destdir.evbppc
67 # Put target work and packages in separate directories. (You might
68 # use OBJMACHINE=yes or WRKOBJDIR=/tmp/work.${MACHINE_ARCH} instead
69 # for the work directories.)
71 # XXX Should not need this.
72 PACKAGES= ${PKGSRCDIR}/packages.${MACHINE_ARCH}
73 WRKDIR_BASENAME= work.${MACHINE_ARCH}
76 You can bootstrap pkgsrc or not; it shouldn't make a difference for
77 cross-compilation. If you do, replace `make' by `bmake' below, of
80 XXX Some variables, notably LOCALBASE and other paths that get baked
81 into packages, cannot currently be set differently for native and
86 Libtool's build system is broken -- it misuses the GNU build system
87 build/host/target settings. For now we need to kludge around it
90 $ cd /usr/pkgsrc/cross/libtool-base
92 $ pkg_add -m powerpc /usr/pkgsrc/packages.powerpc/All/cross-libtool-base-powerpc-2.4.2.tgz
94 (This builds a libtool package for the target, and then installs the
95 target package natively. This *shouldn't* work, and pkg_add normally
96 refuses this, but it does work because libtool is a shell script, and
97 `pkg_add -m powerpc' makes pkg_add pretend we are powerpc to suppress
102 Now packages you build normally will be cross-compiled for the target:
104 $ cd /usr/pkgsrc/net/isc-dhcpd4 && make package
106 You can find the shiny new powerpc package at
108 /usr/pkgsrc/packages.powerpc/
110 Any packages needed on natively to build the target packages will be
111 built and installed automatically, but if for some reason you want to
112 build a native package, you can run
114 $ cd /usr/pkgsrc/net/isc-dhcpd4 && make package USE_CROSS_COMPILE=no
116 XXX Note that currently you cannot omit USE_CROSS_COMPILE?=yes from
117 your mk.conf and pass USE_CROSS_COMPILE=yes on the make command line.
122 I do all this stuff unprivileged in directories under my home
123 directory so that it's easy for me to nuke build products without
124 messing with the package installations I use for development.
126 NetBSD srcdir: ~/netbsd/current/src
127 NetBSD objdir: ~/netbsd/current/obj.evbppc
128 NetBSD tooldir: ~/netbsd/current/obj.evbppc/tooldir.NetBSD-6.1.amd64
129 NetBSD destdir: ~/netbsd/current/obj.evbppc/destdir.evbppc
130 pkgsrc: ~/pkgsrc/current/pkgsrc
131 pkgsrc LOCALBASE: ~/pkgsrc/current/pkg
133 (~/netbsd/current/src and ~/pkgsrc/current/pkgsrc are actually
134 read-only null mounts of ~/netbsd/current/src-cvs and
135 ~/pkgsrc/current/pkgsrc-cvs, respectively.)
137 To build NetBSD, I run:
139 $ cd ~/netbsd/current/src
140 $ ./build.sh -O ../obj.evbppc -U -u -m evbppc -j12 tools
141 $ ./build.sh -O ../obj.evbppc -U -u -m evbppc -j12 distribution
143 My mk.conf additionally has UNPRIVILEGED=yes, and I bootstrap pkgsrc
146 $ cd ~/pkgsrc/current/pkgsrc/bootstrap
148 --gzip-binary-kit ~/pkgsrc/current/bootstrap/20130422.tgz \
149 --mk-fragment ~/pkgsrc/current/bootstrap/20130422.mk \
150 --prefix ~/pkgsrc/current/pkg \
152 --workdir /tmp/bootwork
154 and various other crud to customize the build and package options.
155 This requires putting ~/pkgsrc/current/pkg/{bin,sbin} before
156 /usr/{bin,sbin} in your PATH so that you see bmake and use the right
157 pkg_* tools. Send me a note if you have questions about my setup.
161 This document and the relevant pkgsrc variables call the machine on
162 which the packages are built the `native' machine, and the machine on
163 which the packages are to be run the `target' machine.
165 This is different from the GNU build system, which considers three
166 different machines for so-called Canadian cross-builds, which pkgsrc
169 The `build' machine is the machine on which the software is built.
170 The `host' machine is the machine on which the software will run.
171 The `target' machine is the machine that the software is being
172 configured to operate on, such as a cross-compiler or cross-linker.
174 These correspond to the pkgsrc nomenclature as follows:
176 - Native packages configured for native compilation:
184 - Native packages configured for cross-compilation: