Makefile 6.82 KB
Newer Older
Aaron's avatar
Aaron committed
1

2
3
4
5
# ==========================
# BEDTools Makefile
# (c) 2009 Aaron Quinlan
# ==========================
Aaron's avatar
Aaron committed
6

Aaron's avatar
Aaron committed
7
8
SHELL := /bin/bash -e

Assaf Gordon's avatar
Assaf Gordon committed
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
Aaron's avatar
Aaron committed
14
15
16
export OBJ_DIR	= obj
export BIN_DIR	= bin
export SRC_DIR	= src
Aaron's avatar
Aaron committed
17
export UTIL_DIR	= src/utils
Aaron's avatar
Aaron committed
18
export CXX		= g++
19
20
21
#ifeq ($(DEBUG),1)
#export CXXFLAGS = -Wall -O0 -g -fno-inline -fkeep-inline-functions -D_FILE_OFFSET_BITS=64 -fPIC -DDEBUG -D_DEBUG
#else
Aaron's avatar
Aaron committed
22
export CXXFLAGS = -Wall -O2 -D_FILE_OFFSET_BITS=64 -fPIC
23
#endif
Aaron's avatar
Aaron committed
24
export LIBS		= -lz
25
export BT_ROOT  = src/utils/BamTools/
26
27


Aaron's avatar
Aaron committed
28
SUBDIRS = $(SRC_DIR)/annotateBed \
Aaron's avatar
Aaron committed
29
		  $(SRC_DIR)/bamToBed \
Aaron's avatar
Aaron committed
30
		  $(SRC_DIR)/bamToFastq \
Aaron's avatar
Aaron committed
31
		  $(SRC_DIR)/bedToBam \
Aaron's avatar
Aaron committed
32
		  $(SRC_DIR)/bedpeToBam \
Aaron's avatar
Aaron committed
33
34
35
		  $(SRC_DIR)/bedToIgv \
		  $(SRC_DIR)/bed12ToBed6 \
		  $(SRC_DIR)/closestBed \
36
		  $(SRC_DIR)/clusterBed \
Aaron's avatar
Aaron committed
37
38
		  $(SRC_DIR)/complementBed \
		  $(SRC_DIR)/coverageBed \
Aaron's avatar
Aaron committed
39
		  $(SRC_DIR)/expand \
Aaron's avatar
Aaron committed
40
		  $(SRC_DIR)/fastaFromBed \
Aaron's avatar
Aaron committed
41
		  $(SRC_DIR)/flankBed \
Aaron's avatar
Aaron committed
42
		  $(SRC_DIR)/genomeCoverageBed \
43
44
		  $(SRC_DIR)/getOverlap \
		  $(SRC_DIR)/groupBy \
45
		  $(SRC_DIR)/intersectFile \
46
		  $(SRC_DIR)/jaccard \
Aaron's avatar
Aaron committed
47
48
		  $(SRC_DIR)/linksBed \
		  $(SRC_DIR)/maskFastaFromBed \
49
		  $(SRC_DIR)/mapBed \
50
		  $(SRC_DIR)/mergeBed \
51
		  $(SRC_DIR)/multiBamCov \
52
		  $(SRC_DIR)/multiIntersectBed \
53
		   $(SRC_DIR)/nekSandbox1 \
54
		  $(SRC_DIR)/nucBed \
Aaron's avatar
Aaron committed
55
56
		  $(SRC_DIR)/pairToBed \
		  $(SRC_DIR)/pairToPair \
Aaron's avatar
Aaron committed
57
		  $(SRC_DIR)/randomBed \
58
		  $(SRC_DIR)/regressTest \
59
		  $(SRC_DIR)/reldist \
60
		  $(SRC_DIR)/sampleFile \
Aaron's avatar
Aaron committed
61
62
63
64
		  $(SRC_DIR)/shuffleBed \
		  $(SRC_DIR)/slopBed \
		  $(SRC_DIR)/sortBed \
		  $(SRC_DIR)/subtractBed \
Aaron's avatar
Aaron committed
65
		  $(SRC_DIR)/tagBam \
Aaron's avatar
Aaron committed
66
		  $(SRC_DIR)/unionBedGraphs \
