forked from osquery/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
307 lines (251 loc) · 8.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
PLATFORM := $(shell uname -s)
BASH_EXISTS := $(shell which bash)
CTAGS_EXISTS := $(shell which ctags)
CSCOPE_EXISTS := $(shell which cscope)
SHELL := $(shell which bash)
SOURCE_DIR := $(shell pwd)
ifneq ($(MAKECMDGOALS),deps)
GIT_EXISTS := $(shell which git)
endif
MAKE = make
ifeq ($(PLATFORM),FreeBSD)
MAKE = gmake
endif
DISTRO := $(shell . ./tools/lib.sh; _platform)
DISTRO_VERSION := $(shell . ./tools/lib.sh; _distro $(DISTRO))
DARWIN_BUILD := 10.12
ifeq ($(DISTRO),darwin)
BUILD_NAME = darwin$(DISTRO_VERSION)
else ifeq ($(DISTRO),freebsd)
BUILD_NAME = freebsd$(DISTRO_VERSION)
else
BUILD_NAME = $(DISTRO_VERSION)
endif
ifneq ($(OSQUERY_DEPS),)
DEPS_DIR = $(OSQUERY_DEPS)
else
DEPS_DIR = /usr/local/osquery
endif
# This is a hack to support Vagrant and VirtualBox shared folder.
# LLVM/LLD will use mmap with MAP_SHARED, which is not supported.
ifeq ($(PLATFORM),Linux)
FS_TYPE = $(shell stat --file-system --format=%T $(SOURCE_DIR) 2>&1)
else
FS_TYPE = unknown
endif
ifeq ($(FS_TYPE),nfs)
BUILD_NAME = shared
SHARED_DIR = $(shell stat -L build/shared 2>/dev/null >/dev/null || echo 0)
ifeq ($(SHARED_DIR),0)
DIR = $(shell ln -sf $(shell mktemp -d) build/shared)
endif
DEBUG_SHARED_DIR = $(shell stat -L build/debug_shared 2>/dev/null >/dev/null || echo 0)
ifeq ($(DEBUG_SHARED_DIR),0)
DEBUG_DIR = $(shell ln -sf $(shell mktemp -d) build/debug_shared)
endif
BUILD_DIR = $(shell readlink --canonicalize build/$(BUILD_NAME))$(DIR)
DEBUG_BUILD_DIR = $(shell readlink --canonicalize build/debug_$(BUILD_NAME))$(DEBUG_DIR)
ifneq (build/$(BUILD_NAME),$(BUILD_DIR))
LINK = " \-\> $(BUILD_DIR), $(DEBUG_BUILD_DIR)"
endif
else
BUILD_DIR := build/$(BUILD_NAME)
DEBUG_BUILD_DIR := build/debug_$(BUILD_NAME)
endif
ifneq ($(VERBOSE_TEST),)
VERBOSE_TEST = "-V"
endif
ifeq ($(PLATFORM),Linux)
LINK_FLAGS = -B$(DEPS_DIR)/legacy/lib -rtlib=compiler-rt -fuse-ld=lld
endif
PATH_SET := PATH="$(DEPS_DIR)/bin:/usr/local/bin:$(PATH)"
CMAKE := $(PATH_SET) LDFLAGS="-L$(DEPS_DIR)/legacy/lib -L$(DEPS_DIR)/lib $(LINK_FLAGS)" \
cmake $(CMAKE_EXTRA) $(SOURCE_DIR)/
CTEST := $(PATH_SET) ctest $(SOURCE_DIR)/
FORMAT_COMMAND := python tools/formatting/git-clang-format.py \
"--commit" "master" "-f" "--style=file"
ANALYSIS := ${SOURCE_DIR}/tools/analysis
DEFINES := CTEST_OUTPUT_ON_FAILURE=1 \
LSAN_OPTIONS="detect_container_overflow=0 \
suppressions=${ANALYSIS}/lsan.supp" \
ASAN_OPTIONS="suppressions=${ANALYSIS}/asan.supp" \
TSAN_OPTIONS="suppressions=${ANALYSIS}/tsan.supp,second_deadlock_stack=1" \
$(PATH_SET)
.setup:
ifneq ($(MAKECMDGOALS),deps)
ifeq ($(GIT_EXISTS),)
@echo "Problem: cannot find 'git'"
@false
endif
endif
ifeq ($(BASH_EXISTS),)
@echo "Problem: cannot find 'bash'"
@false
endif
ifeq ($(DISTRO),darwin)
ifneq ($(DISTRO_VERSION),$(DARWIN_BUILD))
@echo "-- Warning! The only Apple OS supported for building is $(DARWIN_BUILD)"
@echo "-- Note: Installing and running osquery is supported on versions 10.9+"
endif
endif
ifeq ($(FS_TYPE),nfs)
@echo "-- Requested build on shared (NFS) folder [Issue #3414]: using a temporary build directory"
@echo "-- Build directories: $(SOURCE_DIR)/build/{debug_}$(BUILD_NAME)$(LINK)"
else
@mkdir -p $(BUILD_DIR)
@mkdir -p $(DEBUG_BUILD_DIR)
endif
@mkdir -p build/docs
ifeq ($(PLATFORM),Linux)
@ln -snf $(BUILD_NAME) build/linux
@ln -snf debug_$(BUILD_NAME) build/debug_linux
endif
ifeq ($(PLATFORM),Darwin)
@ln -sfn $(BUILD_NAME) build/darwin
@ln -sfn debug_$(BUILD_NAME) build/debug_darwin
endif
@export PYTHONPATH="$DEPS_DIR/lib/python2.7/site-packages"
@ln -snf "$(SOURCE_DIR)/tools/tests" $(BUILD_DIR)/test_data
@ln -snf "$(SOURCE_DIR)/tools/tests" $(DEBUG_BUILD_DIR)/test_data
all: .setup
ifeq ($(wildcard $(DEPS_DIR)/.*),)
@echo "-- Warning! Cannot find dependencies install directory: $(DEPS_DIR)"
@echo "-- Have you run: make deps?"
@false
endif
@if [ ! -d $(BUILD_DIR) ]; then \
echo "The build directory cannot be used: $(BUILD_DIR)"; \
echo "Consider: make distclean; make"; \
false; \
fi
@cd $(BUILD_DIR) && $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
setup: .setup
docs: .setup
@mkdir -p docs
@cd build/docs && DOCS=True $(CMAKE) && \
$(DEFINES) $(MAKE) docs --no-print-directory $(MAKEFLAGS)
format_master:
@echo "[+] clang-format (`$(PATH_SET) which clang-format`) version: `$(PATH_SET) clang-format --version`"
@$(PATH_SET) $(FORMAT_COMMAND)
debug: .setup
@cd $(DEBUG_BUILD_DIR) && DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_debug: .setup
@cd $(DEBUG_BUILD_DIR) && DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
analyze: .setup
@cd $(BUILD_DIR) && ANALYZE=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
tidy: .setup
@cd $(BUILD_DIR) && TIDY=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
sanitize: .setup
@cd $(BUILD_DIR) && SANITIZE=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
fuzz: .setup
@echo "[+] zzuf (`$(PATH_SET) which zzuf`) version: `$(PATH_SET) zzuf -V | head -n 1`"
@$(PATH_SET) python tools/analysis/fuzz.py
sdk: .setup
@cd $(BUILD_DIR) && SDK=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_sdk: .setup
@cd $(BUILD_DIR) && SDK=True $(CMAKE) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
debug_sdk: .setup
@cd $(DEBUG_BUILD_DIR) && SDK=True DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_debug_sdk: .setup
@cd $(DEBUG_BUILD_DIR) && SDK=True DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
check:
@echo "[+] cppcheck (`$(PATH_SET) which cppcheck`) version: `$(PATH_SET) cppcheck --version`"
@$(PATH_SET) cppcheck --quiet --enable=all --error-exitcode=0 \
-I ./include ./osquery
@# We want check to produce an error if there are critical issues.
@echo ""
@$(PATH_SET) cppcheck --quiet --enable=warning --error-exitcode=1 \
-I ./include ./osquery
audit: .setup
@tools/audit.sh
debug_build:
cd $(DEBUG_BUILD_DIR) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_build:
cd $(BUILD_DIR) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
test_debug_build:
cd $(DEBUG_BUILD_DIR) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
deps: .setup
./tools/provision.sh build $(BUILD_NAME)
sysprep: .setup
@SKIP_DISTRO_MAIN=0 ./tools/provision.sh build $(BUILD_NAME)
build_deps: .setup
@OSQUERY_BUILD_DEPS=1 SKIP_DISTRO_MAIN=1 make deps
tags:
ifeq ($(CTAGS_EXISTS),)
@echo "problem: cannot find 'ctags'"
@false
endif
@ctags -R ./external ./include ./kernel ./osquery ./third-party
ctags: .setup tags
cscope.files:
@find \
-E \
./external ./include ./kernel ./osquery ./third-party \
-type f \
-iregex '.*\.(c|cc|h|hh|cpp|hpp)' > $@
cscope.out: cscope.files
ifeq ($(CSCOPE_EXISTS),)
@echo "problem: cannot find 'cscope'"
@false
endif
@cscope -b -i cscope.files > $@
cscope: .setup cscope.out
clean: .setup
@cd $(BUILD_DIR) && $(CMAKE) && \
$(DEFINES) $(MAKE) clean --no-print-directory $(MAKEFLAGS)
strip: .setup
cd $(BUILD_DIR) && find ./osquery -executable -type f | xargs strip
distclean:
rm -rf .sources $(BUILD_DIR) $(DEBUG_BUILD_DIR) build/docs build/wiki
rm -f tags cscope.files cscope.out
ifeq ($(PLATFORM),Linux)
rm -rf build/linux build/debug_linux
endif
ifeq ($(PLATFORM),Darwin)
rm -rf build/darwin build/debug_darwin
endif
ifeq ($(FS_TYPE),nfs)
rm -rf build/shared build/debug_shared
endif
depsclean:
./tools/provision.sh clean $(BUILD_NAME)
package: .setup
# Alias for packages (do not use CPack)
@cd $(BUILD_DIR) && PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages/fast --no-print-directory $(MAKEFLAGS)
debug_package: .setup
@cd $(DEBUG_BUILD_DIR) && DEBUG=True PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages --no-print-directory $(MAKEFLAGS)
packages: .setup
@cd $(BUILD_DIR) && PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages/fast --no-print-directory $(MAKEFLAGS)
debug_packages: .setup
@cd $(DEBUG_BUILD_DIR) && DEBUG=True PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages --no-print-directory $(MAKEFLAGS)
sync: .setup
@cd $(BUILD_DIR) && PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) sync --no-print-directory $(MAKEFLAGS)
test: .setup
@cd build/$(BUILD_NAME) && $(DEFINES) $(CTEST) $(VERBOSE_TEST)
.DEFAULT: .setup
@$(MAKE) --no-print-directory $(MAKEFLAGS) setup
@if [ ! -d $(BUILD_DIR) ]; then \
echo "The build directory cannot be used: $(BUILD_DIR)"; \
echo "Consider: make distclean; make"; \
false; \
fi
@cd $(BUILD_DIR) && $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS) $(MAKECMDGOALS)