-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
182 lines (144 loc) · 4.59 KB
/
Copy pathMakefile
File metadata and controls
182 lines (144 loc) · 4.59 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# --- Flags og kompileringsvalg ---
FLAGS ?= -O2 -Wall -Wextra
CFLAGS += $(FLAGS) -MMD -MP
CXXFLAGS += $(FLAGS) -MMD -MP
# CPPFLAGS += <- dont think we need this
LDFLAGS +=
LDLIBS += -lgsl -lgslcblas -lz -lm -lpthread
LDHTS := -lbz2 -llzma -lcurl
CC ?= gcc
CXX ?= g++
CXXSRC := $(wildcard *.cpp)
CSRC := $(wildcard *.c)
OBJ := $(CSRC:.c=.o) $(CXXSRC:.cpp=.o)
#$(info PREFIX before = '$(PREFIX)')
ifneq ($(strip $(PREFIX)),)
override PREFIX := $(abspath $(PREFIX))
endif
#$(info PREFIX after = '$(PREFIX)')
ifneq ($(strip $(EXTRA_INC)),)
override EXTRA_INC := $(foreach d,$(EXTRA_INC),$(abspath $(d)))
endif
ifneq ($(strip $(EXTRA_LIB)),)
override EXTRA_LIB := $(foreach d,$(EXTRA_LIB),$(abspath $(d)))
endif
ifneq ($(strip $(PREFIX)),)
CPPFLAGS += -I$(PREFIX)/include
LDFLAGS += -L$(PREFIX)/lib
endif
ifneq ($(strip $(EXTRA_INC)),)
CPPFLAGS += $(addprefix -I,$(EXTRA_INC))
endif
ifneq ($(strip $(EXTRA_LIB)),)
LDFLAGS += $(addprefix -L,$(EXTRA_LIB))
endif
ifneq ($(strip $(EXTRA_LIBS)),)
LDLIBS += $(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)
# --- 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)
LDLIBS += -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)
LDLIBS += -lhts
LIBHTS :=
else
# Use HTSSRC directly for include path
CPPFLAGS += -I$(HTSSRC)
LIBHTS := $(HTSSRC)/libhts.a
LDLIBS := $(LIBHTS) $(LIBS) $(LDHTS) $(LDLIBS)
$(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.5.0
ifneq ("$(wildcard .git)","")
PACKAGE_VERSION := $(shell git describe --tags --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) $(LDFLAGS) $(LDLIBS)
.PHONY: misc
misc: $(LIBHTS) $(OBJ)
$(MAKE) -C misc HTSSRC=$(ABSPATH) PREFIX="$(PREFIX)"
# --- Automatisk afhængighedshåndtering ---
-include $(OBJ:.o=.d)
bfgs.o: bfgs.cpp $(LIBHTS)
$(CXX) -c $(CPPFLAGS) $(filter-out -Wall -Wextra,$(CXXFLAGS)) -w $< -o $@
%.o: %.c $(LIBHTS)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
%.o: %.cpp $(LIBHTS)
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
# --- Rens og tests ---
.PHONY: clean test testclean force
.PHONY: print
print:
@echo "---- COMPILER ----"
@echo "CC = $(CC)"
@echo "CXX = $(CXX)"
@echo ""
@echo "---- FLAGS ----"
@echo "CFLAGS = $(CFLAGS)"
@echo "CXXFLAGS = $(CXXFLAGS)"
@echo "CPPFLAGS = $(CPPFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "LDLIBS = $(LDLIBS)"
@echo ""
@echo "---- ORIGIN ----"
@echo "CFLAGS origin = $(origin CFLAGS)"
@echo "CXXFLAGS origin = $(origin CXXFLAGS)"
@echo "CPPFLAGS origin = $(origin CPPFLAGS)"
@echo "LDFLAGS origin = $(origin LDFLAGS)"
@echo "LDLIBS origin = $(origin LDLIBS)"
clean:
rm -f *.o *.d $(PROGRAM) version.h *~
ifneq ($(HTSSRC),systemwide)
rm -rf $(HTSSRC)
endif
$(MAKE) -C misc clean
testclean:
rm -f test/*.bam.bin test/*.log test/testAll.sh.log test/testAll2.sh.log
rm -f test/*.bam
rm -rf test/output_extract_reads
rm -f test/data/f570b1db7c.dedup.filtered.rname.bam
rm -rf test/output test/output_data2 test/output_data2_gd test/output_compressbam
test:
@echo "Running unit tests for metaDMG"
cd test ; ./testAll2.sh
force: