xref: /aosp_15_r20/external/sandboxed-api/sandboxed_api/bazel/external/libcap.BUILD (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2019 Google LLC
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#     https://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
15genrule(
16    name = "cap_names_list_h",
17    srcs = ["libcap/include/uapi/linux/capability.h"],
18    outs = ["cap_names.list.h"],
19    # Use the same logic as libcap/Makefile
20    cmd = """
21        sed -ne '/^#define[ \\t]CAP[_A-Z]\\+[ \\t]\\+[0-9]\\+/{s/^#define \\([^ \\t]*\\)[ \\t]*\\([^ \\t]*\\)/\\{"\\1",\\2\\},/p;}' $< | \\
22        tr "[:upper:]" "[:lower:]" > $@
23    """,
24    visibility = ["//visibility:private"],
25)
26
27cc_library(
28    name = "makenames_textual_hdrs",
29    textual_hdrs = [
30        ":cap_names.list.h",
31        "libcap/include/uapi/linux/capability.h",
32    ],
33    visibility = ["//visibility:private"],
34)
35
36cc_binary(
37    name = "makenames",
38    srcs = [
39        "libcap/_makenames.c",
40        "libcap/include/sys/capability.h",
41    ],
42    includes = [
43        "libcap/..",
44        "libcap/include",
45        "libcap/include/uapi",
46    ],
47    visibility = ["//visibility:private"],
48    deps = [":makenames_textual_hdrs"],
49)
50
51genrule(
52    name = "cap_names_h",
53    outs = ["libcap/cap_names.h"],
54    cmd = "mkdir -p libcap && $(location makenames) > $@ || { rm -f $@; false; }",
55    tools = [":makenames"],
56    visibility = ["//visibility:private"],
57)
58
59cc_library(
60    name = "libcap",
61    srcs = [
62        "libcap/cap_alloc.c",
63        "libcap/cap_extint.c",
64        "libcap/cap_file.c",
65        "libcap/cap_flag.c",
66        "libcap/cap_proc.c",
67        "libcap/cap_text.c",
68    ],
69    copts = [
70        "-Wno-tautological-compare",
71        "-Wno-unused-result",
72        # Work around sys/xattr.h not declaring this
73        "-DXATTR_NAME_CAPS=\"\\\"security.capability\\\"\"",
74    ],
75    includes = [
76        "libcap",
77        "libcap/include",
78        "libcap/include/uapi",
79    ],
80    textual_hdrs = [
81        "libcap/include/sys/capability.h",
82        "libcap/include/uapi/linux/capability.h",
83        "libcap/libcap.h",
84        "libcap/cap_names.h",
85    ],
86    visibility = ["//visibility:public"],
87)
88