Aaron's avatar
Aaron committed
67
68
		  $(SRC_DIR)/windowBed \
		  $(SRC_DIR)/windowMaker
69

70
UTIL_SUBDIRS =	$(SRC_DIR)/utils/bedFile \
71
				$(SRC_DIR)/utils/BinTree \
Assaf Gordon's avatar
Assaf Gordon committed
72
				$(SRC_DIR)/utils/version \
Aaron's avatar
Aaron committed
73
				$(SRC_DIR)/utils/bedGraphFile \
74
				$(SRC_DIR)/utils/chromsweep \
75
76
77
				$(SRC_DIR)/utils/Contexts \
				$(SRC_DIR)/utils/FileRecordTools \
				$(SRC_DIR)/utils/general \
Aaron's avatar
Aaron committed
78
79
80
				$(SRC_DIR)/utils/gzstream \
				$(SRC_DIR)/utils/fileType \
				$(SRC_DIR)/utils/bedFilePE \
81
				$(SRC_DIR)/utils/NewChromsweep \
Aaron's avatar
Aaron committed
82
				$(SRC_DIR)/utils/sequenceUtilities \
83
				$(SRC_DIR)/utils/tabFile \
84
				$(SRC_DIR)/utils/BamTools \
85
				$(SRC_DIR)/utils/BamTools-Ancillary \
86
				$(SRC_DIR)/utils/BlockedIntervals \
87
				$(SRC_DIR)/utils/Fasta \
Aaron's avatar
Aaron committed
88
				$(SRC_DIR)/utils/VectorOps \
89
				$(SRC_DIR)/utils/GenomeFile
90

