-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (109 loc) · 3.36 KB
/
Makefile
File metadata and controls
138 lines (109 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# --- Flags og kompileringsvalg ---
FLAGS := -O3
CFLAGS := $(FLAGS)
CXXFLAGS := $(FLAGS)
CPPFLAGS := $(CPPFLAGS) -Wall -Wextra
LDFLAGS := -lgsl -lgslcblas
CC ?= gcc
CXX ?= g++
CXXSRC := $(wildcard *.cpp)
CSRC := $(wildcard *.c)
OBJ := $(CSRC:.c=.o) $(CXXSRC:.cpp=.o)
# --- Brugervalgte paths og biblioteker ---
ifdef PREFIX
CPPFLAGS += -I$(PREFIX)/include
LDFLAGS := -L$(PREFIX)/lib $(LDFLAGS)
endif
ifdef EXTRA_INC
CPPFLAGS += $(addprefix -I,$(EXTRA_INC))
endif
ifdef EXTRA_LIB
LDFLAGS := $(addprefix -L,$(EXTRA_LIB)) $(LDFLAGS)
endif
ifdef EXTRA_LIBS
LIBS += $(EXTRA_LIBS)
endif
# --- Crypto library detektion ---
HAVE_CRYPTO := $(shell echo 'int main(){}'|$(CXX) -x c++ - -lcrypto -o /dev/null 2>/dev/null && echo 0 || echo 1)
LIBS := -lz -lm -lbz2 -llzma -lpthread -lcurl
# --- Mål og bygning ---
PROGRAM = metaDMG-cpp
all: version.h $(PROGRAM) misc
ifeq ($(HAVE_CRYPTO),0)
$(info Crypto library is available to link; adding -lcrypto)
LIBS += -lcrypto
else
$(info Crypto library is not available to link; skipping -lcrypto)
endif
# --- HTSLIB håndtering ---
# HTSSRC is an absolute path (e.g., $(CURDIR)/htslib or user-specified)
ifndef HTSSRC
$(info HTSSRC not defined; cloning htslib from GitHub)
HTSSRC := $(CURDIR)/htslib
ABSPATH=$(HTSSRC) #donkykong
endif
ABSPATH=$(HTSSRC) #donkykong
ifeq ($(HTSSRC),systemwide)
$(info HTSSRC set to systemwide; using systemwide installation)
LIBS += -lhts
LIBHTS :=
else
# Use HTSSRC directly for include path
CPPFLAGS += -I$(HTSSRC)
LIBHTS := $(HTSSRC)/libhts.a
LIBS := $(LIBHTS) $(LIBS)
$(PROGRAM): $(LIBHTS)
ifneq ($(filter /%,$(HTSSRC)),$(HTSSRC))
ABSPATH=../$(HTSSRC)
endif
endif
# Ensure htslib is cloned and built only if libhts.a is missing
$(LIBHTS): .clone_htslib
.clone_htslib:
@if [ ! -d "$(HTSSRC)" ]; then \
echo "Cloning htslib into $(HTSSRC) with submodules..."; \
git clone --recursive https://github.com/samtools/htslib.git $(HTSSRC) || { echo "Clone failed"; exit 1; }; \
else \
echo "$(HTSSRC) already exists, skipping clone."; \
fi
@if [ ! -f "$(LIBHTS)" ]; then \
$(MAKE) -C $(HTSSRC) libhts.a || { echo "Failed to build libhts.a"; exit 1; }; \
else \
echo "$(LIBHTS) already exists, skipping build."; \
fi
$(info CPPFLAGS=$(CPPFLAGS) HTSSRC=$(HTSSRC) (absolute path))
# --- Versionsnummer og version.h ---
PACKAGE_VERSION := 0.4
ifneq ("$(wildcard .git)","")
PACKAGE_VERSION := $(shell git describe --always --dirty)
endif
version.h:
@echo '#define METADAMAGE_VERSION "$(PACKAGE_VERSION)"' > version.h.tmp
@cmp -s version.h.tmp version.h || mv version.h.tmp version.h
@rm -f version.h.tmp
$(PROGRAM): version.h $(OBJ) $(LIBHTS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
.PHONY: misc
misc: $(LIBHTS) $(OBJ)
$(MAKE) -C misc HTSSRC=$(ABSPATH)
# --- Automatisk afhængighedshåndtering ---
-include $(OBJ:.o=.d)
%.o: %.c $(LIBHTS)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
$(CC) -MM $(CPPFLAGS) $(CFLAGS) $< > $*.d
%.o: %.cpp $(LIBHTS)
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $*.d
# --- Rens og tests ---
.PHONY: clean test testclean force
clean:
rm -f *.o *.d $(PROGRAM) version.h *~
rm -rf $(HTSSRC)
$(MAKE) -C misc clean
testclean:
rm -f test/*.bam.bin test/data/*.bam
rm -rf test/output test/logfile version.h
test:
@echo "Running unit tests for metaDMG"
cd test ; ./testAll.sh
force: