-
Notifications
You must be signed in to change notification settings - Fork 161
/
HOWTO-use-crosscompile
183 lines (135 loc) · 6.28 KB
/
HOWTO-use-crosscompile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Cross-compilation in pkgsrc (user's guide) -*- outline -*-
Taylor R. Campbell <riastradh@NetBSD.org>
$NetBSD: HOWTO-use-crosscompile,v 1.18 2024/06/06 02:38:02 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
might use them on your beefy umpteen-core amd64-based build machine
(the `native' machine) to build packages for your feeble powerpc-based
network appliance (the `target' machine).
These instructions assume you use the conventional privileged paths:
/usr/src for the NetBSD source tree, /usr/obj for the NetBSD object
tree, and /usr/pkgsrc for the pkgsrc tree. If you want to do it
unprivileged, see `* Unprivileged notes' below.
XXX This currently works only for NetBSD.
* Build NetBSD tools and distribution for the target system
Use build.sh to build NetBSD tools and a distribution, and remember
what the destdir and tooldir are -- you'll need them for pkgsrc's
mk.conf.
$ cd /usr/src
$ ./build.sh -m evbppc tools
$ ./build.sh -m evbppc distribution
By default, the destdir will be /usr/obj/destdir.evbppc, and the
tooldir will be (say) /usr/obj/tooldir.NetBSD-6.1-amd64 if you're
running NetBSD 6.1 on amd64.
* Set up mk.conf
In addition to whatever else you want in your mk.conf for pkgsrc, add:
# Cross-compile by default. (Alternatively, instead of having this
# setting in mk.conf, you can cross-build packages by just running
# `make package USE_CROSS_COMPILE=yes'.)
#
# Note: This must use `?=' so it doesn't override pkgsrc's internal
# USE_CROSS_COMPILE=no when recursively building toolchain packages
# that have to run on the host.
USE_CROSS_COMPILE?= yes
# Point pkgsrc at the NetBSD tooldir and destdir for cross builds.
TOOLDIR= /usr/obj/tooldir.NetBSD-6.1-amd64
CROSS_DESTDIR= /usr/obj/destdir.evbppc
# Specify the machine architecture of target packages.
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
CROSS_OBJECT_FMT= ELF
Optionally, you can set CROSS_LOCALBASE, CROSS_SYSCONFBASE, and
CROSS_VARBASE for cross-compiled packages separately from LOCALBASE,
SYSCONFBASE, and VARBASE for natively compiled packages. For example,
you can use an unprivileged pkgsrc build into /home/user/cross/pkg that
will create packages which install to /opt/pkg:
LOCALBASE= /home/user/cross/pkg
CROSS_LOCALBASE= /opt/pkg
By default, pkgsrc will assume:
CROSS_LOCALBASE= /usr/pkg
CROSS_SYSCONFBASE= /etc
CROSS_VARBASE= /var
That is, no matter what you set LOCALBASE, SYSCONFBASE, and VARBASE to
in mk.conf for native packages, like directores under /home/user, by
default cross-compiled packages will see LOCALBASE=/usr/pkg,
SYSCONFBASE=/etc, and VARBASE=/var.
** Bootstrapped pkgsrc
You can bootstrap pkgsrc or not; it shouldn't make a difference for
cross-compilation. If you do, replace `make' by `bmake' below:
* Make some packages
Now packages you build normally will be cross-compiled for the target:
$ cd /usr/pkgsrc/net/isc-dhcpd4 && make package
You can find the shiny new powerpc package at
/usr/pkgsrc/packages.powerpc/
Any packages needed on natively to build the target packages will be
built and installed automatically, but if for some reason you want to
build a native package, you can run
$ cd /usr/pkgsrc/net/isc-dhcpd4 && make package USE_CROSS_COMPILE=no
* Unprivileged notes
I do all this stuff unprivileged in directories under my home
directory so that it's easy for me to nuke build products without
messing with the package installations I use for development.
NetBSD srcdir: ~/netbsd/current/src
NetBSD objdir: ~/netbsd/current/obj.evbppc
NetBSD tooldir: ~/netbsd/current/obj.evbppc/tooldir.NetBSD-6.1-amd64
NetBSD destdir: ~/netbsd/current/obj.evbppc/destdir.evbppc
pkgsrc: ~/pkgsrc/current/pkgsrc
pkgsrc LOCALBASE: ~/pkgsrc/current/pkg
(~/netbsd/current/src and ~/pkgsrc/current/pkgsrc are actually
read-only null mounts of ~/netbsd/current/src-cvs and
~/pkgsrc/current/pkgsrc-cvs, respectively.)
To build NetBSD, I run:
$ cd ~/netbsd/current/src
$ ./build.sh -O ../obj.evbppc -U -u -m evbppc -j12 tools
$ ./build.sh -O ../obj.evbppc -U -u -m evbppc -j12 distribution
My mk.conf additionally has UNPRIVILEGED=yes, and I bootstrap pkgsrc
with
$ cd ~/pkgsrc/current/pkgsrc/bootstrap
$ ./bootstrap \
--gzip-binary-kit ~/pkgsrc/current/bootstrap/20130422.tgz \
--mk-fragment ~/pkgsrc/current/bootstrap/20130422.mk \
--prefix ~/pkgsrc/current/pkg \
--unprivileged \
--workdir /tmp/bootwork
and various other crud to customize the build and package options.
This requires putting ~/pkgsrc/current/pkg/{bin,sbin} before
/usr/{bin,sbin} in your PATH so that you see bmake and use the right
pkg_* tools. Send me a note if you have questions about my setup.
* Terminology
This document and the relevant pkgsrc variables call the machine on
which the packages are built the `native' machine, and the machine on
which the packages are to be run the `target' machine.
This is different from the GNU build system, which considers three
different machines for so-called Canadian cross-builds, which pkgsrc
does not support:
The `build' machine is the machine on which the software is built.
The `host' machine is the machine on which the software will run.
The `target' machine is the machine that the software is being
configured to operate on, such as a cross-compiler or cross-linker.
These correspond to the pkgsrc nomenclature as follows:
- Native packages configured for native compilation:
GNU pkgsrc
--- ------
build native
host native
target native
- Native packages configured for cross-compilation:
GNU pkgsrc
--- ------
build native
host native
target target
- Target packages:
GNU pkgsrc
--- ------
build native
host target
target target