Skip to content

Compilation instructions

Uwe Seimet edited this page Jan 27, 2025 · 37 revisions

Table of Contents

General build instructions

In order to build SCSI2Pi from the sources run GNU 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 lsscsi
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.

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 tries to be as platform independent as possible, and therefore also compiles on numerous non-Pi platforms. You can run the unit tests and use some of the binaries. You can even use s2ptool 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 up to date releases of FreeBSD, NetBSd and even macOS, provided that packages like GNU make, g++/clang++, protobuf and spdlog are installed. On macOS ensure that the include and library paths for the required homebrew packages are set correctly.

Using an alternative compiler/linker

clang++ compiles 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.

Clone this wiki locally