# Linux Kernel Module Cheat

#### 38.13.3. gem5 build variants

Analogous to the Linux kernel build variants but with the `--gem5-build-id` option instead:

    # Build master.
    ./build-gem5

    # Build another branch.
    git -C "$(./getvar gem5_source_dir)" checkout some-branch
    ./build-gem5 --gem5-build-id some-branch

    # Restore master.
    git -C "$(./getvar gem5_source_dir)" checkout -

    # Run master.
    ./run --emulator gem5

    # Run another branch.
    git -C "$(./getvar gem5_source_dir)" checkout some-branch
    ./run --gem5-build-id some-branch --emulator gem5

Don’t forget however that gem5 has Python scripts in its source code tree, and that those must match the source code of a given build.

Therefore, you can’t forget to checkout to the sources to that of the corresponding build before running, unless you explicitly tell gem5 to use a non-default source tree with gem5 worktree. This becomes inevitable when you want to launch multiple simultaneous runs at different checkouts.

- gem5 worktree

- gem5 private source trees