• Home
  • 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
21CFLAGS += -Wextra -Wno-missing-field-initializers
22CXXFLAGS += -Wextra -Wno-missing-field-initializers
23
24USE_SYSTEM_GTEST ?= no
25ifeq ($(USE_SYSTEM_GTEST),no)
26GTEST_CXXFLAGS := -std=gnu++11
27GTEST_MAIN := gtest_main.a
28GTEST_LIBS := gtest.a
29else
30GTEST_CXXFLAGS := $(gtest-config --cxxflags)
31GTEST_MAIN := -lgtest -lgtest_main
32GTEST_LIBS := $(gtest-config --libs)
33endif
34
35CORE_OBJECT_FILES := libminijail.o syscall_filter.o signal_handler.o \
36		bpf.o util.o system.o syscall_wrapper.o \
37		libconstants.gen.o libsyscalls.gen.o
38
39all: CC_BINARY(minijail0) CC_LIBRARY(libminijail.so) \
40	CC_LIBRARY(libminijailpreload.so)
41
42parse_seccomp_policy: CXX_BINARY(parse_seccomp_policy)
43
44tests: TEST(CXX_BINARY(libminijail_unittest)) \
45	TEST(CXX_BINARY(syscall_filter_unittest))
46
47
48CC_BINARY(minijail0): LDLIBS += -lcap -ldl
49CC_BINARY(minijail0): $(CORE_OBJECT_FILES) elfparse.o minijail0.o
50clean: CLEAN(minijail0)
51
52
53CC_LIBRARY(libminijail.so): LDLIBS += -lcap
54CC_LIBRARY(libminijail.so): $(CORE_OBJECT_FILES)
55clean: CLEAN(libminijail.so)
56
57
58CXX_BINARY(libminijail_unittest): CXXFLAGS += -Wno-write-strings \
59						$(GTEST_CXXFLAGS)
60CXX_BINARY(libminijail_unittest): LDLIBS += -lcap $(GTEST_MAIN)
61ifeq ($(USE_SYSTEM_GTEST),no)
62CXX_BINARY(libminijail_unittest): $(GTEST_MAIN)
63endif
64CXX_BINARY(libminijail_unittest): libminijail_unittest.o $(CORE_OBJECT_FILES)
65clean: CLEAN(libminijail_unittest)
66
67
68CC_LIBRARY(libminijailpreload.so): LDLIBS += -lcap -ldl
69CC_LIBRARY(libminijailpreload.so): libminijailpreload.o $(CORE_OBJECT_FILES)
70clean: CLEAN(libminijailpreload.so)
71
72
73CXX_BINARY(syscall_filter_unittest): CXXFLAGS += -Wno-write-strings \
74						$(GTEST_CXXFLAGS)
75CXX_BINARY(syscall_filter_unittest): LDLIBS += -lcap $(GTEST_MAIN)
76ifeq ($(USE_SYSTEM_GTEST),no)
77CXX_BINARY(syscall_filter_unittest): $(GTEST_MAIN)
78endif
79CXX_BINARY(syscall_filter_unittest): syscall_filter_unittest.o \
80		syscall_filter.o bpf.o util.o libconstants.gen.o \
81		libsyscalls.gen.o
82clean: CLEAN(syscall_filter_unittest)
83
84
85CXX_BINARY(parse_seccomp_policy): parse_seccomp_policy.o syscall_filter.o \
86		bpf.o util.o libconstants.gen.o libsyscalls.gen.o
87clean: CLEAN(parse_policy)
88
89
90libsyscalls.gen.o: CPPFLAGS += -I$(SRC)
91
92libsyscalls.gen.o.depends: libsyscalls.gen.c
93
94# Only regenerate libsyscalls.gen.c if the Makefile or header changes.
95# NOTE! This will not detect if the file is not appropriate for the target.
96libsyscalls.gen.c: $(SRC)/Makefile $(SRC)/libsyscalls.h
97	@printf "Generating target-arch specific $@...\n"
98	$(QUIET)$(SRC)/gen_syscalls.sh "$(CC)" "$@"
99	@printf "$@ done.\n"
100clean: CLEAN(libsyscalls.gen.c)
101
102$(eval $(call add_object_rules,libsyscalls.gen.o,CC,c,CFLAGS))
103
104libconstants.gen.o: CPPFLAGS += -I$(SRC)
105
106libconstants.gen.o.depends: libconstants.gen.c
107
108# Only regenerate libconstants.gen.c if the Makefile or header changes.
109# NOTE! This will not detect if the file is not appropriate for the target.
110libconstants.gen.c: $(SRC)/Makefile $(SRC)/libconstants.h
111	@printf "Generating target-arch specific $@...\n"
112	$(QUIET)$(SRC)/gen_constants.sh "$(CC)" "$@"
113	@printf "$@ done.\n"
114clean: CLEAN(libconstants.gen.c)
115
116$(eval $(call add_object_rules,libconstants.gen.o,CC,c,CFLAGS))
117
118
119################################################################################
120# Google Test
121
122ifeq ($(USE_SYSTEM_GTEST),no)
123# Points to the root of Google Test, relative to where this file is.
124# Remember to tweak this if you move this file.
125GTEST_DIR = googletest-release-1.8.0/googletest
126
127# Flags passed to the preprocessor.
128# Set Google Test's header directory as a system directory, such that
129# the compiler doesn't generate warnings in Google Test headers.
130CPPFLAGS += -isystem $(GTEST_DIR)/include
131
132# Flags passed to the C++ compiler.
133GTEST_CXXFLAGS += -pthread
134
135# All Google Test headers.  Usually you shouldn't change this
136# definition.
137GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
138		$(GTEST_DIR)/include/gtest/internal/*.h
139
140# House-keeping build targets.
141clean: clean_gtest
142
143clean_gtest:
144	rm -f gtest.a gtest_main.a *.o
145
146# Builds gtest.a and gtest_main.a.
147
148# Usually you shouldn't tweak such internal variables, indicated by a
149# trailing _.
150GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
151
152# For simplicity and to avoid depending on Google Test's
153# implementation details, the dependencies specified below are
154# conservative and not optimized.  This is fine as Google Test
155# compiles fast and for ordinary users its source rarely changes.
156gtest-all.o : $(GTEST_SRCS_)
157	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) $(GTEST_CXXFLAGS) -c \
158		$(GTEST_DIR)/src/gtest-all.cc -o $@
159
160gtest_main.o : $(GTEST_SRCS_)
161	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) $(GTEST_CXXFLAGS) -c \
162		$(GTEST_DIR)/src/gtest_main.cc -o $@
163
164gtest.a : gtest-all.o
165	$(AR) $(ARFLAGS) $@ $^
166
167gtest_main.a : gtest-all.o gtest_main.o
168	$(AR) $(ARFLAGS) $@ $^
169
170endif
171################################################################################
172