xref: /haiku/ReadMe.Compiling.md (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1Building Haiku
2==========================
3This is a overview into the process of building HAIKU from source.
4An online version is available at <https://www.haiku-os.org/guides/building/>.
5
6Official releases of Haiku are at <https://www.haiku-os.org/get-haiku>.
7The (unstable) nightly builds are available at <https://download.haiku-os.org/>.
8
9We currently support the following platforms:
10 * Haiku
11 * Linux
12 * FreeBSD
13 * macOS
14
15Required Software
16----------------------------
17Tools provided within Haiku's repositories:
18 * `jam` (Jam 2.5-haiku-20111222)
19 * Haiku's cross-compiler
20
21The tools to compile Haiku will vary, depending on the platform that you are
22using to build Haiku. When building from Haiku, all of the necessary
23development tools are included in official releases (e.g. R1/beta1) and in the
24nightly builds.
25
26 * `git`
27 * `gcc`/`g++` and binutils (`as`, `ld`, etc., required by GCC)
28 * (GNU) `make`
29 * `bison` (2.4 or better)
30 * `flex` and `lex` (usually a mini shell script invoking `flex`)
31 * `makeinfo` (part of `texinfo`, only needed for building GCC 4)
32 * `autoheader` (part of `autoconf`, needed for building GCC)
33 * `automake` (needed for building GCC)
34 * `awk` (GNU awk is most tested, but other implementations should work)
35 * `nasm`
36 * `wget`
37 * `[un]zip`
38 * `xorriso`
39 * `mtools` (<https://gnu.org/software/mtools/intro.html>)
40 * case-sensitive file system
41
42Whether they are installed can be tested by running them in a shell with
43the `--version` parameter.
44
45The following libraries (and their respective headers) are required:
46 * `zlib`
47
48### Haiku for ARM
49If you want to compile Haiku for ARM, you will also need:
50
51 * `mkimage` (<http://www.denx.de/wiki/U-Boot/WebHome>)
52
53### On macOS
54
55Disk Utility can create a case-sensitive disk image of at least 3 GiB in size.
56The following ports need to be installed:
57 * `expat`
58 * `gawk`
59 * `gettext`
60 * `libiconv`
61 * `gsed`
62 * `cdrtools`
63 * `nasm`
64 * `wget`
65 * `less`
66 * `mpfr`
67 * `gmp`
68 * `libmpc`
69 * `bison` (updated to the latest version)
70
71More information about individual distributions of Linux and BSD can be found
72at <https://haiku-os.org/guides/building/pre-reqs>.
73
74Downloading Haiku's sources
75--------------------------------------------------
76There are two parts to Haiku's sources &mdash; the code for Haiku itself and a set
77of build tools for compiling Haiku on an operating system other than Haiku.
78The buildtools are needed only for non-Haiku platforms.
79
80Anonymous checkout:
81```
82git clone https://review.haiku-os.org/haiku.git
83git clone https://review.haiku-os.org/buildtools.git
84```
85
86If you have commit access:
87```
88git clone ssh://git.haiku-os.org/haiku
89git clone ssh://git.haiku-os.org/buildtools
90```
91
92Building Jam
93-------------------------------------------
94(*This step applies only to non-Haiku platforms. Haiku already ships with the correct version of Jam*)
95
96Change to the `buildtools` folder and run the following commands to
97generate and install `jam`:
98```
99cd buildtools/jam
100make
101sudo ./jam0 install
102```
103Or,  if you don't want to install `jam` systemwide:
104```
105./jam0 -sBINDIR=$HOME/bin install
106```
107
108Configuring the build
109-------------------------------------
110The `configure` script generates a file named `BuildConfig` in the
111`generated/build` directory. As long as `configure` is not modified (!) and the
112cross-compilation tools have not been updated, there is no need to call it again.
113For rebuilding, you only need to invoke `jam` (see below). If you don't
114update the source tree very frequently, you may want to execute `configure`
115after each update just to be on the safe side.
116
117Depending on your goal, there are several different ways to configure Haiku.
118The first way is to call configure from within your Haiku checkout's root. That
119will prepare a folder named 'generated', which will contain the compiled objects.
120Another option is to manually created one or more `generated.*` folders and run
121configure from within them. For example, imagine the following directory setup:
122```
123buildtools/
124haiku/
125haiku/generated.x86gcc2
126```
127
128### Configure an x86_64 (GCC 8) build
129```bash
130cd haiku/generated.x86_64
131../configure --cross-tools-source ../../buildtools --build-cross-tools x86_64
132```
133
134### Configure a 32-bit GCC 2.95/GCC 8 Hybrid, from a non-Haiku platform
135```bash
136cd haiku/generated.x86gcc2
137../configure \
138	--cross-tools-source ../../buildtools/ \
139	--build-cross-tools x86_gcc2 \
140	--build-cross-tools x86
141```
142
143### Configure a 32-bit GCC 2.95/GCC 8 Hybrid, from Haiku
144```bash
145cd haiku/generated.x86gcc2
146../configure --target-arch x86_gcc2 --target-arch x86
147```
148
149Additional information about GCC Hybrids can be found on the website,
150<https://www.haiku-os.org/guides/building/gcc-hybrid>.
151
152### Configure options
153The various runtime options for configure are documented in its onscreen help
154```bash
155./configure --help
156```
157
158Building via Jam
159----------------------------
160
161Haiku can be built in either of two ways, as disk image file (e.g. for use
162with emulators, to be written directly to a usb stick, burned as a compact
163disc) or as installation in a directory.
164
165### Running Jam
166
167There are various ways in which you can run `jam`:
168
169 * If you have a single generated folder, you can run 'jam' from the top level of Haiku's trunk.
170 * If you have one or more generated folders, (e.g. generated.x86gcc2),
171   you can `cd` into that directory and run `jam`.
172 * In either case, you can `cd` into a certain folder in the source tree (e.g.
173   src/apps/debugger) and run jam -sHAIKU_OUTPUT_DIR=<path to generated folder>
174
175Be sure to read `build/jam/UserBuildConfig.ReadMe` and `UserBuildConfig.sample`,
176as they contain information on customizing your build of Haiku.
177
178### Building a Haiku anyboot image (Nightly)
179```
180jam -q @nightly-anyboot
181```
182
183This generates an image file named `haiku-nightly-anyboot.iso` in your output
184directory under `generated/`.
185
186### Building a Haiku raw image (Nightly)
187```
188jam -q @nightly-raw
189```
190
191This generates an image file named `haiku.image` in your output directory under
192`generated/`.
193
194### Building a VMware image file
195```
196jam -q @nightly-vmware
197```
198
199This generates an image file named `haiku.vmdk` in your output
200directory under `generated/`.
201
202### Directory Installation
203```
204HAIKU_INSTALL_DIR=/Haiku jam -q @install
205```
206
207Installs all Haiku components into the volume mounted at "/Haiku" and
208automatically marks it as bootable. To create a partition in the first place
209use DriveSetup and initialize it to BFS.
210
211Note that installing Haiku in a directory only works as expected under Haiku,
212but it is not yet supported under Linux and other non-Haiku platforms.
213
214### Building individual components
215If you don't want to build the complete Haiku, but only a certain
216app/driver/etc. you can specify it as argument to jam, e.g.:
217```
218jam -q Debugger
219```
220Alternatively, you can `cd` to the directory of the component you want to
221build and run `jam` from there. **NOTE:** if your generated directory is named
222something other than `generated/`, you will need to tell `jam` where it is:
223```
224jam -q -sHAIKU_OUTPUT_DIR=<path to generated folder>
225```
226You can also force the rebuild of a component by using the `-a` parameter:
227```
228jam -qa Debugger
229```
230
231Bootstrap Build
232----------------
233New architectures (and occasionally existing ones) will require a bootstrap
234build to compile *build packages*. (Catch-22 software packages which are needed
235to compile Haiku, but need to be initially compiled under Haiku)
236
237### Pre-requirements
238  * All of the standard tools in the Required Software section above.
239  * The following repositories on disk in the same general location
240    * haiku (https://git.haiku-os.org/haiku)
241    * buildtools (https://git.haiku-os.org/buildtools)
242    * haikuporter (https://github.com/haikuports/haikuporter.git)
243    * haikuports.cross (https://github.com/haikuports/haikuports.cross.git)
244    * haikuports (https://github.com/haikuports/haikuports.git)
245
246### Setting Up a Bootstrap build
247Create a clean build directory under the haiku repo.
248```
249mkdir generated.myarch && cd generated.myarch
250```
251
252Configure Haiku's build system for a bootstrap build specifying the location
253of all of the repositories above.
254```
255../configure -j4 \
256  --build-cross-tools myarch --cross-tools-source ../../buildtools \
257  --bootstrap ../../haikuporter/haikuporter ../../haikuports.cross ../../haikuports
258```
259
260Once the build system is configured for bootstrap, we now can begin building
261the bootstrap image.
262
263```
264jam -q @bootstrap-raw
265```
266
267If you are bootstrapping for an architecture Haiku already boots on, the generated
268disk image can be used to compile *build packages* needed for the standard
269Haiku build.
270
271If you are bootstrapping for a new architecture which doesn't build yet, you will
272need to leverage the ```unbootstrap.sh``` script to hack the generated bootstrap
273packages into non-bootstrap packages which can be temporarily used as
274*build packages*.
275
276Running
277----------------
278Generally there are two ways of running Haiku: on real hardware using a
279partition, and on emulated hardware using an emulator (like VirtualBox, or QEMU).
280
281### On Real Hardware
282If you have installed Haiku to its own partition you can include this
283partition in your bootmanager and try to boot Haiku like any other OS you
284have installed. To include a new partition in the Haiku bootmanager, start
285the BootManager configurator by running:
286```
287BootManager
288```
289
290### On Emulated Hardware
291For emulated hardware you should build a disk image (see above). How to set up
292this image depends on your emulator. If you use QEMU, you can usually just
293provide the path to the image as command line argument to the `qemu`
294executable.
295