1// Copyright (C) 2017 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// This is what we want to do:
16//  event_logtags = $(shell
17//    sed -n
18//        "s/^\([0-9]*\)[ \t]*$1[ \t].*/-D`echo $1 | tr a-z A-Z`_LOG_TAG=\1/p"
19//        $(LOCAL_PATH)/$2/event.logtags)
20//  event_flag := $(call event_logtags,auditd)
21//  event_flag += $(call event_logtags,logd)
22//  event_flag += $(call event_logtags,tag_def)
23// so make sure we do not regret hard-coding it as follows:
24package {
25    default_applicable_licenses: ["Android-Apache-2.0"],
26}
27
28event_flag = [
29    "-DAUDITD_LOG_TAG=1003",
30    "-DCHATTY_LOG_TAG=1004",
31    "-DTAG_DEF_LOG_TAG=1005",
32    "-DLIBLOG_LOG_TAG=1006",
33]
34
35cc_defaults {
36    name: "logd_defaults",
37
38    shared_libs: [
39        "libbase",
40        "libz",
41    ],
42    static_libs: ["libzstd"],
43    header_libs: ["libcutils_headers"],
44    cflags: [
45        "-Wextra",
46        "-Wthread-safety",
47    ] + event_flag,
48
49    lto: {
50        thin: true,
51    },
52    sanitize: {
53        cfi: true,
54    },
55}
56
57cc_library_static {
58    name: "liblogd",
59    defaults: ["logd_defaults"],
60    host_supported: true,
61    srcs: [
62        "ChattyLogBuffer.cpp",
63        "CompressionEngine.cpp",
64        "LogBufferElement.cpp",
65        "LogReaderList.cpp",
66        "LogReaderThread.cpp",
67        "LogSize.cpp",
68        "LogStatistics.cpp",
69        "LogTags.cpp",
70        "LogdLock.cpp",
71        "PruneList.cpp",
72        "SerializedFlushToState.cpp",
73        "SerializedLogBuffer.cpp",
74        "SerializedLogChunk.cpp",
75        "SimpleLogBuffer.cpp",
76    ],
77    static_libs: ["liblog"],
78    logtags: ["event.logtags"],
79
80    export_include_dirs: ["."],
81}
82
83cc_binary {
84    name: "logd",
85    defaults: ["logd_defaults"],
86    init_rc: ["logd.rc"],
87
88    srcs: [
89        "main.cpp",
90        "LogPermissions.cpp",
91        "CommandListener.cpp",
92        "LogListener.cpp",
93        "LogReader.cpp",
94        "LogAudit.cpp",
95        "LogKlog.cpp",
96        "libaudit.cpp",
97        "PkgIds.cpp",
98    ],
99
100    static_libs: [
101        "liblog",
102        "liblogd",
103    ],
104
105    shared_libs: [
106        "libsysutils",
107        "libcutils",
108        "libpackagelistparser",
109        "libprocessgroup",
110        "libcap",
111    ],
112}
113
114cc_binary {
115    name: "auditctl",
116
117    srcs: [
118        "auditctl.cpp",
119        "libaudit.cpp",
120    ],
121
122    shared_libs: ["libbase"],
123
124    cflags: [
125        "-Wextra",
126    ],
127}
128
129prebuilt_etc {
130    name: "logtagd.rc",
131    src: "logtagd.rc",
132    sub_dir: "init",
133}
134
135// -----------------------------------------------------------------------------
136// Unit tests.
137// -----------------------------------------------------------------------------
138
139cc_defaults {
140    name: "logd-unit-test-defaults",
141
142    cflags: [
143        "-fstack-protector-all",
144        "-g",
145        "-Wall",
146        "-Wthread-safety",
147        "-Wextra",
148        "-Werror",
149        "-fno-builtin",
150    ] + event_flag,
151
152    srcs: [
153        "ChattyLogBufferTest.cpp",
154        "logd_test.cpp",
155        "LogBufferTest.cpp",
156        "SerializedLogBufferTest.cpp",
157        "SerializedLogChunkTest.cpp",
158        "SerializedFlushToStateTest.cpp",
159    ],
160    sanitize: {
161        cfi: true,
162    },
163    static_libs: [
164        "libbase",
165        "libcutils",
166        "liblog",
167        "liblogd",
168        "libselinux",
169        "libz",
170        "libzstd",
171    ],
172}
173
174// Build tests for the logger. Run with:
175//   adb shell /data/nativetest/logd-unit-tests/logd-unit-tests
176cc_test {
177    name: "logd-unit-tests",
178    host_supported: true,
179    defaults: ["logd-unit-test-defaults"],
180    test_suites: [
181        "general-tests",
182    ],
183}
184
185cc_test {
186    name: "CtsLogdTestCases",
187    defaults: ["logd-unit-test-defaults"],
188    multilib: {
189        lib32: {
190            suffix: "32",
191        },
192        lib64: {
193            suffix: "64",
194        },
195    },
196    test_suites: [
197        "cts",
198        "device-tests",
199    ],
200    test_config: "device_test_config.xml",
201}
202
203cc_binary {
204    name: "replay_messages",
205    defaults: ["logd_defaults"],
206    host_supported: true,
207
208    srcs: [
209        "ReplayMessages.cpp",
210    ],
211
212    static_libs: [
213        "libbase",
214        "libcutils",
215        "liblog",
216        "liblogd",
217        "libselinux",
218        "libz",
219        "libzstd",
220    ],
221}
222