forked from osquery/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
205 lines (168 loc) · 5.93 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
PLATFORM := $(shell uname -s)
BASH_EXISTS := $(shell which bash)
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_DIR = darwin$(DISTRO_VERSION)
else ifeq ($(DISTRO),freebsd)
BUILD_DIR = freebsd$(DISTRO_VERSION)
else
BUILD_DIR = $(DISTRO_VERSION)
endif
ifneq ($(OSQUERY_DEPS),)
DEPS_DIR = $(OSQUERY_DEPS)
else
DEPS_DIR = /usr/local/osquery
endif
PATH_SET := PATH="$(DEPS_DIR)/bin:/usr/local/bin:$(PATH)"
CMAKE := $(PATH_SET) CXXFLAGS="-L$(DEPS_DIR)/lib" cmake ../../
CTEST := $(PATH_SET) ctest ../../
DOCS_CMAKE := $(PATH_SET) CXXFLAGS="-L$(DEPS_DIR)/lib" cmake ../
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"
.PHONY: docs build
all: .setup
ifeq ($(wildcard $(DEPS_DIR)/.*),)
@echo "-- Warning! Cannot find dependencies install directory: $(DEPS_DIR)"
@echo "-- Have you run: make deps?"
@false
endif
@cd build/$(BUILD_DIR) && $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
docs: .setup
@cd build && DOCS=True $(DOCS_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 build/debug_$(BUILD_DIR) && DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_debug: .setup
@cd build/debug_$(BUILD_DIR) && DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
analyze: .setup
@cd build/$(BUILD_DIR) && ANALYZE=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
sanitize: .setup
@cd build/$(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/$(BUILD_DIR) && SDK=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_sdk: .setup
@cd build/$(BUILD_DIR) && SDK=True $(CMAKE) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
debug_sdk: .setup
@cd build/debug_$(BUILD_DIR) && SDK=True DEBUG=True $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_debug_sdk: .setup
@cd build/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
debug_build:
cd build/debug_$(BUILD_DIR) && \
$(DEFINES) $(MAKE) --no-print-directory $(MAKEFLAGS)
test_build:
cd build/$(BUILD_DIR) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
test_debug_build:
cd build/debug_$(BUILD_DIR) && \
$(DEFINES) $(MAKE) test --no-print-directory $(MAKEFLAGS)
deps: .setup
./tools/provision.sh build $(BUILD_DIR)
clean: .setup
@cd build/$(BUILD_DIR) && $(CMAKE) && \
$(DEFINES) $(MAKE) clean --no-print-directory $(MAKEFLAGS)
strip: .setup
cd build/$(BUILD_DIR) && find ./osquery -executable -type f | xargs strip
distclean:
rm -rf .sources build/$(BUILD_DIR) build/debug_$(BUILD_DIR) build/docs build/wiki
ifeq ($(PLATFORM),Linux)
rm -rf build/linux build/debug_linux
endif
ifeq ($(PLATFORM),Darwin)
rm -rf build/darwin build/debug_darwin
endif
depsclean:
./tools/provision.sh clean $(BUILD_DIR)
.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),unknown_version)
@echo Unknown, non-Redhat, non-Ubuntu based Linux distro
@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
@mkdir -p build/docs
@mkdir -p build/$(BUILD_DIR)
@mkdir -p build/debug_$(BUILD_DIR)
ifeq ($(PLATFORM),Linux)
@ln -snf $(BUILD_DIR) build/linux
@ln -snf debug_$(BUILD_DIR) build/debug_linux
endif
ifeq ($(PLATFORM),Darwin)
@ln -sfn $(BUILD_DIR) build/darwin
@ln -sfn debug_$(BUILD_DIR) build/debug_darwin
endif
@export PYTHONPATH="$DEPS_DIR/lib/python2.7/site-packages"
package: .setup
# Alias for packages (do not use CPack)
@cd build/$(BUILD_DIR) && PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages/fast --no-print-directory $(MAKEFLAGS)
debug_package: .setup
@cd build/debug_$(BUILD_DIR) && DEBUG=True PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages --no-print-directory $(MAKEFLAGS)
packages: .setup
@cd build/$(BUILD_DIR) && PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages/fast --no-print-directory $(MAKEFLAGS)
debug_packages: .setup
@cd build/debug_$(BUILD_DIR) && DEBUG=True PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) packages --no-print-directory $(MAKEFLAGS)
sync: .setup
@cd build/$(BUILD_DIR) && PACKAGE=True $(CMAKE) && \
$(DEFINES) $(MAKE) sync --no-print-directory $(MAKEFLAGS)
test:
@cd build/$(BUILD_DIR) && $(DEFINES) $(CTEST)
%::
@cd build/$(BUILD_DIR) && $(CMAKE) && \
$(DEFINES) $(MAKE) --no-print-directory $@