| 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 test/htsutil |
| 137 |
|
| 138 |
static: print_banner $(BIN_DIR)/bedtools.static |
| 139 |
|
| 140 |
BUILT_OBJECTS = $(OBJ_DIR)/bedtools.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 |
$(BIN_DIR)/bedtools: autoversion $(BUILT_OBJECTS) $(HTSDIR)/libhts.a | $(BIN_DIR) |
| 181 |
@echo "- Building main bedtools binary." |
| 182 |
$(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS) |
| 183 |
@echo "done." |
| 184 |
|
| 185 |
$(BIN_DIR)/bedtools.static: autoversion $(BUILT_OBJECTS) $(HTSDIR)/libhts.a | $(BIN_DIR) |
| 186 |
@echo "- Building main bedtools binary." |
| 187 |
$(CCPREFIX) $(CC_WRAPPER) $(CXX) -static $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools.static $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS) |
| 188 |
@echo "done." |
| 189 |
|
| 190 |
test/htsutil: $(OBJ_DIR)/htsutil.o $(HTSDIR)/libhts.a |
| 191 |
$(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_LDFLAGS) -o test/htsutil $(OBJ_DIR)/htsutil.o $(HTSDIR)/libhts.a $(ALL_LIBS) |
| 192 |
|
| 193 |
$(BIN_DIR)/intersectBed: | $(BIN_DIR) |
| 194 |
@echo "- Creating executables for old CLI." |
| 195 |
@$(PYTHON) scripts/makeBashScripts.py |
| 196 |
@chmod +x bin/* |
| 197 |
@echo "done." |
| 198 |
|
| 199 |
|
| 200 |
.PHONY: all |
| 201 |
|
| 202 |
install: |
| 203 |
mkdir -p $(DESTDIR)$(prefix)/bin |
| 204 |
for file in bin/* ; do \ |
| 205 |
cp -f $$file $(DESTDIR)$(prefix)/bin; \ |
| 206 |
done |
| 207 |
|
| 208 |
print_banner: |
| 209 |
@echo "Building BEDTools:" |
| 210 |
@echo "=========================================================" |
| 211 |
@echo "CXXFLAGS is [$(ALL_CXXFLAGS)]" |
| 212 |
.PHONY: print_banner |
| 213 |
|
| 214 |
# make the "obj/" and "bin/" directories, if they don't exist |
| 215 |
$(OBJ_DIR) $(BIN_DIR): |
| 216 |
@mkdir -p $@ |
| 217 |
|
| 218 |
|
| 219 |
# Usually HTSlib's configure script has not been used (detected via config.mk |
| 220 |
# not existing), so clean should also remove the generated config.h. |
| 221 |
clean: |
| 222 |
@echo " * Cleaning up." |
| 223 |
@rm -f $(VERSION_FILE) $(OBJ_DIR)/* $(BIN_DIR)/* test/htsutil |
| 224 |
@cd src/utils/htslib && make clean > /dev/null |
| 225 |
@test -e src/utils/htslib/config.mk || rm -f src/utils/htslib/config.h |
| 226 |
.PHONY: clean |
| 227 |
|
| 228 |
test: |
| 229 |
@cd test; bash test.sh |
| 230 |
|
| 231 |
.PHONY: test |
| 232 |
|
| 233 |
|
| 234 |
## For BEDTools developers (not users): |
| 235 |
## When you want to release (and tag) a new version, run: |
| 236 |
## $ make setversion VERSION=v2.17.2 |
| 237 |
## This will: |
| 238 |
## 1. Update the "/src/utils/version/version_release.txt" file |
| 239 |
## 2. Commit the file |
| 240 |
## 3. Git-Tag the commit with the latest version |
| 241 |
## |
| 242 |
.PHONY: setversion |
| 243 |
setversion: |
| 244 |
ifeq "$(VERSION)" "" |
| 245 |
$(error please set VERSION variable to the new version (e.g "make setversion VERSION=v2.17.2")) |
| 246 |
endif |
| 247 |
@echo "# This file was auto-generated by running \"make setversion VERSION=$(VERSION)\"" > "$(RELEASED_VERSION_FILE)" |
| 248 |
@echo "# on $$(date) ." >> "$(RELEASED_VERSION_FILE)" |
| 249 |
@echo "# Please do not edit or commit this file manually." >> "$(RELEASED_VERSION_FILE)" |
| 250 |
@echo "#" >> "$(RELEASED_VERSION_FILE)" |
| 251 |
@echo "$(VERSION)" >> $(RELEASED_VERSION_FILE) |
| 252 |
@git add $(RELEASED_VERSION_FILE) |
| 253 |
@git commit -q -m "Setting Release-Version $(VERSION)" |
| 254 |
@git tag "$(VERSION)" |
| 255 |
@echo "Version updated to $(VERSION)." |
| 256 |
@echo "" |
| 257 |
@echo "Don't forget to push the commits AND the tags:" |
| 258 |
@echo " git push --all --tags" |
| 259 |
@echo "" |
| 260 |
|
| 261 |
|
| 262 |
## Automatic version detection |
| 263 |
## |
| 264 |
## What's going on here? |
| 265 |
## 1. If there's a ".git" repository - use the version from the repository. |
| 266 |
## ignore any released-version file. git repository is authorative. |
| 267 |
## |
| 268 |
## 2, If there's no ".git" repository, |
| 269 |
## get the "released" version number from the release-version file. |
| 270 |
## |
| 271 |
## 2.1. If the current directory looks like "arq5x-bedtools-XXXXXXX", |
| 272 |
## assume "-XXXXXX" is the last revision number (and the user |
| 273 |
## probably downloaded the ZIP from github). |
| 274 |
## Append the revision number to the released version string. |
| 275 |
## |
| 276 |
## 3. Compare the detected version (from steps 1,2) to the current string |
| 277 |
## in ./src/utils/version/version_git.h . |
| 278 |
## If they differ, update the header file - will cause a recompilation |
| 279 |
## of version.o . |
| 280 |
## |
| 281 |
.PHONY: autoversion |
| 282 |
autoversion: |
| 283 |
@( \ |
| 284 |
if [ -d ".git" ] && which git > /dev/null ; then \ |
| 285 |
DETECTED_VERSION=$$(git describe --always --tags --dirty) ; \ |
| 286 |
else \ |
| 287 |
DETECTED_VERSION=$$(grep -v "^#" "$(RELEASED_VERSION_FILE)") ; \ |
| 288 |
if basename $$(pwd) | grep -q "^[[:alnum:]]*-bedtools-[[:alnum:]]*$$" ; then \ |
| 289 |
DETECTED_VERSION=$${DETECTED_VERSION}-zip-$$(basename "$$(pwd)" | sed 's/^[[:alnum:]]*-bedtools-//') ; \ |
| 290 |
fi ; \ |
| 291 |
fi ; \ |
| 292 |
\ |
| 293 |
CURRENT_VERSION="" ; \ |
| 294 |
[ -e "$(VERSION_FILE)" ] && CURRENT_VERSION=$$(grep "define VERSION_GIT " "$(VERSION_FILE)" | cut -f3 -d" " | sed 's/"//g') ; \ |
| 295 |
\ |
| 296 |
echo "DETECTED_VERSION = $$DETECTED_VERSION" ; \ |
| 297 |
echo "CURRENT_VERSION = $$CURRENT_VERSION" ; \ |
| 298 |
if [ "$${DETECTED_VERSION}" != "$${CURRENT_VERSION}" ] ; then \ |
| 299 |
echo "Updating version file." ; \ |
| 300 |
echo "#ifndef VERSION_GIT_H" > $(VERSION_FILE) ; \ |
| 301 |
echo "#define VERSION_GIT_H" >> $(VERSION_FILE) ; \ |
| 302 |
echo "#define VERSION_GIT \"$${DETECTED_VERSION}\"" >> $(VERSION_FILE) ; \ |
| 303 |
echo "#endif /* VERSION_GIT_H */" >> $(VERSION_FILE) ; \ |
| 304 |
fi ) |