Skip to content

Commit 491d3cb

Browse files
authored
Merge pull request #668 from KimBioInfoStudio/fix/makefile-conda-compat
build: unify static/dynamic linking for conda/package manager compatibility
2 parents fcf9166 + 596e5bb commit 491d3cb

7 files changed

Lines changed: 50 additions & 1390 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,45 @@ jobs:
2424
if: runner.os == 'Linux'
2525
run: |
2626
sudo apt-get update
27-
sudo apt-get install -y build-essential libdeflate-dev nasm
27+
sudo apt-get install -y build-essential nasm
2828
2929
- name: build ISA-L static (Ubuntu)
3030
if: runner.os == 'Linux'
3131
run: |
32-
git clone --depth=1 --branch v2.31.0 https://github.com/intel/isa-l.git /tmp/isa-l
32+
git clone --depth=1 --branch v2.31.1 https://github.com/intel/isa-l.git /tmp/isa-l
3333
cd /tmp/isa-l
3434
./autogen.sh
35-
./configure --prefix=/tmp/isal-install --enable-static --disable-shared
35+
./configure --prefix=/usr/local --enable-static --disable-shared
3636
make -j$(nproc)
37-
make install
37+
sudo make install
38+
39+
- name: build libdeflate static (Ubuntu)
40+
if: runner.os == 'Linux'
41+
run: |
42+
git clone --depth=1 --branch v1.23 https://github.com/ebiggers/libdeflate.git /tmp/libdeflate
43+
cd /tmp/libdeflate
44+
cmake -B _build -DCMAKE_BUILD_TYPE=Release \
45+
-DLIBDEFLATE_BUILD_STATIC_LIB=ON -DLIBDEFLATE_BUILD_SHARED_LIB=OFF \
46+
-DLIBDEFLATE_BUILD_GZIP=OFF -DCMAKE_INSTALL_PREFIX=/usr/local
47+
cmake --build _build -j$(nproc)
48+
sudo cmake --install _build
3849
3950
- name: install dependencies (macOS)
4051
if: runner.os == 'macOS'
4152
run: brew install libdeflate isa-l
4253

43-
- name: build Highway static
54+
- name: build Highway
4455
run: |
4556
git clone --depth=1 --branch 1.3.0 https://github.com/google/highway.git /tmp/highway
4657
cd /tmp/highway
4758
cmake -B _build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
4859
-DHWY_ENABLE_TESTS=OFF -DHWY_ENABLE_EXAMPLES=OFF \
49-
-DCMAKE_INSTALL_PREFIX=/tmp/hwy-install
60+
-DCMAKE_INSTALL_PREFIX=/usr/local
5061
cmake --build _build -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
51-
cmake --install _build
62+
sudo cmake --install _build
5263
5364
- name: build fastp
54-
run: |
55-
EXTRA_INC="" EXTRA_LIB=""
56-
for prefix in /tmp/hwy-install /tmp/isal-install; do
57-
[ -d "$prefix/include" ] && EXTRA_INC="$EXTRA_INC $prefix/include"
58-
[ -d "$prefix/lib" ] && EXTRA_LIB="$EXTRA_LIB $prefix/lib"
59-
[ -d "$prefix/lib64" ] && EXTRA_LIB="$EXTRA_LIB $prefix/lib64"
60-
done
61-
make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) \
62-
INCLUDE_DIRS="$EXTRA_INC" LIBRARY_DIRS="$EXTRA_LIB"
65+
run: make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
6366

6467
- name: smoke test
6568
run: |

Makefile

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ BINDIR ?= $(PREFIX)/bin
77
INCLUDE_DIRS ?=
88
LIBRARY_DIRS ?=
99

