7.2 KiB
Build system
Building an operating system is tricky: there are many different components to be built that all support varying configurations, and there are lots of dependencies (including compilers and assemblers) that need to be prepared. The Essence build system has been designed to make this as much of a streamlined process as is possible. And hopefully it is a lot easier than building other operating systems from scratch (for a comparison, see the wonderful "Linux From Scratch" books).
The build system is divided into three components. start.sh, util/build.c and util/build_core.c ("build core").
start.shfirst verifies the environment is acceptable for building Essence, and then it compiles and runsutil/build.c.util/build.cprovides a command prompt interface where the developer can issue commands to build and test project, and additionally manage configurations, emulators, ports and the source tree. It should be invoked by runningstart.sh. If you pass arguments tostart.sh, then they will be forwarded toutil/build.cand executed as a command; it will exit after this command completes. For example,./start.sh bwill build the system without requiring interaction.- Build core is responsible for actually building Essence components, and producing a finished drive image. It expects all dependencies and the toolchain to be prepared before it is executed. It is able to run within Essence itself (where dependencies and a toolchain are already provided). It has minimal interaction with the platform it is running on. It is typically invoked automatically by
util/build.c, which passes a description of the requested build inbin/build.ini. This includes information of the toolchain to use, enabled options, applications and drivers to compile, fonts to bundle, installation settings (such as how large the drive image should be), and other general settings (like how many threads to compile with, and whether optimisations are enabled).
util/build_common.h contains common definitions shared between these components.
util/build.c
The following commands are available in the interactive prompt:
helpPrint a list of the most commonly used commands, with a short description.exit,x,quit,qExit the interactive prompt.compile,cCompile the operating system components with optimisations disabled. This does not produce a drive image.build,bBuild the operating system tobin/drivewith optimisations disabled.build-optimised,optBuild the operating system tobin/drivewith optimisations enabled.debug,dBuild the operating system tobin/drivewith optimisations disabled, and then launch Qemu configured to wait for GDB to attach to it before starting.vbox,vBuild the operating system tobin/vbox.vdiwith optimisations enabled, and then launch VBox. To use this, you need to make a 128MB drive calledvbox.vdiin thebinfolder, and attach it to a virtual machine called "Essence" (choose "Windows 7 64-bit" as the OS).vbox-without-opt,v2Same asvbut with optimisations disabled.vbox-without-compile,v3Same asvbut compilation is skipped.qemu-with-opt,tBuild the operating system tobin/drivewith optimisations enabled, and then launch Qemu.test,t2Same astbut with optimisations disabled.qemu-without-compile,t3Same astbut compilation is skipped.qemu-with-kvm,kSame astbut Qemu is launched with the-enable-kvmflag. This results in significantly faster emulation. The command also disables theFlag.DEBUG_BUILDoption; see below for a description of this.build-crossForce a rebuild of the cross compiler toolchain.build-utilities,uBuild the utility applications only, which will run on the host development system. This is done automatically as needed by the other commands.make-installer-archiveCompress the contents ofroot/to make a archive for use by the system installer application. This outputs the filesbin/installer_archive.datandbin/installer_metadata.dat.make-installer-rootCopy all the needed files to make an installer image toroot/. You need to runmake-installer-archivefirst.font-editorCompile and launch the bitmap font editor utility application. This requires X11.configCompile and launch the config editor utility application. This requires X11.designer2Compile and launch the theme editor utility application. This requires X11.replace-manyReplace a list of strings in the source code. A file containing the strings to replace and their replacements is passed. Each line should be of the form<thing to replace> <what to replace it with>.replaceReplace a string in the source code. Only full words are matched.replace-inSame asreplace, except it only replaces in a single folder.findFind a string in the source code. Ignores binary files.find-wordSame asfind, except only the full word is matched. For example,atwould not matchcat.find-inSame asfind, except it looks in a single folder.fix-replaced-field-nameAfter renaming a structure field, run this to change all references to it. It parses the compiler errors to do this automatically.ascii <string>Converts a string to ASCII codepoints.build-optional-portsRuns theport.shscript in each of the folders inports/. If there is no script, the folder is skipped. Note that to use many of the ports the POSIX subsystem must be enabled.do <string>Run a command throughsystem().liveBuild a live CD or USB image. Work in progress.line-countCalculate the number of lines of code in the project.a2l <symbols file>Run the a2l utility. See the "a2l" section.build-portBuild a single port. A list of availble ports are listed.get-source <folder name> <url>The file at the URL is downloaded and cached inbin/cache. The download is skipped if the file was already cached. It is then extracted and untar'd. The folder of the given name is then moved tobin/source.make-crash-reportCopies various system files and logs into a.tar.gzwhich can be used to report a crash.setup-pre-built-toolchainSetup the pre-built toolchain for use by the build system. You can download and prepare it by running./start.sh get-source prefix https://github.com/nakst/build-gcc/releases/download/gcc-11.1.0/gcc-x86_64-essence.tar.xzfollowed by./start.sh setup-pre-built-toolchain.
Levels of optimisation
Commands in the build system provide two levels of optimisation, either with optimisations enabled or disabled. However, there is an additional configuration flag, Flag.DEBUG_BUILD which can be toggled in the configuration editor. This determines whether the DEBUG_BUILD flag will be defined in the source code or not. When this flag is defined, many expensive checks are performed to constantly validate the operating system's data structures. To make a "fully optimised" build of Essence, you should first disable this flag, and then build with optimisations enabled.
Note that some commands will force disable the Flag.DEBUG_BUILD option. Most notably, the k command.
Build core
TODO
Configuration editor
TODO
Configuration options
TODO
a2l
TODO