blob: f72c059a31f899aa14227c6eedce2c3167fe667d [file] [log] [blame]
Tim Windelschmidt8fd51cd2025-06-29 02:20:17 +02001load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
2load("@bazel_skylib//rules:write_file.bzl", "write_file")
Tim Windelschmidt156248b2025-01-10 00:27:45 +01003load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +02004
Tim Windelschmidt8fd51cd2025-06-29 02:20:17 +02005write_file(
6 name = "config.h_template",
7 out = "config.h.in",
8 content = ["""\
9#define LINUX
10#define DEBUG 0
11#define USE_PTHREAD_ASYNCDNS
12
13#define CHRONY_VERSION "%CHRONY_VERSION%"
14#define CHRONYD_FEATURES "NTP RTC SCFILTER ASYNCDNS"
15#define FEAT_NTP
16#define FEAT_RTC
17#define FEAT_SCFILTER
18#define FEAT_ASYNCDNS
19#define FEAT_PRIVDROP
20#define CAP_IS_SUPPORTED
21
22#define DEFAULT_COMMAND_SOCKET "/todo/chronyd.sock"
23#define DEFAULT_CONF_FILE "/todo/chrony.conf"
24#define DEFAULT_HWCLOCK_FILE ""
25#define DEFAULT_PID_FILE "/todo/chronyd.pid"
26#define DEFAULT_RTC_DEVICE "/dev/rtc"
27#define DEFAULT_USER "root"
28
29#define MAIL_PROGRAM "/todo/sendmail"
30"""],
31)
32
33expand_template(
34 name = "config.h_expanded",
35 template = ":config.h.in",
36 out = "config.h",
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +020037 substitutions = {
Tim Windelschmidte1420ab2024-08-27 01:53:16 +020038 # ONCHANGE(//build/bazel:third_party.MODULE.bazel): version needs to be kept in sync
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +020039 "%CHRONY_VERSION%": "4.1-monogon",
Lorenz Brun68dcee12021-08-31 13:12:07 +020040 },
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +020041)
42
43# Headers which couldn't be decoupled into sub-libraries.
44cc_library(
45 name = "common_hdrs",
46 srcs = [
Tim Windelschmidt8fd51cd2025-06-29 02:20:17 +020047 ":config.h_expanded",
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +020048
49 # Headers corresponding to .c files in :common.
50 "addrfilt.h",
51 "array.h",
52 "clientlog.h",
53 "cmdparse.h",
54 "conf.h",
55 "keys.h",
56 "local.h",
57 "logging.h",
58 "memory.h",
59 "nameserv.h",
60 "reference.h",
61 "regress.h",
62 "samplefilt.h",
63 "sched.h",
64 "smooth.h",
65 "socket.h",
66 "sources.h",
67 "sourcestats.h",
68 "util.h",
69
70 # Corresponding to .c files in :ntp.
71 "ntp_core.h",
72 "ntp_sources.h",
73 "nts_ke.h",
74
75 # Other headers.
76 "addressing.h",
77 "candm.h",
78 "cmdmon.h",
79 "cmac.h",
80 "hash.h",
81 "localp.h",
82 "manual.h",
83 "ntp.h",
84 "privops.h",
85 "refclock.h",
86 "reports.h",
87 "siv.h",
88 "srcparams.h",
89 "sysincl.h",
90 ],
91)
92
93# Sources which couldn't be decoupled into sub-libraries.
94cc_library(
95 name = "common",
96 srcs = [
97 "addrfilt.c",
98 "array.c",
99 "clientlog.c",
100 "cmdparse.c",
101 "conf.c",
102 "keys.c",
103 "local.c",
104 "logging.c",
105 "memory.c",
106 "reference.c",
107 "regress.c",
108 "samplefilt.c",
109 "sched.c",
110 "smooth.c",
111 "socket.c",
112 "sources.c",
113 "sourcestats.c",
114 "util.c",
115 ],
116 deps = [
117 ":common_hdrs",
118 ],
119)
120
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +0200121# MD5 library used by keys.c, which does #include "md5.c".
122cc_library(
123 name = "md5",
124 textual_hdrs = [
125 "md5.h",
126 "md5.c",
127 ],
128)
129
130cc_library(
131 name = "nameserv",
132 srcs = [
133 "nameserv.c",
134 "nameserv_async.h",
135 "nameserv_async.c",
136 ],
137 deps = [
138 ":common",
139 ],
140)
141
142cc_library(
143 name = "ntp",
144 srcs = [
145 "nts_ke_client.h",
146 "nts_ke_server.h",
147 "nts_ke_session.h",
148 "nts_ntp_client.h",
149 "nts_ntp_auth.h",
150 "nts_ntp_server.h",
151 "nts_ntp.h",
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +0200152 "ntp_auth.h",
153 "ntp_auth.c",
154 "ntp_core.c",
155 "ntp_ext.h",
156 "ntp_ext.c",
157 "ntp_io.h",
158 "ntp_io.c",
159 "ntp_signd.h",
160 "ntp_sources.c",
161 ],
162 deps = [
163 ":common",
164 ":nameserv",
165 ],
166)
167
168cc_library(
169 name = "sys",
170 srcs = [
171 "sys.h",
172 "sys.c",
173 "sys_generic.h",
174 "sys_generic.c",
175 "sys_linux.h",
176 "sys_linux.c",
177 "sys_timex.h",
178 "sys_timex.c",
179 "sys_posix.h",
180 "sys_null.h",
181 "sys_null.c",
182 ],
183 deps = [
184 ":common",
185 "@seccomp//:seccomp",
Tim Windelschmidt04b67082025-05-28 17:40:07 +0200186 "@libcap//:libcap",
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +0200187 ],
188)
189
190cc_library(
191 name = "rtc",
192 srcs = [
193 "rtc.h",
194 "rtc.c",
195 "rtc_linux.h",
196 "rtc_linux.c",
197 ],
198 deps = [
199 ":common",
200 ":sys",
201 ],
202)
203
204cc_library(
205 name = "tempcomp",
206 srcs = [
207 "tempcomp.h",
208 "tempcomp.c",
209 ],
210 deps = [
211 ":common",
212 ],
213)
214
215cc_binary(
216 name = "chrony",
217 srcs = [
218 "hash_intmd5.c",
219 "main.h",
220 "main.c",
221 "stubs.c",
Serge Bazanski8ff4b7c2021-08-17 19:21:18 +0200222 ],
223 deps = [
224 ":common",
225 ":md5",
226 ":ntp",
227 ":rtc",
228 ":tempcomp",
229 ],
230 visibility = ["//visibility:public"],
231)