1 # Copyright (C) 2015 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 LOCAL_PATH := $(call my-dir) 16 17 18 # Common variables. 19 # ========================================================= 20 libminijailSrcFiles := \ 21 bpf.c \ 22 libminijail.c \ 23 signal_handler.c \ 24 syscall_filter.c \ 25 util.c 26 27 minijailCommonCFlags := -DHAVE_SECUREBITS_H -Wall -Werror 28 minijailCommonLibraries := libcap 29 30 # Android devices running kernel version < 3.8 are not required to 31 # support seccomp. Brillo devices must support seccomp regardless of 32 # kernel version. 33 # TODO: remove when no longer supporting kernel versions < 3.8. 34 ifndef BRILLO 35 minijailCommonCFlags += -DUSE_SECCOMP_SOFTFAIL 36 endif 37 38 39 # Static library for generated code. 40 # ========================================================= 41 include $(CLEAR_VARS) 42 LOCAL_MODULE := libminijail_generated 43 44 LOCAL_MODULE_CLASS := STATIC_LIBRARIES 45 generated_sources_dir := $(local-generated-sources-dir) 46 47 my_gen := $(generated_sources_dir)/$(TARGET_ARCH)/libsyscalls.c 48 # We need the quotes so the shell script treats the following as one argument. 49 my_cc := "$(lastword $(CLANG)) \ 50 $(addprefix -isystem ,$(TARGET_C_INCLUDES)) \ 51 $(CLANG_TARGET_GLOBAL_CFLAGS)" 52 $(my_gen): PRIVATE_CC := $(my_cc) 53 $(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@ 54 $(my_gen): $(LOCAL_PATH)/gen_syscalls.sh 55 $(transform-generated-source) 56 LOCAL_GENERATED_SOURCES_$(TARGET_ARCH) += $(my_gen) 57 58 my_gen := $(generated_sources_dir)/$(TARGET_ARCH)/libconstants.c 59 $(my_gen): PRIVATE_CC := $(my_cc) 60 $(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@ 61 $(my_gen): $(LOCAL_PATH)/gen_constants.sh 62 $(transform-generated-source) 63 LOCAL_GENERATED_SOURCES_$(TARGET_ARCH) += $(my_gen) 64 65 # For processes running in 32-bit compat mode on 64-bit processors. 66 ifdef TARGET_2ND_ARCH 67 my_gen := $(generated_sources_dir)/$(TARGET_2ND_ARCH)/libsyscalls.c 68 my_cc := "$(lastword $(CLANG)) \ 69 $(addprefix -isystem ,$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES)) \ 70 $($(TARGET_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CFLAGS)" 71 $(my_gen): PRIVATE_CC := $(my_cc) 72 $(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@ 73 $(my_gen): $(LOCAL_PATH)/gen_syscalls.sh 74 $(transform-generated-source) 75 LOCAL_GENERATED_SOURCES_$(TARGET_2ND_ARCH) += $(my_gen) 76 77 my_gen := $(generated_sources_dir)/$(TARGET_2ND_ARCH)/libconstants.c 78 $(my_gen): PRIVATE_CC := $(my_cc) 79 $(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@ 80 $(my_gen): $(LOCAL_PATH)/gen_constants.sh 81 $(transform-generated-source) 82 LOCAL_GENERATED_SOURCES_$(TARGET_2ND_ARCH) += $(my_gen) 83 endif 84 85 LOCAL_CFLAGS := $(minijailCommonCFlags) 86 LOCAL_CLANG := true 87 include $(BUILD_STATIC_LIBRARY) 88 89 90 # libminijail shared library for target. 91 # ========================================================= 92 include $(CLEAR_VARS) 93 LOCAL_MODULE := libminijail 94 95 LOCAL_CFLAGS := $(minijailCommonCFlags) 96 LOCAL_CLANG := true 97 LOCAL_SRC_FILES := $(libminijailSrcFiles) 98 99 LOCAL_STATIC_LIBRARIES := libminijail_generated 100 LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries) 101 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) 102 include $(BUILD_SHARED_LIBRARY) 103 104 105 # Example ASan-ified libminijail shared library for target. 106 # Commented out since it's only needed for local debugging. 107 # ========================================================= 108 # include $(CLEAR_VARS) 109 # LOCAL_MODULE := libminijail_asan 110 # LOCAL_MODULE_TAGS := optional 111 # 112 # LOCAL_CFLAGS := $(minijailCommonCFlags) 113 # LOCAL_CLANG := true 114 # LOCAL_SANITIZE := address 115 # LOCAL_MODULE_RELATIVE_PATH := asan 116 # LOCAL_SRC_FILES := $(libminijailSrcFiles) 117 # 118 # LOCAL_STATIC_LIBRARIES := libminijail_generated 119 # LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries) 120 # LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) 121 # include $(BUILD_SHARED_LIBRARY) 122 123 124 # libminijail static library for target. 125 # ========================================================= 126 include $(CLEAR_VARS) 127 LOCAL_MODULE := libminijail 128 129 LOCAL_CFLAGS := $(minijailCommonCFlags) 130 LOCAL_CLANG := true 131 LOCAL_SRC_FILES := $(libminijailSrcFiles) 132 133 LOCAL_WHOLE_STATIC_LIBRARIES := libminijail_generated $(minijailCommonLibraries) 134 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) 135 include $(BUILD_STATIC_LIBRARY) 136 137 138 # libminijail native unit tests. Run with: 139 # adb shell /data/nativetest/libminijail_unittest/libminijail_unittest 140 # ========================================================= 141 include $(CLEAR_VARS) 142 LOCAL_MODULE := libminijail_unittest 143 ifdef BRILLO 144 LOCAL_MODULE_TAGS := eng 145 endif 146 147 LOCAL_CFLAGS := $(minijailCommonCFlags) 148 LOCAL_CLANG := true 149 LOCAL_SRC_FILES := \ 150 bpf.c \ 151 libminijail.c \ 152 libminijail_unittest.c \ 153 signal_handler.c \ 154 syscall_filter.c \ 155 util.c \ 156 157 LOCAL_STATIC_LIBRARIES := libminijail_generated 158 LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries) 159 include $(BUILD_NATIVE_TEST) 160 161 162 # Syscall filtering native unit tests. Run with: 163 # adb shell /data/nativetest/syscall_filter_unittest/syscall_filter_unittest 164 # ========================================================= 165 include $(CLEAR_VARS) 166 LOCAL_MODULE := syscall_filter_unittest 167 ifdef BRILLO 168 LOCAL_MODULE_TAGS := eng 169 endif 170 171 LOCAL_CFLAGS := $(minijailCommonCFlags) 172 LOCAL_CLANG := true 173 LOCAL_SRC_FILES := \ 174 bpf.c \ 175 syscall_filter.c \ 176 syscall_filter_unittest.c \ 177 util.c \ 178 179 LOCAL_STATIC_LIBRARIES := libminijail_generated 180 LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries) 181 include $(BUILD_NATIVE_TEST) 182 183 184 # test_minijail executable for brillo_Minijail test. 185 # ========================================================= 186 include $(CLEAR_VARS) 187 LOCAL_MODULE := libminijail_test 188 ifdef BRILLO 189 LOCAL_MODULE_TAGS := eng 190 endif 191 192 LOCAL_CFLAGS := $(minijailCommonCFlags) 193 LOCAL_CLANG := true 194 LOCAL_SRC_FILES := \ 195 test/libminijail_test.cpp 196 197 LOCAL_SHARED_LIBRARIES := libbase libminijail 198 include $(BUILD_EXECUTABLE) 199 200 201 # libminijail usage example. 202 # ========================================================= 203 include $(CLEAR_VARS) 204 LOCAL_MODULE := drop_privs 205 LOCAL_MODULE_TAGS := optional 206 LOCAL_CFLAGS := $(minijailCommonCFlags) 207 LOCAL_CLANG := true 208 # Don't build with ASan, but leave commented out for easy local debugging. 209 # LOCAL_SANITIZE := address 210 LOCAL_SRC_FILES := \ 211 examples/drop_privs.cpp 212 213 LOCAL_SHARED_LIBRARIES := libbase libminijail 214 include $(BUILD_EXECUTABLE) 215 216 217 # minijail0 executable. 218 # This is not currently used on Brillo/Android, 219 # but it's convenient to be able to build it. 220 # ========================================================= 221 include $(CLEAR_VARS) 222 LOCAL_MODULE := minijail0 223 LOCAL_MODULE_TAGS := optional 224 LOCAL_CFLAGS := \ 225 $(minijailCommonCFlags) -Wno-missing-field-initializers \ 226 -DPRELOADPATH=\"/invalidminijailpreload.so\" 227 LOCAL_CLANG := true 228 LOCAL_SRC_FILES := \ 229 elfparse.c \ 230 minijail0.c \ 231 232 LOCAL_STATIC_LIBRARIES := libminijail_generated 233 LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries) libminijail 234 include $(BUILD_EXECUTABLE) 235