Skip to content

Commit 39e3295

Browse files
KimYannnclaude
andcommitted
build: auto-detect deps via pkg-config, unify static/dynamic linking
1. Add pkg-config auto-detection for libhwy, libisal, libdeflate. When installed via package managers (conda, brew, apt), their include/lib paths are automatically picked up without needing to pass INCLUDE_DIRS/LIBRARY_DIRS manually. 2. Unify linking: on Linux, keep -static when all .a archives exist (default). When some .a are missing (conda/apt shared-only), fallback to .a + -l dynamic. macOS unchanged. With this change, bioconda build.sh can simply call: make CXX=$CXX -j$CPU_COUNT make install PREFIX=$PREFIX Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fcf9166 commit 39e3295

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

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

0 commit comments

Comments
 (0)