• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5BASE_VER=0
6include common.mk
7
8LIBDIR ?= lib
9PRELOADNAME = libminijailpreload.so
10PRELOADPATH = \"/$(LIBDIR)/$(PRELOADNAME)\"
11CPPFLAGS += -DPRELOADPATH="$(PRELOADPATH)"
12
13ifneq ($(HAVE_SECUREBITS_H),no)
14CPPFLAGS += -DHAVE_SECUREBITS_H
15endif
16
17ifeq ($(USE_seccomp),no)
18CPPFLAGS += -DUSE_SECCOMP_SOFTFAIL
19endif
20
21ifeq ($(USE_ASAN),yes)
22CPPFLAGS += -fsanitize=address
23LDFLAGS += -fsanitize=address
24USE_EXIT_ON_DIE = yes
25endif
26
27# Setting this flag can be useful for both AddressSanitizer builds and running
28# fuzzing tools, which do not expect crashes on gracefully-handled malformed
29# inputs.
30ifeq ($(USE_EXIT_ON_DIE),yes)
31CPPFLAGS += -DUSE_EXIT_ON_DIE
32endif
33
34MJ_COMMON_FLAGS = -Wunused-parameter -Wextra -Wno-missing-field-initializers
35CFLAGS += $(MJ_COMMON_FLAGS)
36CXXFLAGS += $(MJ_COMMON_FLAGS)
37
38USE_SYSTEM_GTEST ?= no
39ifeq ($(USE_SYSTEM_GTEST),no)
40GTEST_CXXFLAGS := -std=gnu++14
41GTEST_LIBS := gtest.a
42else
43GTEST_CXXFLAGS := $(shell gtest-config --cxxflags)
44GTEST_LIBS := $(shell gtest-config --libs)
45endif
46
47CORE_OBJECT_FILES := libminijail.o syscall_filter.o signal_handler.o \
48		bpf.o util.o system.o syscall_wrapper.o \
49		libconstants.gen.o libsyscalls.gen.o
50
51all: CC_BINARY(minijail0) CC_LIBRARY(libminijail.so) \
52	CC_LIBRARY(libminijailpreload.so)
53
54parse_seccomp_policy: CXX_BINARY(parse_seccomp_policy)
55
56tests: TEST(CXX_BINARY(libminijail_unittest)) \
57	TEST(CXX_BINARY(minijail0_cli_unittest)) \
58	TEST(CXX_BINARY(syscall_filter_unittest)) \
59	TEST(CXX_BINARY(system_unittest)) \
60	TEST(CXX_BINARY(util_unittest)) \
61
62
63CC_BINARY(minijail0): LDLIBS += -lcap -ldl
64CC_BINARY(minijail0): $(CORE_OBJECT_FILES) \
65	elfparse.o minijail0.o minijail0_cli.o
66clean: CLEAN(minijail0)
67
68
69CC_LIBRARY(libminijail.so): LDLIBS += -lcap
70CC_LIBRARY(libminijail.so): $(CORE_OBJECT_FILES)
71clean: CLEAN(libminijail.so)
72
73
74CXX_BINARY(libminijail_unittest): CXXFLAGS += -Wno-write-strings \
75						$(GTEST_CXXFLAGS)
76CXX_BINARY(libminijail_unittest): LDLIBS += -lcap $(GTEST_LIBS)
77ifeq ($(USE_SYSTEM_GTEST),no)
78CXX_BINARY(libminijail_unittest): $(GTEST_LIBS)
79endif
80CXX_BINARY(libminijail_unittest): libminijail_unittest.o $(CORE_OBJECT_FILES) \
81		testrunner.o
82clean: CLEAN(libminijail_unittest)
83
84
85CC_LIBRARY(libminijailpreload.so): LDLIBS += -lcap -ldl
86CC_LIBRARY(libminijailpreload.so): libminijailpreload.o $(CORE_OBJECT_FILES)
87clean: CLEAN(libminijailpreload.so)
88
89
90CXX_BINARY(minijail0_cli_unittest): CXXFLAGS += $(GTEST_CXXFLAGS)
91CXX_BINARY(minijail0_cli_unittest): LDLIBS += -lcap $(GTEST_LIBS)
92ifeq ($(USE_SYSTEM_GTEST),no)
93CXX_BINARY(minijail0_cli_unittest): $(GTEST_LIBS)
94endif
95CXX_BINARY(minijail0_cli_unittest): minijail0_cli_unittest.o \
96		$(CORE_OBJECT_FILES) minijail0_cli.o elfparse.o testrunner.o
97clean: CLEAN(minijail0_cli_unittest)
98
99
100CXX_BINARY(syscall_filter_unittest): CXXFLAGS += -Wno-write-strings \
101						$(GTEST_CXXFLAGS)
102CXX_BINARY(syscall_filter_unittest): LDLIBS += -lcap $(GTEST_LIBS)
103ifeq ($(USE_SYSTEM_GTEST),no)
104CXX_BINARY(syscall_filter_unittest): $(GTEST_LIBS)
105endif
106CXX_BINARY(syscall_filter_unittest): syscall_filter_unittest.o \
107		$(CORE_OBJECT_FILES) testrunner.o
108clean: CLEAN(syscall_filter_unittest)
109
110
111CXX_BINARY(system_unittest): CXXFLAGS += $(GTEST_CXXFLAGS)
112CXX_BINARY(system_unittest): LDLIBS += -lcap $(GTEST_LIBS)
113ifeq ($(USE_SYSTEM_GTEST),no)
114CXX_BINARY(system_unittest): $(GTEST_LIBS)
115endif
116CXX_BINARY(system_unittest): system_unittest.o \
117		$(CORE_OBJECT_FILES) testrunner.o
118clean: CLEAN(system_unittest)
119
120
121CXX_BINARY(util_unittest): CXXFLAGS += $(GTEST_CXXFLAGS)
122CXX_BINARY(util_unittest): LDLIBS += -lcap $(GTEST_LIBS)
123ifeq ($(USE_SYSTEM_GTEST),no)
124CXX_BINARY(util_unittest): $(GTEST_LIBS)
125endif
126CXX_BINARY(util_unittest): util_unittest.o \
127		$(CORE_OBJECT_FILES) testrunner.o
128clean: CLEAN(util_unittest)
129
130
131CXX_BINARY(parse_seccomp_policy): parse_seccomp_policy.o syscall_filter.o \
132		bpf.o util.o libconstants.gen.o libsyscalls.gen.o
133clean: CLEAN(parse_seccomp_policy)
134
135
136libsyscalls.gen.o: CPPFLAGS += -I$(SRC)
137
138libsyscalls.gen.o.depends: libsyscalls.gen.c
139
140# Only regenerate libsyscalls.gen.c if the Makefile or header changes.
141# NOTE! This will not detect if the file is not appropriate for the target.
142libsyscalls.gen.c: $(SRC)/Makefile $(SRC)/libsyscalls.h
143	@printf "Generating target-arch specific $@...\n"
144	$(QUIET)CC="$(CC)" $(SRC)/gen_syscalls.sh "$@"
145	@printf "$@ done.\n"
146clean: CLEAN(libsyscalls.gen.c)
147
148$(eval $(call add_object_rules,libsyscalls.gen.o,CC,c,CFLAGS))
149
150libconstants.gen.o: CPPFLAGS += -I$(SRC)
151
152libconstants.gen.o.depends: libconstants.gen.c
153
154# Only regenerate libconstants.gen.c if the Makefile or header changes.
155# NOTE! This will not detect if the file is not appropriate for the target.
156libconstants.gen.c: $(SRC)/Makefile $(SRC)/libconstants.h
157	@printf "Generating target-arch specific $@...\n"
158	$(QUIET)CC="$(CC)" $(SRC)/gen_constants.sh "$@"
159	@printf "$@ done.\n"
160clean: CLEAN(libconstants.gen.c)
161
162$(eval $(call add_object_rules,libconstants.gen.o,CC,c,CFLAGS))
163
164
165################################################################################
166# Google Test
167
168ifeq ($(USE_SYSTEM_GTEST),no)
169# Points to the root of Google Test, relative to where this file is.
170# Remember to tweak this if you move this file.
171GTEST_DIR = googletest-release-1.8.0/googletest
172
173# Flags passed to the preprocessor.
174# Set Google Test's header directory as a system directory, such that
175# the compiler doesn't generate warnings in Google Test headers.
176CPPFLAGS += -isystem $(GTEST_DIR)/include
177
178# Flags passed to the C++ compiler.
179GTEST_CXXFLAGS += -pthread
180
181# All Google Test headers.  Usually you shouldn't change this
182# definition.
183GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
184		$(GTEST_DIR)/include/gtest/internal/*.h
185
186# House-keeping build targets.
187clean: clean_gtest
188
189clean_gtest:
190	rm -f gtest.a gtest_main.a *.o
191
192# Builds gtest.a and gtest_main.a.
193
194# Usually you shouldn't tweak such internal variables, indicated by a
195# trailing _.
196GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
197
198# For simplicity and to avoid depending on Google Test's
199# implementation details, the dependencies specified below are
200# conservative and not optimized.  This is fine as Google Test
201# compiles fast and for ordinary users its source rarely changes.
202gtest-all.o : $(GTEST_SRCS_)
203	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) $(GTEST_CXXFLAGS) -c \
204		$(GTEST_DIR)/src/gtest-all.cc -o $@
205
206gtest_main.o : $(GTEST_SRCS_)
207	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) $(GTEST_CXXFLAGS) -c \
208		$(GTEST_DIR)/src/gtest_main.cc -o $@
209
210gtest.a : gtest-all.o
211	$(AR) $(ARFLAGS) $@ $^
212
213gtest_main.a : gtest-all.o gtest_main.o
214	$(AR) $(ARFLAGS) $@ $^
215
216endif
217################################################################################
218