10+
# Auto-detect library paths via pkg-config (works with conda, brew, system packages)
11+
PKG_CONFIG ?= pkg-config
12+
HWY_CFLAGS := $(shell $(PKG_CONFIG) --cflags libhwy 2>/dev/null)
13+
HWY_LIBS := $(shell $(PKG_CONFIG) --libs-only-L libhwy 2>/dev/null)
14+
ISAL_CFLAGS := $(shell $(PKG_CONFIG) --cflags libisal 2>/dev/null)
15+
ISAL_LIBS := $(shell $(PKG_CONFIG) --libs-only-L libisal 2>/dev/null)
16+
DEFLATE_CFLAGS := $(shell $(PKG_CONFIG) --cflags libdeflate 2>/dev/null)
17+
DEFLATE_LIBS := $(shell $(PKG_CONFIG) --libs-only-L libdeflate 2>/dev/null)
18+
1019
SRC := $(wildcard ${DIR_SRC}/*.cpp)
1120
OBJ := $(patsubst %.cpp,${DIR_OBJ}/%.o,$(notdir ${SRC}))
1221

@@ -15,23 +24,31 @@ TARGET := fastp
1524
BIN_TARGET := ${TARGET}
1625

1726
CXX ?= g++
18-
CXXFLAGS := -std=c++11 -pthread -g -O3 -MD -MP -I. -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) ${CXXFLAGS}
27+
CXXFLAGS := -std=c++11 -pthread -g -O3 -MD -MP -I. -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) $(HWY_CFLAGS) $(ISAL_CFLAGS) $(DEFLATE_CFLAGS) ${CXXFLAGS}
1928
LIBS := -lisal -ldeflate -lhwy -lpthread
2029

30+
PKG_LDFLAGS := $(HWY_LIBS) $(ISAL_LIBS) $(DEFLATE_LIBS)
31+
2132
UNAME_S := $(shell uname -s)
33+
FIND_STATIC = $(firstword $(foreach d,$(LIBRARY_DIRS),$(wildcard $(d)/lib$(1).a)) $(wildcard /usr/local/lib/lib$(1).a /opt/homebrew/lib/lib$(1).a))
34+
STATIC_LIBS :=
35+
DYNAMIC_LIBS :=
36+
$(foreach lib,isal deflate hwy,\
37+
$(if $(call FIND_STATIC,$(lib)),\
38+
$(eval STATIC_LIBS += $(call FIND_STATIC,$(lib))),\
39+
$(eval DYNAMIC_LIBS += -l$(lib))))
40+
2241
ifeq ($(UNAME_S),Linux)
23-
# Linux: fully static binary
24-
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) -static -Wl,--no-as-needed -pthread $(LIBS) $(LD_FLAGS)
42+
ifeq ($(DYNAMIC_LIBS),)
43+
# All .a found: fully static binary (default for Linux)
44+
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_LDFLAGS) -static -Wl,--no-as-needed -pthread $(LIBS) $(LD_FLAGS)
45+
else
46+
# Some .a missing (e.g. conda): link .a directly + dynamic fallback
47+
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_LDFLAGS) $(STATIC_LIBS) $(DYNAMIC_LIBS) -lpthread $(LD_FLAGS)
48+
endif
2549
else
26-
# macOS: link 3rd-party libs statically via .a when available, fallback to dynamic
27-
FIND_STATIC = $(firstword $(foreach d,$(LIBRARY_DIRS),$(wildcard $(d)/lib$(1).a)) $(wildcard /usr/local/lib/lib$(1).a /opt/homebrew/lib/lib$(1).a))
28-
STATIC_LIBS :=
29-
DYNAMIC_LIBS :=
30-
$(foreach lib,isal deflate hwy,\
31-
$(if $(call FIND_STATIC,$(lib)),\
32-
$(eval STATIC_LIBS += $(call FIND_STATIC,$(lib))),\
33-
$(eval DYNAMIC_LIBS += -l$(lib))))
34-
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(STATIC_LIBS) $(DYNAMIC_LIBS) -lpthread $(LD_FLAGS)
50+
# macOS: .a preferred, fallback to dynamic
51+
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_LDFLAGS) $(STATIC_LIBS) $(DYNAMIC_LIBS) -lpthread $(LD_FLAGS)
3552
endif
3653

3754

src/fastqreader.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ SOFTWARE.
3131
#include "common.h"
3232
#include <iostream>
3333
#include <fstream>
34-
#if __has_include(<isa-l/igzip_lib.h>)
3534
#include <isa-l/igzip_lib.h>
36-
#else
37-
#include "igzip_lib.h"
38-
#endif
3935
#include "readpool.h"
4036

4137
class FastqReader{

0 commit comments

Comments
 (0)