-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
91 lines (75 loc) · 2.82 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
HTSLIB_PATH := ./htslib
ZSTD_PATH := ./zstd/lib
# C++ Compiler
CXX=g++
INCLUDE_DIRS=-I include -I $(HTSLIB_PATH)/htslib -I $(ZSTD_PATH)
#EXTRA_FLAGS=-fsanitize=address -fsanitize=undefined -fsanitize=pointer-subtract -fsanitize=pointer-compare -fno-omit-frame-pointer -fstack-protector-all -fcf-protection
ifeq ($(ADD_EXTRA),y)
EXTRA_FLAGS=-fsanitize=address -fsanitize=undefined -fsanitize=pointer-subtract -fsanitize=pointer-compare -fno-omit-frame-pointer -fstack-protector-all -fcf-protection
endif
ifeq ($(OLEVEL),)
OLEVEL=3
endif
CXXFLAGS=-O$(OLEVEL) -g -Wall -std=c++17 $(INCLUDE_DIRS) $(CXXEXTRAFLAGS) $(EXTRA_FLAGS)
# Linker
LD=g++
LIBS=-lpthread -lhts -lzstd
LDFLAGS=-O$(OLEVEL) $(EXTRA_FLAGS) -L $(HTSLIB_PATH) -L $(ZSTD_PATH)
# Project specific :
TARGET := xsqueezeit
SOURCE := xsqueezeit.cpp
OBJ := $(SOURCE:.cpp=.o)
CPP_SOURCES := $(wildcard *.cpp)
CPP_OBJS := $(CPP_SOURCES:.cpp=.o)
CPP_OBJS := $(CPP_OBJS:.c=.o)
OBJS := xcf.o bcf_traversal.o accessor.o c_api.o xsi_mixed_vcf.o $(OBJ)
DEPENDENCIES := $(CPP_SOURCES:.cpp=.d)
DEPENDENCIES := $(DEPENDENCIES:.c=.d)
NOT_IN_GIT_REPO := $(shell git rev-parse --short HEAD >/dev/null 2>/dev/null; echo $$?)
ifneq ($(NOT_IN_GIT_REPO),0)
GEN_GIT_REV := gen_git_rev
GIT_REVISION := 0
else
GIT_REVISION := $(shell git rev-parse --short HEAD)
REV_NOT_UP_TO_DATE := $(shell grep $(GIT_REVISION) include/git_rev.h >/dev/null 2>/dev/null; echo $$?)
ifneq ($(REV_NOT_UP_TO_DATE),0)
GEN_GIT_REV := gen_git_rev
endif
endif
# Rules
all : $(GEN_GIT_REV) $(DEPENDENCIES) $(TARGET)
datetime :
date | figlet 2> /dev/null
gen_git_rev :
echo "#define GIT_REVISION 0x$(GIT_REVISION)" > include/git_rev.h
# Link the target
$(TARGET) : $(OBJS)
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
xsqueezeit_standalone : $(OBJS) $(OBJ)
$(LD) $(LDFLAGS) $^ $(HTSLIB_PATH)/libhts.a $(ZSTD_PATH)/libzstd.a -pthread -static -static-libgcc -static-libstdc++ -o $@ -Wl,-Bstatic $(LIBS) -lz -lbz2 -llzma -lcurl -ldeflate
# Do not include the depency rules for "clean"
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDENCIES)
endif
# Compile
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
%.o : %.c
$(CXX) $(CXXFLAGS) -c $< -o $@
# Rule to generate the dependency files
%.d : %.cpp
$(CXX) $(INCLUDE_DIRS) -MG -MP -MM -MT '$(@:.d=.o)' $< -MF $@
%.d : %.c
$(CXX) $(INCLUDE_DIRS) -MG -MP -MM -MT '$(@:.d=.o)' $< -MF $@
EXPORT_DIR := xsqueezeit_export
package-sources : xcf.cpp bcf_traversal.cpp accessor.cpp c_api.cpp xsi_mixed_vcf.cpp
mkdir -p $(EXPORT_DIR)/include
cp $^ $(EXPORT_DIR)
for dep in $(^:.cpp=.d); do for file in $$(sed -n 's/\(^include.*\):/\1/p' $${dep}); do cp $${file} $(EXPORT_DIR)/include ; done ; done
cp Makefile_export $(EXPORT_DIR)/Makefile
# Remove artifacts
clean :
rm -f $(OBJS) $(TARGET) $(DEPENDENCIES)
rm -rf $(EXPORT_DIR)
# Rules that don't generate artifacts
.PHONY : all clean debug package-sources datetime