# build.sh

## Overview

`build.sh` is a shell script designed to automate a series of build and cleanup operations using the Ninja build system. It sequentially builds multiple targets defined in a Ninja build file named `build.linux.ninja`, and after each build, it performs a cleanup of the generated build artifacts. This script streamlines the process of building various components or configurations of the project and ensures the build environment is clean after each build step, likely to avoid cross-contamination between builds.

## Script Structure and Workflow

The script uses the following pattern repetitively for each build target:

1. **Cleanup:** Runs `ninja` with the `-t clean` target to remove all build outputs.

2. **Build:** Invokes `ninja` to build a specific target or the default one.

3. **Cleanup:** Runs the cleanup command again to remove build outputs before moving to the next target.

This sequence is repeated for the following targets:

* The default (main) target (no explicit target name)

* `memory`

* `perf`

* `perf-long`

* `perf-alloc`

* `perf-alloc-long`

* `perf-json-c`

* `perf-json-c-long`

Each `ninja` invocation references the same build manifest file, `build.linux.ninja`, with the `-f` flag, explicitly specifying which Ninja build file to use.

## Detailed Explanation of Commands

### Cleanup Command

```bash
ninja -f build.linux.ninja -t clean > /dev/null 2>&1

This command is executed before and after each build target to ensure a clean state.

Build Commands

Examples:

ninja -f build.linux.ninja
ninja -f build.linux.ninja memory

Usage Example

To execute the script, run:

./build.sh

This will sequentially build and clean each target as described.

Implementation Details

Interaction with Other System Components

Flowchart of Script Execution

flowchart TD
Start --> Clean1[Cleanup All Builds]
Clean1 --> BuildMain[Build Default Target]
BuildMain --> Clean2[Cleanup All Builds]
Clean2 --> BuildMemory[Build "memory" Target]
BuildMemory --> Clean3[Cleanup All Builds]
Clean3 --> BuildPerf[Build "perf" Target]
BuildPerf --> Clean4[Cleanup All Builds]
Clean4 --> BuildPerfLong[Build "perf-long" Target]
BuildPerfLong --> Clean5[Cleanup All Builds]
Clean5 --> BuildPerfAlloc[Build "perf-alloc" Target]
BuildPerfAlloc --> Clean6[Cleanup All Builds]
Clean6 --> BuildPerfAllocLong[Build "perf-alloc-long" Target]
BuildPerfAllocLong --> Clean7[Cleanup All Builds]
Clean7 --> BuildPerfJsonC[Build "perf-json-c" Target]
BuildPerfJsonC --> Clean8[Cleanup All Builds]
Clean8 --> BuildPerfJsonCLong[Build "perf-json-c-long" Target]
BuildPerfJsonCLong --> Clean9[Cleanup All Builds]
Clean9 --> End[End]

This flowchart illustrates the sequential execution order of the cleanup and build steps for each target.


This script is focused exclusively on invoking Ninja build commands in a controlled sequence and does not contain any functions, classes, or complex algorithms. Its purpose is to automate repetitive build and cleanup tasks cleanly and reliably.
```