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