1//
2// Copyright (C) 2017 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17cc_defaults {
18    name: "init_defaults",
19    cpp_std: "experimental",
20    sanitize: {
21        misc_undefined: ["signed-integer-overflow"],
22    },
23    cflags: [
24        "-DLOG_UEVENTS=0",
25        "-Wall",
26        "-Wextra",
27        "-Wno-unused-parameter",
28        "-Werror",
29        "-DALLOW_LOCAL_PROP_OVERRIDE=0",
30        "-DALLOW_PERMISSIVE_SELINUX=0",
31        "-DREBOOT_BOOTLOADER_ON_PANIC=0",
32        "-DWORLD_WRITABLE_KMSG=0",
33        "-DDUMP_ON_UMOUNT_FAILURE=0",
34        "-DSHUTDOWN_ZERO_TIMEOUT=0",
35    ],
36    product_variables: {
37        debuggable: {
38            cppflags: [
39                "-UALLOW_LOCAL_PROP_OVERRIDE",
40                "-DALLOW_LOCAL_PROP_OVERRIDE=1",
41                "-UALLOW_PERMISSIVE_SELINUX",
42                "-DALLOW_PERMISSIVE_SELINUX=1",
43                "-UREBOOT_BOOTLOADER_ON_PANIC",
44                "-DREBOOT_BOOTLOADER_ON_PANIC=1",
45                "-UWORLD_WRITABLE_KMSG",
46                "-DWORLD_WRITABLE_KMSG=1",
47                "-UDUMP_ON_UMOUNT_FAILURE",
48                "-DDUMP_ON_UMOUNT_FAILURE=1",
49            ],
50        },
51        eng: {
52            cppflags: [
53                "-USHUTDOWN_ZERO_TIMEOUT",
54                "-DSHUTDOWN_ZERO_TIMEOUT=1",
55            ],
56        },
57        uml: {
58            cppflags: ["-DUSER_MODE_LINUX"],
59        },
60    },
61    static_libs: [
62        "libbootloader_message",
63        "libfs_mgr",
64        "libfec",
65        "libfec_rs",
66        "libhidl-gen-utils",
67        "libsquashfs_utils",
68        "liblogwrap",
69        "libext4_utils",
70        "libcutils",
71        "libbase",
72        "libc",
73        "libseccomp_policy",
74        "libselinux",
75        "liblog",
76        "libcrypto_utils",
77        "libcrypto",
78        "libc++_static",
79        "libdl",
80        "libsparse",
81        "libz",
82        "libprocessgroup",
83        "libavb",
84        "libkeyutils",
85        "libprotobuf-cpp-lite",
86        "libpropertyinfoserializer",
87        "libpropertyinfoparser",
88    ],
89}
90
91cc_library_static {
92    name: "libinit",
93    defaults: ["init_defaults"],
94    srcs: [
95        "action.cpp",
96        "action_manager.cpp",
97        "action_parser.cpp",
98        "bootchart.cpp",
99        "builtins.cpp",
100        "capabilities.cpp",
101        "descriptors.cpp",
102        "devices.cpp",
103        "firmware_handler.cpp",
104        "import_parser.cpp",
105        "init.cpp",
106        "init_first_stage.cpp",
107        "keychords.cpp",
108        "log.cpp",
109        "parser.cpp",
110        "persistent_properties.cpp",
111        "persistent_properties.proto",
112        "property_service.cpp",
113        "property_type.cpp",
114        "reboot.cpp",
115        "security.cpp",
116        "selinux.cpp",
117        "service.cpp",
118        "sigchld_handler.cpp",
119        "subcontext.cpp",
120        "subcontext.proto",
121        "rlimit_parser.cpp",
122        "tokenizer.cpp",
123        "uevent_listener.cpp",
124        "ueventd.cpp",
125        "ueventd_parser.cpp",
126        "util.cpp",
127        "watchdogd.cpp",
128    ],
129    whole_static_libs: ["libcap"],
130    header_libs: ["bootimg_headers"],
131    proto: {
132        type: "lite",
133        export_proto_headers: true,
134    },
135}
136
137/*
138This is not yet ready, see the below TODOs for what is missing
139
140cc_binary {
141    // TODO: Missing,
142    //LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
143    //LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
144
145    name: "init",
146    defaults: ["init_defaults"],
147    required: [
148        "e2fsdroid",
149        "mke2fs",
150        "sload_f2fs",
151        "make_f2fs",
152    ],
153    static_executable: true,
154    srcs: ["main.cpp"],
155    symlinks: [
156        "sbin/ueventd",
157        "sbin/watchdogd",
158    ],
159}
160*/
161
162// Tests
163// ------------------------------------------------------------------------------
164
165cc_test {
166    name: "init_tests",
167    defaults: ["init_defaults"],
168    static_executable: true,
169    srcs: [
170        "devices_test.cpp",
171        "init_test.cpp",
172        "persistent_properties_test.cpp",
173        "property_service_test.cpp",
174        "property_type_test.cpp",
175        "result_test.cpp",
176        "rlimit_parser_test.cpp",
177        "service_test.cpp",
178        "subcontext_test.cpp",
179        "ueventd_test.cpp",
180        "util_test.cpp",
181    ],
182    static_libs: ["libinit"],
183}
184
185cc_benchmark {
186    name: "init_benchmarks",
187    static_executable: true,
188    defaults: ["init_defaults"],
189    srcs: [
190        "subcontext_benchmark.cpp",
191    ],
192    static_libs: ["libinit"],
193}
194
195// Host Verifier
196// ------------------------------------------------------------------------------
197
198genrule {
199    name: "generated_stub_builtin_function_map",
200    out: ["generated_stub_builtin_function_map.h"],
201    srcs: ["builtins.cpp"],
202    cmd: "sed -n '/Builtin-function-map start/{:a;n;/Builtin-function-map end/q;p;ba}' $(in) | sed -e 's/do_[^}]*/do_stub/g' > $(out)",
203}
204
205cc_binary {
206    name: "host_init_verifier",
207    host_supported: true,
208    cpp_std: "experimental",
209    cflags: [
210        "-Wall",
211        "-Wextra",
212        "-Wno-unused-parameter",
213        "-Werror",
214    ],
215    static_libs: [
216        "libbase",
217        "libselinux",
218    ],
219    whole_static_libs: ["libcap"],
220    shared_libs: [
221        "libprotobuf-cpp-lite",
222        "libhidl-gen-utils",
223        "libprocessgroup",
224        "liblog",
225        "libcutils",
226    ],
227    srcs: [
228        "action.cpp",
229        "action_manager.cpp",
230        "action_parser.cpp",
231        "capabilities.cpp",
232        "descriptors.cpp",
233        "import_parser.cpp",
234        "host_init_parser.cpp",
235        "host_init_stubs.cpp",
236        "parser.cpp",
237        "rlimit_parser.cpp",
238        "tokenizer.cpp",
239        "service.cpp",
240        "subcontext.cpp",
241        "subcontext.proto",
242        "util.cpp",
243    ],
244    proto: {
245        type: "lite",
246    },
247    generated_headers: ["generated_stub_builtin_function_map"],
248    target: {
249        android: {
250            enabled: false,
251        },
252        darwin: {
253            enabled: false,
254        },
255    },
256}
257
258subdirs = ["*"]
259