diff --git a/Makefile b/Makefile index 9e15043..1e23534 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,22 @@ NVBIT_PATH=./third_party/nvbit/core INCLUDES=-I$(NVBIT_PATH) -I./$(INCLUDE_DIR) -I./third_party # Libraries -LIBS=-L$(NVBIT_PATH) -lnvbit -lzstd +# Dynamically find static zstd library for self-contained builds +# Priority: 1) pkg-config, 2) common system paths +# Note: -lpthread is required because zstd uses POSIX threads internally +ZSTD_STATIC := $(shell pkg-config --variable=libdir libzstd 2>/dev/null)/libzstd.a +ifeq ($(wildcard $(ZSTD_STATIC)),) + ZSTD_STATIC := $(shell for p in /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib; do \ + if [ -f "$$p/libzstd.a" ]; then echo "$$p/libzstd.a"; break; fi; done) +endif +ifeq ($(ZSTD_STATIC),) + $(warning WARNING: libzstd.a not found - falling back to dynamic linking.) + $(warning WARNING: The resulting binary will NOT be self-contained/portable.) + $(warning WARNING: Install static library with: dnf install libzstd-static (RHEL/Fedora) or apt install libzstd-dev (Ubuntu/Debian)) + ZSTD_STATIC := -lzstd +endif + +LIBS=-L$(NVBIT_PATH) -lnvbit $(ZSTD_STATIC) -lpthread NVCC_PATH=-L $(subst bin/nvcc,lib64,$(shell which nvcc | tr -s /)) # Identify inject_funcs.cu specifically diff --git a/readme.md b/readme.md index aaea544..8ece312 100644 --- a/readme.md +++ b/readme.md @@ -28,14 +28,21 @@ git clone git@github.com:facebookresearch/CUTracer.git cd CUTracer ``` -2. Install system dependencies (libzstd): +2. Install system dependencies (libzstd static library for self-contained builds): ```bash # Ubuntu/Debian +# On most Ubuntu/Debian systems, libzstd-dev provides both shared and static libs (libzstd.a). +# You can verify this with: dpkg -L libzstd-dev | grep 'libzstd.a' +# If your distribution does not ship the static library in libzstd-dev, you may need to +# build zstd from source or install a distro-specific static libzstd package. sudo apt-get install libzstd-dev -# CentOS/RHEL -sudo dnf install libzstd-devel +# CentOS/RHEL/Fedora (static library for portable builds) +sudo dnf install libzstd-static + +# If static library is not available, the build will fall back to dynamic linking +# and display a warning. The resulting binary will not be self-contained. ``` 3. Download third-party dependencies: