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 5 BASE_VER=0 6 include common.mk 7 8 LIBDIR ?= lib 9 PRELOADNAME = libminijailpreload.so 10 PRELOADPATH = \"/$(LIBDIR)/$(PRELOADNAME)\" 11 CPPFLAGS += -DPRELOADPATH="$(PRELOADPATH)" 12 13 ifneq ($(HAVE_SECUREBITS_H),no) 14 CPPFLAGS += -DHAVE_SECUREBITS_H 15 endif 16 17 ifeq ($(USE_seccomp),no) 18 CPPFLAGS += -DUSE_SECCOMP_SOFTFAIL 19 endif 20 21 CFLAGS += -Wextra -Wno-missing-field-initializers 22 CXXFLAGS += -Wextra -Wno-missing-field-initializers 23 24 USE_SYSTEM_GTEST ?= no 25 ifeq ($(USE_SYSTEM_GTEST),no) 26 GTEST_CXXFLAGS := -std=gnu++11 27 GTEST_MAIN := gtest_main.a 28 GTEST_LIBS := gtest.a 29 else 30 GTEST_CXXFLAGS := $(gtest-config --cxxflags) 31 GTEST_MAIN := -lgtest -lgtest_main 32 GTEST_LIBS := $(gtest-config --libs) 33 endif 34 35 CORE_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 39 all: CC_BINARY(minijail0) CC_LIBRARY(libminijail.so) \ 40 CC_LIBRARY(libminijailpreload.so) 41 42 parse_seccomp_policy: CXX_BINARY(parse_seccomp_policy) 43 44 tests: TEST(CXX_BINARY(libminijail_unittest)) \ 45 TEST(CXX_BINARY(syscall_filter_unittest)) 46 47 48 CC_BINARY(minijail0): LDLIBS += -lcap -ldl 49 CC_BINARY(minijail0): $(CORE_OBJECT_FILES) elfparse.o minijail0.o 50 clean: CLEAN(minijail0) 51 52 53 CC_LIBRARY(libminijail.so): LDLIBS += -lcap 54 CC_LIBRARY(libminijail.so): $(CORE_OBJECT_FILES) 55 clean: CLEAN(libminijail.so) 56 57 58 CXX_BINARY(libminijail_unittest): CXXFLAGS += -Wno-write-strings \ 59 $(GTEST_CXXFLAGS) 60 CXX_BINARY(libminijail_unittest): LDLIBS += -lcap $(GTEST_MAIN) 61 ifeq ($(USE_SYSTEM_GTEST),no) 62 CXX_BINARY(libminijail_unittest): $(GTEST_MAIN) 63 endif 64 CXX_BINARY(libminijail_unittest): libminijail_unittest.o $(CORE_OBJECT_FILES) 65 clean: CLEAN(libminijail_unittest) 66 67 68 CC_LIBRARY(libminijailpreload.so): LDLIBS += -lcap -ldl 69 CC_LIBRARY(libminijailpreload.so): libminijailpreload.o $(CORE_OBJECT_FILES) 70 clean: CLEAN(libminijailpreload.so) 71 72 73 CXX_BINARY(syscall_filter_unittest): CXXFLAGS += -Wno-write-strings \ 74 $(GTEST_CXXFLAGS) 75 CXX_BINARY(syscall_filter_unittest): LDLIBS += -lcap $(GTEST_MAIN) 76 ifeq ($(USE_SYSTEM_GTEST),no) 77 CXX_BINARY(syscall_filter_unittest): $(GTEST_MAIN) 78 endif 79 CXX_BINARY(syscall_filter_unittest): syscall_filter_unittest.o \ 80 syscall_filter.o bpf.o util.o libconstants.gen.o \ 81 libsyscalls.gen.o 82 clean: CLEAN(syscall_filter_unittest) 83 84 85 CXX_BINARY(parse_seccomp_policy): parse_seccomp_policy.o syscall_filter.o \ 86 bpf.o util.o libconstants.gen.o libsyscalls.gen.o 87 clean: CLEAN(parse_policy) 88 89 90 libsyscalls.gen.o: CPPFLAGS += -I$(SRC) 91 92 libsyscalls.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. 96 libsyscalls.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" 100 clean: CLEAN(libsyscalls.gen.c) 101 102 $(eval $(call add_object_rules,libsyscalls.gen.o,CC,c,CFLAGS)) 103 104 libconstants.gen.o: CPPFLAGS += -I$(SRC) 105 106 libconstants.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. 110 libconstants.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" 114 clean: CLEAN(libconstants.gen.c) 115 116 $(eval $(call add_object_rules,libconstants.gen.o,CC,c,CFLAGS)) 117 118 119 ################################################################################ 120 # Google Test 121 122 ifeq ($(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. 125 GTEST_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. 130 CPPFLAGS += -isystem $(GTEST_DIR)/include 131 132 # Flags passed to the C++ compiler. 133 GTEST_CXXFLAGS += -pthread 134 135 # All Google Test headers. Usually you shouldn't change this 136 # definition. 137 GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ 138 $(GTEST_DIR)/include/gtest/internal/*.h 139 140 # House-keeping build targets. 141 clean: clean_gtest 142 143 clean_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 _. 150 GTEST_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. 156 gtest-all.o : $(GTEST_SRCS_) 157 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) $(GTEST_CXXFLAGS) -c \ 158 $(GTEST_DIR)/src/gtest-all.cc -o $@ 159 160 gtest_main.o : $(GTEST_SRCS_) 161 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) $(GTEST_CXXFLAGS) -c \ 162 $(GTEST_DIR)/src/gtest_main.cc -o $@ 163 164 gtest.a : gtest-all.o 165 $(AR) $(ARFLAGS) $@ $^ 166 167 gtest_main.a : gtest-all.o gtest_main.o 168 $(AR) $(ARFLAGS) $@ $^ 169 170 endif 171 ################################################################################ 172