-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
executable file
·100 lines (79 loc) · 2.06 KB
/
Makefile
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
# Compiler options
CC = gcc
CXX = g++
OPTCXXFLAGS += -O2
CXXFLAGS += -Wall -std=c++11 $(OPTCXXFLAGS)
CFLAGS += -Wall -Wno-maybe-uninitialized
LDFLAGS += -pthread -lstdc++ -lz -L$(INCLUDE)/bwa -lbwa
# Directory organization
BASEDIR = .
BIN = $(BASEDIR)/bin
BUILD = $(BASEDIR)/build
INCLUDE = $(BASEDIR)/include
SRC = $(BASEDIR)/src
CPPFILES = $(wildcard $(SRC)/*.cpp)
# Get number of parallel jobs
MAKE_PID := $(shell echo $$PPID)
JOBS := $(shell ps T | sed -n 's/.*$(MAKE_PID).*$(MAKE).* \(-j\|--jobs\) *\([0-9][0-9]*\).*/\2/p')
ifeq ($(JOBS),)
JOBS := 1
endif
# Object files inferred from cpp files
OBJS = $(addprefix $(BUILD)/, $(notdir $(CPPFILES:.cpp=.o)))
# Target
TARGETS = $(BIN)/radsex
# Declare phony targets (i.e. targets which are not files)
.PHONY: all clean clean-bwa clean-kfun clean-all rebuild rebuild-all docs
# Main rule
all: $(BUILD) $(BIN) $(TARGETS)
# Build directory
$(BUILD):
if [ ! -e $@ ]; then \
mkdir $@; \
fi;
# Bin directory
$(BIN):
if [ ! -e $@ ]; then \
mkdir $@; \
fi;
# Build BWA
$(INCLUDE)/bwa/libbwa.a:
(cd $(INCLUDE)/bwa && $(MAKE) CC=$(CC) -j $(JOBS))
# Clean BWA
clean-bwa:
(cd $(INCLUDE)/bwa && $(MAKE) clean)
# Build kfun
$(INCLUDE)/kfun/kfun.o: $(INCLUDE)/kfun/kfun.cpp
$(CC) $(CFLAGS) -I $(INCLUDE) -c -o $@ $^
# Clean BWA
clean-kfun: $(INCLUDE)/kfun/kfun.o
if [ -e $^ ]; then \
rm -f $^; \
fi;
# Clean radsex files
clean:
rm -rf $(BUILD)/*.o
rm -rf $(BIN)/*
# Clean all files
clean-all: clean clean-bwa clean-kfun
# Rebuild radsex only
rebuild:
$(MAKE) clean
$(MAKE) -j $(JOBS)
# Rebuild radsex and dependencies
rebuild-all:
$(MAKE) clean-all
$(MAKE) -j $(JOBS)
# Linking
$(BIN)/radsex: $(OBJS) $(INCLUDE)/kfun/kfun.o
$(CXX) $(CXXFLAGS) -I $(INCLUDE) -o $(BIN)/radsex $^ $(LDFLAGS)
# Build a single object file. Added libs as dependency so they are built before object files
$(BUILD)/%.o: $(SRC)/%.cpp $(INCLUDE)/bwa/libbwa.a
$(CXX) $(CXXFLAGS) -I $(INCLUDE) -c -o $@ $<
# Build doc with doxygen
docs:
(cd docs && make)
clean-docs:
(cd docs && make clean)
rebuild-docs:
(cd docs && make rebuild)