Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 63 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,56 +1,74 @@
CC= gcc
CFLAGS= -g -Wall -O2
DFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DBGZF_CACHE
LOBJS= bgzf.o kstring.o bam_aux.o bam.o bam_import.o bam_index.o sam_header.o bedutil.o commons.o
PROG= bamdst
INCLUDES= -Isamlib/ -I.
SUBDIRS= . samlib
LIBPATH= -L.
CFLAGS= -g -Wall -O2 -std=gnu99
DFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE

# Source files
SOURCES= xamdst.c kstring.c bedutil.c commons.c
PROG= xamdst

# ---- htslib configuration ---------------------------------------------------
# Resolution order:
# 1. HTSLIB_DIR=<path> explicit override (a built htslib source tree)
# 2. system htslib detected via pkg-config
# 3. sibling ./htslib local source tree -- libhts.a is auto-built if missing
# 4. otherwise error
#
# If static linking fails with "cannot find -lbz2/-llzma", your htslib was
# built without them -- override:
# make HTSLIB_DEPS="-lz -lpthread -lm"
HTSLIB_DIR ?=

ifeq ($(HTSLIB_DIR),)
HAVE_PKG_HTSLIB := $(shell pkg-config --exists htslib 2>/dev/null && echo yes)
ifneq ($(HAVE_PKG_HTSLIB),)
# 2. system htslib (pkg-config)
HTSLIB_CFLAGS := $(shell pkg-config --cflags htslib)
HTSLIB_LIBS := $(shell pkg-config --libs htslib)
else
ifneq ($(wildcard htslib/htslib/hts.h),)
# 3. sibling ./htslib source tree (libhts.a auto-built below)
HTSLIB_CFLAGS := -Ihtslib
HTSLIB_LIBS := htslib/libhts.a
HTSLIB_DEPS ?= -lz -lbz2 -llzma -lpthread -lm
HTSLIB_BUILD := htslib/libhts.a
else
# 4. not found
$(error htslib not found. \
Install htslib system-wide (then pkg-config detects it), \
or clone it as a sibling: `git clone https://github.com/samtools/htslib htslib`, \
or pass HTSLIB_DIR=/path/to/htslib)
endif
endif
else
# 1. explicit override
HTSLIB_CFLAGS := -I$(HTSLIB_DIR)
HTSLIB_LIBS := $(HTSLIB_DIR)/libhts.a
HTSLIB_DEPS ?= -lz -lbz2 -llzma -lpthread -lm
HTSLIB_BUILD := $(HTSLIB_DIR)/libhts.a
endif

INCLUDES= -I. $(HTSLIB_CFLAGS)
LIBS= $(HTSLIB_LIBS) $(HTSLIB_DEPS) -lz -lpthread -lm

.SUFFIXES:.c .o
.PHONY: all
.PHONY: all clean

# auto-build the local htslib (handles a git clone: autoreconf + configure + make)
ifdef HTSLIB_BUILD
$(HTSLIB_BUILD):
cd $(dir $(HTSLIB_BUILD)) && \
(test -f configure || autoreconf -i) && \
(test -f config.status || ./configure) && \
$(MAKE)
endif

.c.o:
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@

all:clean $(PROG)

.PHONY:all clean

lib:libbam.a

libbam.a:$(LOBJS)
$(AR) -csru $@ $(LOBJS)

bamdst:lib $(AOBJS) samlib/bam.h
$(CC) $(CFLAGS) -o $@ $(AOBJS) $(LDFLAGS) bamdst.c $(LIBPATH) $(INCLUDES) -lm -lbam -lz

bgzf.o:bgzf.c bgzf.h
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) bgzf.c -o $@

kstring.o:kstring.c kstring.h
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) kstring.c -o $@

bam.o:samlib/bam.h samlib/bam_endian.h kstring.h samlib/sam_header.h samlib/bam.c
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) samlib/bam.c -o $@

bam_import.o:samlib/bam.h kseq.h khash.h samlib/bam_import.c
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) samlib/bam_import.c -o $@

bam_index.o:samlib/bam.h khash.h ksort.h samlib/bam_endian.h samlib/bam_index.c
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) samlib/bam_index.c -o $@

sam_header.o:samlib/sam_header.h khash.h samlib/sam_header.c
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) samlib/sam_header.c -o $@

bam_aux.o:samlib/bam.h samlib/bam_aux.c khash.h
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) samlib/bam_aux.c -o $@

commons.o:commons.c commons.h
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) commons.c -o $@
all:clean $(PROG)

bedutil.o:bedutil.c bedutil.h
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) bedutil.c -o $@
xamdst: $(SOURCES:.c=.o) $(HTSLIB_BUILD)
$(CC) $(CFLAGS) -o $@ $(SOURCES:.c=.o) $(INCLUDES) $(LIBS)

clean:
rm -fr gmon.out *.o a.out *.exe *.dSYM $(PROG) *~ *.a target.dep *.plot *.report *.tsv.gz uncover.bed
Loading