Skip to content

Compilation instructions

Uwe Seimet edited this page Mar 26, 2024 · 22 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 build an optimized build. You obtain a debug build with
make DEBUG=1
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 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. Run s2pctl on your local PC and connect to your Pi with the -h option, for instance.
SCSI2Pi compiles with g++ and clang++ on a Linux PC (amd64 or aarch64), and with clang++ on FreeBSD 14.0 and NetBSD 10.0, provided that packages like GNU make, g++/clang++, protobuf or spdlog are installed. In particular with FreeBSD and NetBSD the latest compiler versions have to be installed. On macos 13 everything compiles but not everything links against protobuf@3, though, which appears to be a macos/homebrew library issue.
All required packages are available for installation with the respective package managers or homebrew.

Using an alternative compiler/linker

The clang++ compiler is faster than g++ and needs less memory. You can select the compiler with the CXXFLAGS, e.g.:

export CXXFLAGS="clang++"

Linkers like "mold", "gold" or "lld" are faster than the regular "bfd" linker. You can 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.