aboutsummaryrefslogtreecommitdiff
path: root/Android.mk
blob: 82f4c29d74da86114bc2e9bcdb2bf06f10204dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

LOCAL_PATH := $(call my-dir)


# Common variables.
# =========================================================
libminijailSrcFiles := \
	bpf.c \
	libminijail.c \
	signal_handler.c \
	syscall_filter.c \
	util.c

# TODO(b/27632733): Re-enable including the system's <linux/securebits.h>.
#minijailCommonCFlags := -DHAVE_SECUREBITS_H -Wall -Werror
minijailCommonCFlags := -Wall -Werror
minijailCommonLibraries := libcap

# Android devices running kernel version < 3.8 are not required to
# support seccomp. Brillo devices must support seccomp regardless of
# kernel version.
# TODO: remove when no longer supporting kernel versions < 3.8.
ifndef BRILLO
minijailCommonCFlags += -DUSE_SECCOMP_SOFTFAIL
endif


# Static library for generated code.
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libminijail_generated

LOCAL_MODULE_CLASS := STATIC_LIBRARIES
generated_sources_dir := $(local-generated-sources-dir)

my_gen := $(generated_sources_dir)/$(TARGET_ARCH)/libsyscalls.c
# We need the quotes so the shell script treats the following as one argument.
my_cc := "$(lastword $(CLANG)) \
    $(addprefix -isystem ,$(TARGET_C_INCLUDES)) \
    $(CLANG_TARGET_GLOBAL_CFLAGS)"
$(my_gen): PRIVATE_CC := $(my_cc)
$(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@
$(my_gen): $(LOCAL_PATH)/gen_syscalls.sh
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES_$(TARGET_ARCH) += $(my_gen)

my_gen := $(generated_sources_dir)/$(TARGET_ARCH)/libconstants.c
$(my_gen): PRIVATE_CC := $(my_cc)
$(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@
$(my_gen): $(LOCAL_PATH)/gen_constants.sh
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES_$(TARGET_ARCH) += $(my_gen)

# For processes running in 32-bit compat mode on 64-bit processors.
ifdef TARGET_2ND_ARCH
my_gen := $(generated_sources_dir)/$(TARGET_2ND_ARCH)/libsyscalls.c
my_cc := "$(lastword $(CLANG)) \
    $(addprefix -isystem ,$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_C_INCLUDES)) \
    $($(TARGET_2ND_ARCH_VAR_PREFIX)CLANG_TARGET_GLOBAL_CFLAGS)"
$(my_gen): PRIVATE_CC := $(my_cc)
$(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@
$(my_gen): $(LOCAL_PATH)/gen_syscalls.sh
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES_$(TARGET_2ND_ARCH) += $(my_gen)

my_gen := $(generated_sources_dir)/$(TARGET_2ND_ARCH)/libconstants.c
$(my_gen): PRIVATE_CC := $(my_cc)
$(my_gen): PRIVATE_CUSTOM_TOOL = $< $(PRIVATE_CC) $@
$(my_gen): $(LOCAL_PATH)/gen_constants.sh
	$(transform-generated-source)
LOCAL_GENERATED_SOURCES_$(TARGET_2ND_ARCH) += $(my_gen)
endif

LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
include $(BUILD_STATIC_LIBRARY)


# libminijail shared library for target.
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libminijail

LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
LOCAL_SRC_FILES := $(libminijailSrcFiles)

LOCAL_STATIC_LIBRARIES := libminijail_generated
LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
include $(BUILD_SHARED_LIBRARY)


# libminijail static library for target.
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libminijail

LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
LOCAL_SRC_FILES := $(libminijailSrcFiles)

LOCAL_WHOLE_STATIC_LIBRARIES := libminijail_generated $(minijailCommonLibraries)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
include $(BUILD_STATIC_LIBRARY)


# libminijail native unit tests. Run with:
# adb shell /data/nativetest/libminijail_unittest/libminijail_unittest
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libminijail_unittest
ifdef BRILLO
  LOCAL_MODULE_TAGS := eng
endif

LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
LOCAL_SRC_FILES := \
	bpf.c \
	libminijail.c \
	libminijail_unittest.c \
	signal_handler.c \
	syscall_filter.c \
	util.c \

LOCAL_STATIC_LIBRARIES := libminijail_generated
LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries)
include $(BUILD_NATIVE_TEST)


# Syscall filtering native unit tests. Run with:
# adb shell /data/nativetest/syscall_filter_unittest/syscall_filter_unittest
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := syscall_filter_unittest
ifdef BRILLO
  LOCAL_MODULE_TAGS := eng
endif

LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
LOCAL_SRC_FILES := \
	bpf.c \
	syscall_filter.c \
	syscall_filter_unittest.c \
	util.c \

LOCAL_STATIC_LIBRARIES := libminijail_generated
LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries)
include $(BUILD_NATIVE_TEST)


# libminijail_test executable for brillo_Minijail test.
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libminijail_test
ifdef BRILLO
  LOCAL_MODULE_TAGS := eng
endif

LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
LOCAL_SRC_FILES := \
	test/libminijail_test.cpp

LOCAL_SHARED_LIBRARIES := libbase libminijail
include $(BUILD_EXECUTABLE)


# libminijail usage example.
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := drop_privs
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := $(minijailCommonCFlags)
LOCAL_CLANG := true
LOCAL_SRC_FILES := \
	examples/drop_privs.cpp

LOCAL_SHARED_LIBRARIES := libbase libminijail
include $(BUILD_EXECUTABLE)


# minijail0 executable.
# This is not currently used on Brillo/Android,
# but it's convenient to be able to build it.
# =========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := minijail0
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := \
	$(minijailCommonCFlags) -Wno-missing-field-initializers \
	-DPRELOADPATH=\"/invalidminijailpreload.so\"
LOCAL_CLANG := true
LOCAL_SRC_FILES := \
	elfparse.c \
	minijail0.c \

LOCAL_STATIC_LIBRARIES := libminijail_generated
LOCAL_SHARED_LIBRARIES := $(minijailCommonLibraries) libminijail
include $(BUILD_EXECUTABLE)