Aaron's avatar
Aaron committed
91
BUILT_OBJECTS = $(OBJ_DIR)/*.o
Aaron's avatar
Aaron committed
92

Aaron's avatar
Aaron committed
93

94
all: print_banner $(OBJ_DIR) $(BIN_DIR) autoversion $(UTIL_SUBDIRS) $(SUBDIRS)
Aaron's avatar
Aaron committed
95
	@echo "- Building main bedtools binary."
96
	@$(CXX) $(CXXFLAGS) -c src/bedtools.cpp -o obj/bedtools.o -I$(UTIL_DIR)/version/
97
	@$(CXX) $(CXXFLAGS) -o $(BIN_DIR)/bedtools $(BUILT_OBJECTS) -L$(UTIL_DIR)/BamTools/lib/ -lbamtools $(LIBS) $(LDFLAGS)
98
99
100
101
102
103
	@echo "done."
	
	@echo "- Creating executables for old CLI."
	@python scripts/makeBashScripts.py
	@chmod +x bin/*
	@echo "done."
Aaron's avatar
Aaron committed
104
	
105

106
107
.PHONY: all

108
109
110
111
112
113
114
115
116
print_banner:
	@echo "Building BEDTools:"
	@echo "========================================================="
.PHONY: print_banner

# make the "obj/" and "bin/" directories, if they don't exist
$(OBJ_DIR) $(BIN_DIR):
	@mkdir -p $@

117
118
119
120
121
122
123
124

# One special case: All (or almost all) programs requires the BamTools API files to be created first.
.PHONY: bamtools_api
bamtools_api:
	@$(MAKE) --no-print-directory --directory=$(BT_ROOT) api
$(UTIL_SUBDIRS) $(SUBDIRS): bamtools_api


125
126
127
128
129
130
131
# even though these are real directories, treat them as phony targets, forcing to always go in them are re-make.
# a future improvement would be the check for the compiled object, and rebuild only if the source code is newer.
.PHONY: $(UTIL_SUBDIRS) $(SUBDIRS)
$(UTIL_SUBDIRS) $(SUBDIRS): $(OBJ_DIR) $(BIN_DIR)
	@echo "- Building in $@"
	@$(MAKE) --no-print-directory --directory=$@

132
clean:
133
134
	@$(MAKE) --no-print-directory --directory=$(BT_ROOT) clean_api
	@echo " * Cleaning up."
Aaron's avatar
Aaron committed
135
	@rm -f $(OBJ_DIR)/* $(BIN_DIR)/*
136
.PHONY: clean
137

Aaron's avatar
Aaron committed
138
test: all
139
140
	@cd test; sh test.sh

Aaron's avatar
Aaron committed
141
.PHONY: test
142

143
144
145
146
147
148
149
150
151
152
153
154

## For BEDTools developers (not users):
## When you want to release (and tag) a new version, run:
##   $ make setversion VERSION=v2.17.2
## This will:
##   1. Update the "/src/utils/version/version_release.txt" file
##   2. Commit the file
##   3. Git-Tag the commit with the latest version
##
.PHONY: setversion
setversion:
    ifeq "$(VERSION)" ""
Aaron's avatar
Aaron committed
155
		$(error please set VERSION variable to the new version (e.g "make setversion VERSION=v2.17.2"))
156
    endif
Aaron's avatar
Aaron committed
157
158
159
160
161
162
163
164
165
166
167
168
169
		@echo "# This file was auto-generated by running \"make setversion VERSION=$(VERSION)\"" > "$(RELEASED_VERSION_FILE)"
		@echo "# on $$(date) ." >> "$(RELEASED_VERSION_FILE)"
		@echo "# Please do not edit or commit this file manually." >> "$(RELEASED_VERSION_FILE)"
		@echo "#" >> "$(RELEASED_VERSION_FILE)"
		@echo "$(VERSION)" >> $(RELEASED_VERSION_FILE)
		@git add $(RELEASED_VERSION_FILE)
		@git commit -q -m "Setting Release-Version $(VERSION)"
		@git tag "$(VERSION)"
		@echo "Version updated to $(VERSION)."
		@echo ""
		@echo "Don't forget to push the commits AND the tags:"
		@echo "  git push --all --tags"
		@echo ""
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


## Automatic version detection
##
## What's going on here?
## 1. If there's a ".git" repository - use the version from the repository.
##    ignore any released-version file. git repository is authorative.
##
## 2, If there's no ".git" repository,
##    get the "released" version number from the release-version file.
##
##    2.1. If the current directory looks like "arq5x-bedtools-XXXXXXX",
##         assume "-XXXXXX" is the last revision number (and the user
##         probably downloaded the ZIP from github).
##         Append the revision number to the released version string.
##
## 3. Compare the detected version (from steps 1,2) to the current string
##    in ./src/utils/version/version_git.h .
##    If they differ, update the header file - will cause a recompilation
##    of version.o .
##
.PHONY: autoversion
autoversion:
	@( \
194
	if [ -d ".git" ] && which git > /dev/null ; then \
195
196
197
198
199
200
201
202
203
204
205
206
207
208
		DETECTED_VERSION=$$(git describe --always --tags --dirty) ; \
	else \
		DETECTED_VERSION=$$(grep -v "^#" "$(RELEASED_VERSION_FILE)") ; \
		if basename $$(pwd) | grep -q "^[[:alnum:]]*-bedtools-[[:alnum:]]*$$" ; then \
			DETECTED_VERSION=$${DETECTED_VERSION}-zip-$$(basename "$$(pwd)" | sed 's/^[[:alnum:]]*-bedtools-//') ; \
		fi ; \
	fi ; \
	\
	CURRENT_VERSION="" ; \
	[ -e "$(VERSION_FILE)" ] && CURRENT_VERSION=$$(grep "define VERSION_GIT " "$(VERSION_FILE)" | cut -f3 -d" " | sed 's/"//g') ; \
	\
	echo "DETECTED_VERSION = $$DETECTED_VERSION" ; \
	echo "CURRENT_VERSION  = $$CURRENT_VERSION" ; \
	if [ "$${DETECTED_VERSION}" != "$${CURRENT_VERSION}" ] ; then \
209
		echo "Updating version file." ; \
210
211
212
213
		echo "#ifndef VERSION_GIT_H" > $(VERSION_FILE) ; \
		echo "#define VERSION_GIT_H" >> $(VERSION_FILE) ; \
		echo "#define VERSION_GIT \"$${DETECTED_VERSION}\"" >> $(VERSION_FILE) ; \
		echo "#endif /* VERSION_GIT_H */" >> $(VERSION_FILE) ; \
Aaron's avatar
Aaron committed
214
	fi )