Skip to content

How are source trees structured?

Joel Nider edited this page Jan 19, 2022 · 2 revisions

A source tree is the organization of all the source code required to build a project. The result can be a library, an executable, or multiple different targets. A build system must understand the structure of the source tree. The following is a description of common source tree structures, and how bake can be used in each case.

Simple

The simple tree does not use any paths. A project of this type has some input files in the root directory, and is used to produce a target in the root directory. Any intermediate files also live in the root directory. This is commonly used in projects that have a small number of source files (Hello world).

root
+-- hello.c
+-- hello.elf
+-- recipe

Subdirectories

When source trees get a little bigger, it is common to separate source files and header files into subdirectories. Intermediate files can be created in either the root directory or in the subdirectories alongside the corresponding source files. Since there is only a single target and all source files live together, they can be built with a single recipe file.

root
+-- src_a/
|   +-- file1.c
|   +-- file2.c
|   +-- file3.c
+-- include/
|   +-- header1.h
+-- target.elf
+-- recipe

Libraries

Libraries allow for more control over integration. The libraries can be written by independent development teams, can be from different source control repos and versioned differently. At this point in the source tree progression, each library should have its own recipe. Think of making a cake: one recipe describes the cake itself, while another recipe describes the icing. Together, they are used to make a single cake, but each sub-product (cake, icing) can be produced and understood independently.

root
+-- src_a/
|   +-- include/
|   |   +-- header2.h
|   +-- file1.c
|   +-- file2.c
|   +-- lib_a.a
|   +-- recipe
+-- src_b/
|   +-- include/
|   |   +-- header3.h
|   +-- file3.c
|   +-- file4.c
|   +-- lib_b.a
|   +-- recipe
+-- include/
|   +-- header1.h
+-- target.elf
+-- recipe

Clone this wiki locally