xref: /haiku/ReadMe.Compiling.md (revision a143f249c2ebb0ba596aa44a32dfc5a30fab4d4f)
1b87e672aSAugustin CavalierBuilding Haiku
2b87e672aSAugustin Cavalier==========================
3b87e672aSAugustin CavalierThis is a overview into the process of building HAIKU from source.
4fc2c93fbSAugustin CavalierAn online version is available at <https://www.haiku-os.org/guides/building/>.
5b87e672aSAugustin Cavalier
6fc2c93fbSAugustin CavalierOfficial releases of Haiku are at <https://www.haiku-os.org/get-haiku>.
7b87e672aSAugustin CavalierThe (unstable) nightly builds are available at <https://download.haiku-os.org/>.
8b87e672aSAugustin Cavalier
9b87e672aSAugustin CavalierWe currently support the following platforms:
10b87e672aSAugustin Cavalier * Haiku
11b87e672aSAugustin Cavalier * Linux
12b87e672aSAugustin Cavalier * FreeBSD
13fc2c93fbSAugustin Cavalier * macOS
14b87e672aSAugustin Cavalier
15b87e672aSAugustin CavalierRequired Software
16b87e672aSAugustin Cavalier----------------------------
17b87e672aSAugustin CavalierTools provided within Haiku's repositories:
18b87e672aSAugustin Cavalier * `jam` (Jam 2.5-haiku-20111222)
195d200bd3SAugustin Cavalier * Haiku's cross-compiler
20b87e672aSAugustin Cavalier
21b87e672aSAugustin CavalierThe tools to compile Haiku will vary, depending on the platform that you are
22b87e672aSAugustin Cavalierusing to build Haiku. When building from Haiku, all of the necessary
235d200bd3SAugustin Cavalierdevelopment tools are included in official releases (e.g. R1/beta1) and in the
24b87e672aSAugustin Cavaliernightly builds.
25b87e672aSAugustin Cavalier
26b87e672aSAugustin Cavalier * `git`
27b87e672aSAugustin Cavalier * `gcc`/`g++` and binutils (`as`, `ld`, etc., required by GCC)
28b87e672aSAugustin Cavalier * (GNU) `make`
29e37802d3SAugustin Cavalier * `bison` (2.4 or better)
30b87e672aSAugustin Cavalier * `flex` and `lex` (usually a mini shell script invoking `flex`)
31b87e672aSAugustin Cavalier * `makeinfo` (part of `texinfo`, only needed for building GCC 4)
32b87e672aSAugustin Cavalier * `autoheader` (part of `autoconf`, needed for building GCC)
33fc2c93fbSAugustin Cavalier * `automake` (needed for building GCC)
343b3bcbf7SAdrien Destugues * `awk` (GNU awk is most tested, but other implementations should work)
35b87e672aSAugustin Cavalier * `nasm`
36b87e672aSAugustin Cavalier * `wget`
37b87e672aSAugustin Cavalier * `[un]zip`
385d200bd3SAugustin Cavalier * `xorriso`
395d200bd3SAugustin Cavalier * `mtools` (<https://gnu.org/software/mtools/intro.html>)
40*a143f249SFrançois Revol * `python3`
41b87e672aSAugustin Cavalier * case-sensitive file system
42b87e672aSAugustin Cavalier
43b87e672aSAugustin CavalierWhether they are installed can be tested by running them in a shell with
44b87e672aSAugustin Cavalierthe `--version` parameter.
45b87e672aSAugustin Cavalier
46b87e672aSAugustin CavalierThe following libraries (and their respective headers) are required:
47b87e672aSAugustin Cavalier * `zlib`
48*a143f249SFrançois Revol * `zstd`
49b87e672aSAugustin Cavalier
50b87e672aSAugustin Cavalier### Haiku for ARM
51b87e672aSAugustin CavalierIf you want to compile Haiku for ARM, you will also need:
52b87e672aSAugustin Cavalier
53b87e672aSAugustin Cavalier * `mkimage` (<http://www.denx.de/wiki/U-Boot/WebHome>)
54b87e672aSAugustin Cavalier
55fc2c93fbSAugustin Cavalier### On macOS
56b87e672aSAugustin Cavalier
57b87e672aSAugustin CavalierDisk Utility can create a case-sensitive disk image of at least 3 GiB in size.
58b87e672aSAugustin CavalierThe following ports need to be installed:
59b87e672aSAugustin Cavalier * `expat`
60b87e672aSAugustin Cavalier * `gawk`
61b87e672aSAugustin Cavalier * `gettext`
62b87e672aSAugustin Cavalier * `libiconv`
63b87e672aSAugustin Cavalier * `gsed`
64b87e672aSAugustin Cavalier * `cdrtools`
65b87e672aSAugustin Cavalier * `nasm`
66b87e672aSAugustin Cavalier * `wget`
67b87e672aSAugustin Cavalier * `less`
68b87e672aSAugustin Cavalier * `mpfr`
69b87e672aSAugustin Cavalier * `gmp`
70b87e672aSAugustin Cavalier * `libmpc`
71958bf097SHumdinger * `bison` (updated to the latest version)
72b87e672aSAugustin Cavalier
73b87e672aSAugustin CavalierMore information about individual distributions of Linux and BSD can be found
74b87e672aSAugustin Cavalierat <https://haiku-os.org/guides/building/pre-reqs>.
75b87e672aSAugustin Cavalier
76b87e672aSAugustin CavalierDownloading Haiku's sources
77b87e672aSAugustin Cavalier--------------------------------------------------
78b87e672aSAugustin CavalierThere are two parts to Haiku's sources &mdash; the code for Haiku itself and a set
79b87e672aSAugustin Cavalierof build tools for compiling Haiku on an operating system other than Haiku.
80b87e672aSAugustin CavalierThe buildtools are needed only for non-Haiku platforms.
81b87e672aSAugustin Cavalier
82b87e672aSAugustin CavalierAnonymous checkout:
83b87e672aSAugustin Cavalier```
845d200bd3SAugustin Cavaliergit clone https://review.haiku-os.org/haiku.git
855d200bd3SAugustin Cavaliergit clone https://review.haiku-os.org/buildtools.git
86b87e672aSAugustin Cavalier```
87b87e672aSAugustin Cavalier
88b87e672aSAugustin CavalierIf you have commit access:
89b87e672aSAugustin Cavalier```
90b87e672aSAugustin Cavaliergit clone ssh://git.haiku-os.org/haiku
91b87e672aSAugustin Cavaliergit clone ssh://git.haiku-os.org/buildtools
92b87e672aSAugustin Cavalier```
93b87e672aSAugustin Cavalier
94b87e672aSAugustin CavalierBuilding Jam
95b87e672aSAugustin Cavalier-------------------------------------------
969762e2feSAdrien Destugues(*This step applies only to non-Haiku platforms. Haiku already ships with the correct version of Jam*)
97b87e672aSAugustin Cavalier
98b87e672aSAugustin CavalierChange to the `buildtools` folder and run the following commands to
99b87e672aSAugustin Cavaliergenerate and install `jam`:
100b87e672aSAugustin Cavalier```
101b87e672aSAugustin Cavaliercd buildtools/jam
102b87e672aSAugustin Cavaliermake
103b87e672aSAugustin Cavaliersudo ./jam0 install
104b87e672aSAugustin Cavalier```
105b87e672aSAugustin CavalierOr,  if you don't want to install `jam` systemwide:
106b87e672aSAugustin Cavalier```
107b87e672aSAugustin Cavalier./jam0 -sBINDIR=$HOME/bin install
108b87e672aSAugustin Cavalier```
109b87e672aSAugustin Cavalier
110b87e672aSAugustin CavalierConfiguring the build
111b87e672aSAugustin Cavalier-------------------------------------
112b87e672aSAugustin CavalierThe `configure` script generates a file named `BuildConfig` in the
113b87e672aSAugustin Cavalier`generated/build` directory. As long as `configure` is not modified (!) and the
114b87e672aSAugustin Cavaliercross-compilation tools have not been updated, there is no need to call it again.
115b87e672aSAugustin CavalierFor rebuilding, you only need to invoke `jam` (see below). If you don't
116b87e672aSAugustin Cavalierupdate the source tree very frequently, you may want to execute `configure`
117b87e672aSAugustin Cavalierafter each update just to be on the safe side.
118b87e672aSAugustin Cavalier
119b87e672aSAugustin CavalierDepending on your goal, there are several different ways to configure Haiku.
120fc2c93fbSAugustin CavalierThe first way is to call configure from within your Haiku checkout's root. That
121fc2c93fbSAugustin Cavalierwill prepare a folder named 'generated', which will contain the compiled objects.
122b87e672aSAugustin CavalierAnother option is to manually created one or more `generated.*` folders and run
123b87e672aSAugustin Cavalierconfigure from within them. For example, imagine the following directory setup:
124b87e672aSAugustin Cavalier```
125fc2c93fbSAugustin Cavalierbuildtools/
126fc2c93fbSAugustin Cavalierhaiku/
127fc2c93fbSAugustin Cavalierhaiku/generated.x86gcc2
128b87e672aSAugustin Cavalier```
129b87e672aSAugustin Cavalier
1309762e2feSAdrien Destugues### Configure an x86_64 (GCC 8) build
1319762e2feSAdrien Destugues```bash
1329762e2feSAdrien Destuguescd haiku/generated.x86_64
1333e4b6636SPawan Wadhwani../configure --cross-tools-source ../../buildtools --build-cross-tools x86_64
1349762e2feSAdrien Destugues```
1359762e2feSAdrien Destugues
1369762e2feSAdrien Destugues### Configure a 32-bit GCC 2.95/GCC 8 Hybrid, from a non-Haiku platform
137b87e672aSAugustin Cavalier```bash
138fc2c93fbSAugustin Cavaliercd haiku/generated.x86gcc2
139fc2c93fbSAugustin Cavalier../configure \
1403e4b6636SPawan Wadhwani	--cross-tools-source ../../buildtools/ \
141d1f10fceSdsizzle	--build-cross-tools x86_gcc2 \
142b87e672aSAugustin Cavalier	--build-cross-tools x86
143b87e672aSAugustin Cavalier```
144b87e672aSAugustin Cavalier
1459762e2feSAdrien Destugues### Configure a 32-bit GCC 2.95/GCC 8 Hybrid, from Haiku
1469762e2feSAdrien Destugues```bash
147fc2c93fbSAugustin Cavaliercd haiku/generated.x86gcc2
148b87e672aSAugustin Cavalier../configure --target-arch x86_gcc2 --target-arch x86
149b87e672aSAugustin Cavalier```
150b87e672aSAugustin Cavalier
151b87e672aSAugustin CavalierAdditional information about GCC Hybrids can be found on the website,
152fc2c93fbSAugustin Cavalier<https://www.haiku-os.org/guides/building/gcc-hybrid>.
153b87e672aSAugustin Cavalier
154b87e672aSAugustin Cavalier### Configure options
155b87e672aSAugustin CavalierThe various runtime options for configure are documented in its onscreen help
156b87e672aSAugustin Cavalier```bash
157b87e672aSAugustin Cavalier./configure --help
158b87e672aSAugustin Cavalier```
159b87e672aSAugustin Cavalier
160b87e672aSAugustin CavalierBuilding via Jam
161b87e672aSAugustin Cavalier----------------------------
162b87e672aSAugustin Cavalier
163b87e672aSAugustin CavalierHaiku can be built in either of two ways, as disk image file (e.g. for use
164b87e672aSAugustin Cavalierwith emulators, to be written directly to a usb stick, burned as a compact
165b87e672aSAugustin Cavalierdisc) or as installation in a directory.
166b87e672aSAugustin Cavalier
167b87e672aSAugustin Cavalier### Running Jam
168b87e672aSAugustin Cavalier
169b87e672aSAugustin CavalierThere are various ways in which you can run `jam`:
170b87e672aSAugustin Cavalier
171b87e672aSAugustin Cavalier * If you have a single generated folder, you can run 'jam' from the top level of Haiku's trunk.
172b87e672aSAugustin Cavalier * If you have one or more generated folders, (e.g. generated.x86gcc2),
173b87e672aSAugustin Cavalier   you can `cd` into that directory and run `jam`.
174b87e672aSAugustin Cavalier * In either case, you can `cd` into a certain folder in the source tree (e.g.
175b87e672aSAugustin Cavalier   src/apps/debugger) and run jam -sHAIKU_OUTPUT_DIR=<path to generated folder>
176b87e672aSAugustin Cavalier
177b87e672aSAugustin CavalierBe sure to read `build/jam/UserBuildConfig.ReadMe` and `UserBuildConfig.sample`,
178b87e672aSAugustin Cavalieras they contain information on customizing your build of Haiku.
179b87e672aSAugustin Cavalier
180979de7d7SPanagiotis "Ivory" Vasilopoulos### Building a Haiku anyboot image (Nightly)
181b87e672aSAugustin Cavalier```
182979de7d7SPanagiotis "Ivory" Vasilopoulosjam -q @nightly-anyboot
183b87e672aSAugustin Cavalier```
184b87e672aSAugustin Cavalier
185979de7d7SPanagiotis "Ivory" VasilopoulosThis generates an image file named `haiku-nightly-anyboot.iso` in your output
186b87e672aSAugustin Cavalierdirectory under `generated/`.
187b87e672aSAugustin Cavalier
188979de7d7SPanagiotis "Ivory" Vasilopoulos### Building a Haiku raw image (Nightly)
189979de7d7SPanagiotis "Ivory" Vasilopoulos```
190979de7d7SPanagiotis "Ivory" Vasilopoulosjam -q @nightly-raw
191979de7d7SPanagiotis "Ivory" Vasilopoulos```
192979de7d7SPanagiotis "Ivory" Vasilopoulos
193979de7d7SPanagiotis "Ivory" VasilopoulosThis generates an image file named `haiku.image` in your output directory under
194979de7d7SPanagiotis "Ivory" Vasilopoulos`generated/`.
195979de7d7SPanagiotis "Ivory" Vasilopoulos
196b87e672aSAugustin Cavalier### Building a VMware image file
197b87e672aSAugustin Cavalier```
198979de7d7SPanagiotis "Ivory" Vasilopoulosjam -q @nightly-vmware
199b87e672aSAugustin Cavalier```
200979de7d7SPanagiotis "Ivory" Vasilopoulos
201b87e672aSAugustin CavalierThis generates an image file named `haiku.vmdk` in your output
202b87e672aSAugustin Cavalierdirectory under `generated/`.
203b87e672aSAugustin Cavalier
204b87e672aSAugustin Cavalier### Directory Installation
205b87e672aSAugustin Cavalier```
206b87e672aSAugustin CavalierHAIKU_INSTALL_DIR=/Haiku jam -q @install
207b87e672aSAugustin Cavalier```
208b87e672aSAugustin Cavalier
209b87e672aSAugustin CavalierInstalls all Haiku components into the volume mounted at "/Haiku" and
210b87e672aSAugustin Cavalierautomatically marks it as bootable. To create a partition in the first place
211b87e672aSAugustin Cavalieruse DriveSetup and initialize it to BFS.
212b87e672aSAugustin Cavalier
213b87e672aSAugustin CavalierNote that installing Haiku in a directory only works as expected under Haiku,
214b87e672aSAugustin Cavalierbut it is not yet supported under Linux and other non-Haiku platforms.
215b87e672aSAugustin Cavalier
216b87e672aSAugustin Cavalier### Building individual components
217b87e672aSAugustin CavalierIf you don't want to build the complete Haiku, but only a certain
218b87e672aSAugustin Cavalierapp/driver/etc. you can specify it as argument to jam, e.g.:
219b87e672aSAugustin Cavalier```
220b87e672aSAugustin Cavalierjam -q Debugger
221b87e672aSAugustin Cavalier```
222b87e672aSAugustin CavalierAlternatively, you can `cd` to the directory of the component you want to
223b87e672aSAugustin Cavalierbuild and run `jam` from there. **NOTE:** if your generated directory is named
224b87e672aSAugustin Cavaliersomething other than `generated/`, you will need to tell `jam` where it is:
225b87e672aSAugustin Cavalier```
226b87e672aSAugustin Cavalierjam -q -sHAIKU_OUTPUT_DIR=<path to generated folder>
227b87e672aSAugustin Cavalier```
228b87e672aSAugustin CavalierYou can also force the rebuild of a component by using the `-a` parameter:
229b87e672aSAugustin Cavalier```
230b87e672aSAugustin Cavalierjam -qa Debugger
231b87e672aSAugustin Cavalier```
232b87e672aSAugustin Cavalier
2331b1df682SAlexander von Gluck IVBootstrap Build
2341b1df682SAlexander von Gluck IV----------------
2351b1df682SAlexander von Gluck IVNew architectures (and occasionally existing ones) will require a bootstrap
2361b1df682SAlexander von Gluck IVbuild to compile *build packages*. (Catch-22 software packages which are needed
2371b1df682SAlexander von Gluck IVto compile Haiku, but need to be initially compiled under Haiku)
2381b1df682SAlexander von Gluck IV
2391b1df682SAlexander von Gluck IV### Pre-requirements
2401b1df682SAlexander von Gluck IV  * All of the standard tools in the Required Software section above.
2411b1df682SAlexander von Gluck IV  * The following repositories on disk in the same general location
2421b1df682SAlexander von Gluck IV    * haiku (https://git.haiku-os.org/haiku)
2431b1df682SAlexander von Gluck IV    * buildtools (https://git.haiku-os.org/buildtools)
2441b1df682SAlexander von Gluck IV    * haikuporter (https://github.com/haikuports/haikuporter.git)
2451b1df682SAlexander von Gluck IV    * haikuports.cross (https://github.com/haikuports/haikuports.cross.git)
2461b1df682SAlexander von Gluck IV    * haikuports (https://github.com/haikuports/haikuports.git)
2471b1df682SAlexander von Gluck IV
2481b1df682SAlexander von Gluck IV### Setting Up a Bootstrap build
2491b1df682SAlexander von Gluck IVCreate a clean build directory under the haiku repo.
2501b1df682SAlexander von Gluck IV```
2511b1df682SAlexander von Gluck IVmkdir generated.myarch && cd generated.myarch
2521b1df682SAlexander von Gluck IV```
2531b1df682SAlexander von Gluck IV
2541b1df682SAlexander von Gluck IVConfigure Haiku's build system for a bootstrap build specifying the location
2551b1df682SAlexander von Gluck IVof all of the repositories above.
2561b1df682SAlexander von Gluck IV```
2571b1df682SAlexander von Gluck IV../configure -j4 \
258d1f10fceSdsizzle  --build-cross-tools myarch --cross-tools-source ../../buildtools \
2591b1df682SAlexander von Gluck IV  --bootstrap ../../haikuporter/haikuporter ../../haikuports.cross ../../haikuports
2601b1df682SAlexander von Gluck IV```
2611b1df682SAlexander von Gluck IV
2621b1df682SAlexander von Gluck IVOnce the build system is configured for bootstrap, we now can begin building
2631b1df682SAlexander von Gluck IVthe bootstrap image.
2641b1df682SAlexander von Gluck IV
2651b1df682SAlexander von Gluck IV```
2661b1df682SAlexander von Gluck IVjam -q @bootstrap-raw
2671b1df682SAlexander von Gluck IV```
2681b1df682SAlexander von Gluck IV
2691b1df682SAlexander von Gluck IVIf you are bootstrapping for an architecture Haiku already boots on, the generated
2701b1df682SAlexander von Gluck IVdisk image can be used to compile *build packages* needed for the standard
2711b1df682SAlexander von Gluck IVHaiku build.
2721b1df682SAlexander von Gluck IV
2731b1df682SAlexander von Gluck IVIf you are bootstrapping for a new architecture which doesn't build yet, you will
2741b1df682SAlexander von Gluck IVneed to leverage the ```unbootstrap.sh``` script to hack the generated bootstrap
2751b1df682SAlexander von Gluck IVpackages into non-bootstrap packages which can be temporarily used as
2761b1df682SAlexander von Gluck IV*build packages*.
2771b1df682SAlexander von Gluck IV
278b87e672aSAugustin CavalierRunning
279b87e672aSAugustin Cavalier----------------
280b87e672aSAugustin CavalierGenerally there are two ways of running Haiku: on real hardware using a
281b87e672aSAugustin Cavalierpartition, and on emulated hardware using an emulator (like VirtualBox, or QEMU).
282b87e672aSAugustin Cavalier
283b87e672aSAugustin Cavalier### On Real Hardware
284b87e672aSAugustin CavalierIf you have installed Haiku to its own partition you can include this
285b87e672aSAugustin Cavalierpartition in your bootmanager and try to boot Haiku like any other OS you
286b87e672aSAugustin Cavalierhave installed. To include a new partition in the Haiku bootmanager, start
287b87e672aSAugustin Cavalierthe BootManager configurator by running:
288b87e672aSAugustin Cavalier```
289b87e672aSAugustin CavalierBootManager
290b87e672aSAugustin Cavalier```
291b87e672aSAugustin Cavalier
292b87e672aSAugustin Cavalier### On Emulated Hardware
293fc2c93fbSAugustin CavalierFor emulated hardware you should build a disk image (see above). How to set up
294b87e672aSAugustin Cavalierthis image depends on your emulator. If you use QEMU, you can usually just
295b87e672aSAugustin Cavalierprovide the path to the image as command line argument to the `qemu`
296b87e672aSAugustin Cavalierexecutable.
297