Debian Codegraph @

Makefile

raw ◀ ▶
3 Debian patches touch this file
1
2 # ==========================
3 # BEDTools Makefile
4 # (c) 2009 Aaron Quinlan
5 # ==========================
6
7 SHELL := /bin/bash -e
8
9 VERSION_FILE=./src/utils/version/version_git.h
10 RELEASED_VERSION_FILE=./src/utils/version/version_release.txt
11
12
13 # define our object and binary directories
14 ifeq ($(VERBOSE),1)
15 CCPREFIX =
16 else
17 CCPREFIX = @
18 endif
19
20 OBJ_DIR = obj
21 BIN_DIR = bin
22 SRC_DIR = src
23
24 CXX = g++
25
26 PYTHON ?= $(shell python --version >/dev/null 2>&1 && echo "python" || echo python3)
27
28 ifeq ($(DEBUG),1)
29 BT_CPPFLAGS = -DDEBUG -D_DEBUG -D_FILE_OFFSET_BITS=64 -DWITH_HTS_CB_API $(INCLUDES)
30 BT_CXXFLAGS = -Wconversion -Wall -Wextra -g -O0
31 else
32 BT_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -DWITH_HTS_CB_API $(INCLUDES)
33 BT_CXXFLAGS = -g -Wall -O2
34 endif
35
36 # If the user has specified to do so, tell the compile to use rand() (instead of mt19937).
37 ifeq ($(USE_RAND),1)
38 BT_CXXFLAGS += -DUSE_RAND
39 else
40 BT_CXXFLAGS += -std=c++11
41 endif
42
43 BT_LDFLAGS =
44 BT_LIBS = -lz -lm -lbz2 -llzma -lpthread
45
46 prefix ?= /usr/local
47
48 SUBDIRS = $(SRC_DIR)/annotateBed \
49 $(SRC_DIR)/bamToBed \
50 $(SRC_DIR)/bamToFastq \
51 $(SRC_DIR)/bedToBam \
52 $(SRC_DIR)/bedpeToBam \
53 $(SRC_DIR)/bedToIgv \
54 $(SRC_DIR)/bed12ToBed6 \
55 $(SRC_DIR)/closestFile \
56 $(SRC_DIR)/clusterBed \
57 $(SRC_DIR)/complementFile \
58 $(SRC_DIR)/coverageFile \
59 $(SRC_DIR)/expand \
60 $(SRC_DIR)/fastaFromBed \
61 $(SRC_DIR)/flankBed \
62 $(SRC_DIR)/genomeCoverageBed \
63 $(SRC_DIR)/getOverlap \
64 $(SRC_DIR)/groupBy \
65 $(SRC_DIR)/intersectFile \
66 $(SRC_DIR)/fisher \
67 $(SRC_DIR)/jaccard \
68 $(SRC_DIR)/linksBed \
69 $(SRC_DIR)/maskFastaFromBed \
70 $(SRC_DIR)/mapFile \
71 $(SRC_DIR)/mergeFile \
72 $(SRC_DIR)/multiBamCov \
73 $(SRC_DIR)/multiIntersectBed \
74 $(SRC_DIR)/nucBed \
75 $(SRC_DIR)/pairToBed \
76 $(SRC_DIR)/pairToPair \
77 $(SRC_DIR)/randomBed \
78 $(SRC_DIR)/regressTest \
79 $(SRC_DIR)/reldist \
80 $(SRC_DIR)/sampleFile \
81 $(SRC_DIR)/shiftBed \
82 $(SRC_DIR)/shuffleBed \
83 $(SRC_DIR)/slopBed \
84 $(SRC_DIR)/sortBed \
85 $(SRC_DIR)/spacingFile \
86 $(SRC_DIR)/split \
87 $(SRC_DIR)/subtractFile \
88 $(SRC_DIR)/summaryFile \
89 $(SRC_DIR)/tagBam \
90 $(SRC_DIR)/unionBedGraphs \
91 $(SRC_DIR)/windowBed \
92 $(SRC_DIR)/windowMaker
93
94 UTIL_SUBDIRS = $(SRC_DIR)/utils/FileRecordTools \
95 $(SRC_DIR)/utils/FileRecordTools/FileReaders \
96 $(SRC_DIR)/utils/FileRecordTools/Records \
97 $(SRC_DIR)/utils/bedFile \
98 $(SRC_DIR)/utils/BinTree \
99 $(SRC_DIR)/utils/version \
100 $(SRC_DIR)/utils/bedGraphFile \
101 $(SRC_DIR)/utils/chromsweep \
102 $(SRC_DIR)/utils/Contexts \
103 $(SRC_DIR)/utils/general \
104 $(SRC_DIR)/utils/gzstream \
105 $(SRC_DIR)/utils/fileType \
106 $(SRC_DIR)/utils/bedFilePE \
107 $(SRC_DIR)/utils/KeyListOps \
108 $(SRC_DIR)/utils/NewChromsweep \
109 $(SRC_DIR)/utils/sequenceUtilities \
110 $(SRC_DIR)/utils/tabFile \
111 $(SRC_DIR)/utils/BamTools-Ancillary \
112 $(SRC_DIR)/utils/BlockedIntervals \
113 $(SRC_DIR)/utils/Fasta \
114 $(SRC_DIR)/utils/VectorOps \
115 $(SRC_DIR)/utils/GenomeFile \
116 $(SRC_DIR)/utils/RecordOutputMgr \
117 $(SRC_DIR)/utils/ToolBase \
118 $(SRC_DIR)/utils/driver \
119 $(SRC_DIR)/utils/BamTools
120
121 INCLUDES = $(addprefix -I,$(SUBDIRS) $(UTIL_SUBDIRS)) \
122 -I$(SRC_DIR)/utils/BamTools/include \
123 -I$(HTSDIR) \
124 -I$(SRC_DIR)/utils/lineFileUtilities \
125 -I$(SRC_DIR)/utils/Point \
126 -I$(SRC_DIR)/utils/stringUtilities
127
128
129 # Ensure that the user's $CXXFLAGS/etc are applied after bedtools's.
130 ALL_CXXFLAGS = $(BT_CXXFLAGS) $(CXXFLAGS)
131 ALL_CPPFLAGS = $(BT_CPPFLAGS) $(CPPFLAGS)
132 ALL_LDFLAGS = $(BT_LDFLAGS) $(LDFLAGS)
133 ALL_LIBS = $(BT_LIBS) $(LIBS)
134
135
•136 all: print_banner $(BIN_DIR)/bedtools $(BIN_DIR)/intersectBed
137
138 static: print_banner $(BIN_DIR)/bedtools.static
139
•140 BUILT_OBJECTS = $(OBJ_DIR)/bedtools.o $(OBJ_DIR)/htsutil.o
141 # Include all the Makefile fragments, which add to $(BUILT_OBJECTS)
142 include $(patsubst %,%/Makefile.frag,$(SUBDIRS) $(UTIL_SUBDIRS))
143
144 ## Automatically generate C++ dependencies.
145 ## $(DEPFLAGS) is a set of compiler flags that causes the compiler to generate
146 ## dependencies as a byproduct (which we write to a temporary file, only moving
147 ## it into place on successful compilations).
148 ## We then include the dependency files into this Makefile.
149 ## The subdirectories' Makefile fragments contain rules like the one for
150 ## $(OBJ_DIR)/bedtools.o below, with a dependency on obj/foo.d so that if
151 ## the dependency file is missing the target will be rebuilt.
152 ##
153 DEPFLAGS = -MT $@ -MMD -MP -MF $*.Td
154
155 define CXX_COMPILE
156 @echo " * compiling $<"
157 $(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_CXXFLAGS) $(ALL_CPPFLAGS) $(DEPFLAGS) -c -o $@ $<
158 @mv -f $*.Td $*.d
159 endef
160
161 $(OBJ_DIR)/%.d: ;
162 .PRECIOUS: $(OBJ_DIR)/%.d
163
164 -include $(patsubst %.o,%.d,$(BUILT_OBJECTS))
165
166 $(OBJ_DIR)/bedtools.o: $(SRC_DIR)/bedtools.cpp $(OBJ_DIR)/bedtools.d
167 $(CXX_COMPILE)
168
169 $(OBJ_DIR)/htsutil.o: $(SRC_DIR)/htsutil.cpp $(OBJ_DIR)/htsutil.d
170 $(CXX_COMPILE)
171
172 # HTSlib's htslib.mk provides rules to rebuild $(HTSDIR)/libhts.a.
173 HTSDIR = src/utils/htslib
174 include $(HTSDIR)/htslib.mk
175
176 # This order-only prerequisite ensures OBJ_DIR exists before building any .o file
177 # but ignores the directory's timestamp, which changes every time a .o file is written.
178 $(BUILT_OBJECTS): | $(OBJ_DIR)
179
•180 $(BUILT_OBJECTS): autoversion
181
182 $(BIN_DIR)/bedtools: autoversion $(BUILT_OBJECTS) $(HTSDIR)/libhts.a | $(BIN_DIR)
183 @echo "- Building main bedtools binary."
184 $(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS)
185 @echo "done."
186
187 $(BIN_DIR)/bedtools.static: autoversion $(BUILT_OBJECTS) $(HTSDIR)/libhts.a | $(BIN_DIR)
188 @echo "- Building main bedtools binary."
189 $(CCPREFIX) $(CC_WRAPPER) $(CXX) -static $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools.static $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS)
190 @echo "done."
191
192 test/htsutil: $(OBJ_DIR)/htsutil.o $(HTSDIR)/libhts.a
193 $(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_LDFLAGS) -o test/htsutil $(OBJ_DIR)/htsutil.o $(HTSDIR)/libhts.a $(ALL_LIBS)
194
195 $(BIN_DIR)/intersectBed: | $(BIN_DIR)
196 @echo "- Creating executables for old CLI."
197 @$(PYTHON) scripts/makeBashScripts.py
198 @chmod +x bin/*
199 @echo "done."
200
201
202 .PHONY: all
203
•204 install:
205 mkdir -p $(DESTDIR)$(prefix)/bin
206 for file in bin/* ; do \
207 cp -f $$file $(DESTDIR)$(prefix)/bin; \
208 done
209
210 print_banner:
211 @echo "Building BEDTools:"
212 @echo "========================================================="
213 @echo "CXXFLAGS is [$(ALL_CXXFLAGS)]"
214 .PHONY: print_banner
215
216 # make the "obj/" and "bin/" directories, if they don't exist
217 $(OBJ_DIR) $(BIN_DIR):
218 @mkdir -p $@
219
220
221 # Usually HTSlib's configure script has not been used (detected via config.mk
222 # not existing), so clean should also remove the generated config.h.
223 clean:
224 @echo " * Cleaning up."
225 @rm -f $(VERSION_FILE) $(OBJ_DIR)/* $(BIN_DIR)/* test/htsutil
226 @cd src/utils/htslib && make clean > /dev/null
227 @test -e src/utils/htslib/config.mk || rm -f src/utils/htslib/config.h
228 .PHONY: clean
229
•230 test:
231 @cd test; bash test.sh
232
233 .PHONY: test
234
235
236 ## For BEDTools developers (not users):
237 ## When you want to release (and tag) a new version, run:
238 ## $ make setversion VERSION=v2.17.2
239 ## This will:
240 ## 1. Update the "/src/utils/version/version_release.txt" file
241 ## 2. Commit the file
242 ## 3. Git-Tag the commit with the latest version
243 ##
244 .PHONY: setversion
245 setversion:
246 ifeq "$(VERSION)" ""
247 $(error please set VERSION variable to the new version (e.g "make setversion VERSION=v2.17.2"))
248 endif
249 @echo "# This file was auto-generated by running \"make setversion VERSION=$(VERSION)\"" > "$(RELEASED_VERSION_FILE)"
250 @echo "# on $$(date) ." >> "$(RELEASED_VERSION_FILE)"
251 @echo "# Please do not edit or commit this file manually." >> "$(RELEASED_VERSION_FILE)"
252 @echo "#" >> "$(RELEASED_VERSION_FILE)"
253 @echo "$(VERSION)" >> $(RELEASED_VERSION_FILE)
254 @git add $(RELEASED_VERSION_FILE)
255 @git commit -q -m "Setting Release-Version $(VERSION)"
256 @git tag "$(VERSION)"
257 @echo "Version updated to $(VERSION)."
258 @echo ""
259 @echo "Don't forget to push the commits AND the tags:"
260 @echo " git push --all --tags"
261 @echo ""
262
263
264 ## Automatic version detection
265 ##
266 ## What's going on here?
267 ## 1. If there's a ".git" repository - use the version from the repository.
268 ## ignore any released-version file. git repository is authorative.
269 ##
270 ## 2, If there's no ".git" repository,
271 ## get the "released" version number from the release-version file.
272 ##
273 ## 2.1. If the current directory looks like "arq5x-bedtools-XXXXXXX",
274 ## assume "-XXXXXX" is the last revision number (and the user
275 ## probably downloaded the ZIP from github).
276 ## Append the revision number to the released version string.
277 ##
278 ## 3. Compare the detected version (from steps 1,2) to the current string
279 ## in ./src/utils/version/version_git.h .
280 ## If they differ, update the header file - will cause a recompilation
281 ## of version.o .
282 ##
283 .PHONY: autoversion
284 autoversion:
285 @( \
286 if [ -d ".git" ] && which git > /dev/null ; then \
287 DETECTED_VERSION=$$(git describe --always --tags --dirty) ; \
288 else \
289 DETECTED_VERSION=$$(grep -v "^#" "$(RELEASED_VERSION_FILE)") ; \
290 if basename $$(pwd) | grep -q "^[[:alnum:]]*-bedtools-[[:alnum:]]*$$" ; then \
291 DETECTED_VERSION=$${DETECTED_VERSION}-zip-$$(basename "$$(pwd)" | sed 's/^[[:alnum:]]*-bedtools-//') ; \
292 fi ; \
293 fi ; \
294 \
295 CURRENT_VERSION="" ; \
296 [ -e "$(VERSION_FILE)" ] && CURRENT_VERSION=$$(grep "define VERSION_GIT " "$(VERSION_FILE)" | cut -f3 -d" " | sed 's/"//g') ; \
297 \
298 echo "DETECTED_VERSION = $$DETECTED_VERSION" ; \
299 echo "CURRENT_VERSION = $$CURRENT_VERSION" ; \
300 if [ "$${DETECTED_VERSION}" != "$${CURRENT_VERSION}" ] ; then \
301 echo "Updating version file." ; \
302 echo "#ifndef VERSION_GIT_H" > $(VERSION_FILE) ; \
303 echo "#define VERSION_GIT_H" >> $(VERSION_FILE) ; \
304 echo "#define VERSION_GIT \"$${DETECTED_VERSION}\"" >> $(VERSION_FILE) ; \
305 echo "#endif /* VERSION_GIT_H */" >> $(VERSION_FILE) ; \
306 fi )