xref: /haiku/ReadMe.Compiling.md (revision d1f10fcef93242bcfee9ff16c0255bf3b64ec33b)
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 file
179```
180jam -q @anyboot-image
181```
182
183This generates an image file named `haiku-anyboot.image` in your output
184directory under `generated/`.
185
186### Building a VMware image file
187```
188jam -q @vmware-image
189```
190This generates an image file named `haiku.vmdk` in your output
191directory under `generated/`.
192
193### Directory Installation
194```
195HAIKU_INSTALL_DIR=/Haiku jam -q @install
196```
197
198Installs all Haiku components into the volume mounted at "/Haiku" and
199automatically marks it as bootable. To create a partition in the first place
200use DriveSetup and initialize it to BFS.
201
202Note that installing Haiku in a directory only works as expected under Haiku,
203but it is not yet supported under Linux and other non-Haiku platforms.
204
205### Building individual components
206If you don't want to build the complete Haiku, but only a certain
207app/driver/etc. you can specify it as argument to jam, e.g.:
208```
209jam -q Debugger
210```
211Alternatively, you can `cd` to the directory of the component you want to
212build and run `jam` from there. **NOTE:** if your generated directory is named
213something other than `generated/`, you will need to tell `jam` where it is:
214```
215jam -q -sHAIKU_OUTPUT_DIR=<path to generated folder>
216```
217You can also force the rebuild of a component by using the `-a` parameter:
218```
219jam -qa Debugger
220```
221
222Bootstrap Build
223----------------
224New architectures (and occasionally existing ones) will require a bootstrap
225build to compile *build packages*. (Catch-22 software packages which are needed
226to compile Haiku, but need to be initially compiled under Haiku)
227
228### Pre-requirements
229  * All of the standard tools in the Required Software section above.
230  * The following repositories on disk in the same general location
231    * haiku (https://git.haiku-os.org/haiku)
232    * buildtools (https://git.haiku-os.org/buildtools)
233    * haikuporter (https://github.com/haikuports/haikuporter.git)
234    * haikuports.cross (https://github.com/haikuports/haikuports.cross.git)
235    * haikuports (https://github.com/haikuports/haikuports.git)
236
237### Setting Up a Bootstrap build
238Create a clean build directory under the haiku repo.
239```
240mkdir generated.myarch && cd generated.myarch
241```
242
243Configure Haiku's build system for a bootstrap build specifying the location
244of all of the repositories above.
245```
246../configure -j4 \
247  --build-cross-tools myarch --cross-tools-source ../../buildtools \
248  --bootstrap ../../haikuporter/haikuporter ../../haikuports.cross ../../haikuports
249```
250
251Once the build system is configured for bootstrap, we now can begin building
252the bootstrap image.
253
254```
255jam -q @bootstrap-raw
256```
257
258If you are bootstrapping for an architecture Haiku already boots on, the generated
259disk image can be used to compile *build packages* needed for the standard
260Haiku build.
261
262If you are bootstrapping for a new architecture which doesn't build yet, you will
263need to leverage the ```unbootstrap.sh``` script to hack the generated bootstrap
264packages into non-bootstrap packages which can be temporarily used as
265*build packages*.
266
267Running
268----------------
269Generally there are two ways of running Haiku: on real hardware using a
270partition, and on emulated hardware using an emulator (like VirtualBox, or QEMU).
271
272### On Real Hardware
273If you have installed Haiku to its own partition you can include this
274partition in your bootmanager and try to boot Haiku like any other OS you
275have installed. To include a new partition in the Haiku bootmanager, start
276the BootManager configurator by running:
277```
278BootManager
279```
280
281### On Emulated Hardware
282For emulated hardware you should build a disk image (see above). How to set up
283this image depends on your emulator. If you use QEMU, you can usually just
284provide the path to the image as command line argument to the `qemu`
285executable.
286