-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
113 lines (86 loc) · 2.57 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
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# File Integrity Tracker (fit)
#
# Copyright (c) 2023, Stone Steps Inc.
#
SHELL := /bin/bash
# remove all standard suffix rules
.SUFFIXES:
.PHONY: all clean
SRCDIR := src
# build all output in ./build, unless asked otherwise
ifeq ($(strip $(BLDDIR)),)
BLDDIR := build
endif
SRCS := fit.cpp file_tree_walker.cpp file_tracker.cpp exif_reader.cpp \
print_stream.cpp sqlite.cpp unicode.cpp
LIBS := sqlite3 pthread stdc++fs exiv2 expat z fmt
ifdef NO_SSE_AVX
SRCS += sha256/sha256.c
else
INCDIRS += /usr/include/isa-l_crypto
LIBS += :libisal_crypto.a
endif
OBJS := $(patsubst %.c,%.o,$(filter %.c,$(SRCS))) \
$(patsubst %.cpp,%.o,$(filter %.cpp,$(SRCS)))
DEPS := $(OBJS:.o=.d)
# compiler options shared between C and C++ source
CCFLAGS_COMMON := -Werror -pedantic
ifdef DEBUG
CCFLAGS_COMMON += -g
endif
ifdef NO_SSE_AVX
CCFLAGS_COMMON += -DNO_SSE_AVX
endif
CFLAGS := -std=gnu99 \
$(CCFLAGS_COMMON)
CXXFLAGS := -std=c++20 \
$(CCFLAGS_COMMON) \
-fexceptions \
-DRAPIDJSON_HAS_STDSTRING \
-DRAPIDJSON_HAS_CXX11_RVALUE_REFS \
-DRAPIDJSON_HAS_CXX11_NOEXCEPT \
-DRAPIDJSON_HAS_CXX11_RANGE_FOR
ifeq ($(findstring -g,$(CXXFLAGS)),)
CXXFLAGS += -O3
endif
ifeq ($(findstring -g,$(CFLAGS)),)
CFLAGS += -O3
endif
# if CI pipeline build number is provided, add it to the build
ifdef GH_BUILD_NUMBER
CXXFLAGS += -DBUILD_NUMBER=$(GH_BUILD_NUMBER)
endif
$(BLDDIR)/fit: $(addprefix $(BLDDIR)/,$(OBJS)) | $(BLDDIR)
$(CXX) -o $@ $(addprefix -L,$(LIBDIRS)) \
$(addprefix $(BLDDIR)/,$(OBJS)) \
$(addprefix -l,$(LIBS))
$(BLDDIR):
@mkdir $(BLDDIR)
clean:
@echo 'Removing object files...'
@rm -f $(addprefix $(BLDDIR)/, $(OBJS))
@echo 'Removing dependency files...'
@rm -f $(addprefix $(BLDDIR)/, $(DEPS))
@echo 'Removing binaries...'
@rm -f $(BLDDIR)/fit
@echo 'Done'
# C/C++ compile rules
$(BLDDIR)/%.o : $(SRCDIR)/%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(addprefix -I,$(INCDIRS)) $< -o $@
$(BLDDIR)/%.o : $(SRCDIR)/%.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(addprefix -I,$(INCDIRS)) $< -o $@
# dependencies
$(BLDDIR)/%.d : $(SRCDIR)/%.c
@if [ ! -e $(@D) ]; then mkdir -p $(@D); fi
set -e; $(CC) -MM $(CPPFLAGS) $(CFLAGS) $(addprefix -I,$(INCDIRS)) $< | \
sed 's|^[ \t]*$(*F)\.o|$(BLDDIR)/$*.o $(BLDDIR)/$*.d|g' > $@
$(BLDDIR)/%.d : $(SRCDIR)/%.cpp
@if [ ! -e $(@D) ]; then mkdir -p $(@D); fi
set -e; $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $(addprefix -I,$(INCDIRS)) $< | \
sed 's|^[ \t]*$(*F)\.o|$(BLDDIR)/$*.o $(BLDDIR)/$*.d|g' > $@
ifeq ($(MAKECMDGOALS),)
include $(addprefix $(BLDDIR)/, $(DEPS))
else ifneq ($(filter $(BLDDIR)/fit,$(MAKECMDGOALS)),)
include $(addprefix $(BLDDIR)/, $(DEPS))
endif