Skip to content

Compilation instructions

Uwe Seimet edited this page Nov 25, 2024 · 34 revisions

Table of Contents

General build instructions

In order to build SCSI2Pi from the sources run make in the top-level folder. You may have to install some additional packages first.

sudo apt install -y g++ make protobuf-compiler libspdlog-dev libgmock-dev
git clone https://github.com/uweseimet/scsi2pi
cd scsi2pi
git checkout develop
make
This will run an optimized build for all binaries. You get a debug build with
make DEBUG=1
If you only want to build a subset of the binaries, specify the respective build targets, e.g.
make s2p s2pctl
Debug builds have assertions enabled and run slower, but they compile faster.
sudo make install installs the binaries and manpages in /opt/scsi2pi. make help displays information on the available build targets.
SCSI2Pi tries to be as platform independent as possible. While the board hareware requires a Pi, numerous other platforms can be used for development (e.g. with an IDE like Eclipse CDT), for running the unit tests and for testing the SCSI layer with the in-process bus.

Compiling, testing and running on a Raspberry Pi

SCSI2Pi compiles with g++ and clang++ and supports 32 and 64 bit operating systems. After a successful make you can compile and run the unit tests with make test.

Compiling, testing and running on non-Pi platforms

SCSI2Pi also compiles on numerous non-Pi platforms. You can run the unit tests and use some of the binaries for testing purposes. You can even use the in_process_test to execute SCSI commands within the s2p process. Or you run s2pctl on your local PC and connect to your Pi with the -h option.
SCSI2Pi compiles with g++ and/or clang++ on a Linux PC (amd64 or aarch64), on FreeBSD 14.1 and NetBSD 10.0, provided that packages like GNU make, g++/clang++, protobuf and spdlog are installed. In particular with FreeBSD and NetBSD the latest compiler versions have to be used. On macos 15 everything compiles as long as the include and library paths for the required homebrew packages are set correctly.

Using an alternative compiler/linker

The clang++ compiler is faster than g++ and needs less memory. You change the compiler like this:

make CXX=clang++
Note that on some platforms with clang++ linking may fail because the protobuf library was built with a different toolchain than clang++. In such a case, use g++.

Linkers like "mold", "gold" or "lld" are faster than the regular "bfd" linker. You select the linker with the LDFLAGS, e.g.:
export LDFLAGS="-fuse-ld=lld"

Of the linkers listed above "mold" is the fastest, followed by "lld". On a Pi Zero alternative linkers save several minutes of build time.

Link-time optimization

The SCSI2Pi binaries can be further optimized/shrunk by enabling link-time optimization:

export EXTRA_FLAGS="-flto"

With this setting the amount of memory and the time needed for compiling and linking increase. On Pis with only 512 MB of main memory this optimization cannot be used. The SCSI2Pi binary packages are built with this optimization.