1
2def build(ctx):
3    bldnode = ctx.bldnode.abspath()
4
5    if ctx.variant == "host":
6        bison_source = ["ntp_parser.y"]
7
8        ctx(
9            features="c",
10            includes=[ctx.bldnode.parent.abspath(), "../include", "."],
11            source=bison_source,
12            target="bison_obj",
13        )
14
15        # Generate Bison file first.
16        ctx.add_group()
17
18        keyword_gen_source = ["keyword-gen.c", ]
19
20        ctx(
21            features="c cprogram",
22            includes=[ctx.bldnode.parent.abspath(), "../include", "."],
23            install_path=None,
24            source=keyword_gen_source,
25            target="keyword-gen",
26        )
27
28        # XXX: needs a dependency to rebuild ntp_keyword.h
29        #      when keyword-gen is rebuilt
30
31        # Make sure keyword-gen is created next.
32        ctx.add_group()
33
34        ctx(
35            features="c",
36            rule="%s/ntpd/keyword-gen ${SRC} > ${TGT}" % bldnode,
37            source="ntp_parser.tab.h",
38            target="ntp_keyword.h"
39        )
40
41        # Make sure ntp_keyword.h is created last.
42        ctx.add_group()
43
44        return
45
46    libntpd_source = [
47        "ntp_control.c",
48        "ntp_filegen.c",
49        "ntp_leapsec.c",
50        "ntp_monitor.c",    # Needed by the restrict code
51        "ntp_recvbuff.c",
52        "ntp_restrict.c",
53        "ntp_util.c",
54    ]
55
56    if not ctx.env.DISABLE_NTS:
57      libntpd_source += [
58        "nts.c",
59        "nts_server.c",
60        "nts_client.c",
61        "nts_cookie.c",
62        "nts_extens.c",
63    ]
64
65    ctx(
66        features="c",
67        includes=[ctx.bldnode.parent.abspath(), "../include", "../libaes_siv"],
68        source=libntpd_source,
69        target="libntpd_obj",
70        use="CRYPTO aes_siv",
71    )
72
73    ctx(
74        target="ntpd_lib",
75        features="c cstlib",
76        use="libntpd_obj",
77        # use="libntpd_obj bison_obj",
78    )
79
80    use_refclock = ""      # XXX: there must be a better way to do this
81    if ctx.env.REFCLOCK_ENABLE:
82
83        refclock_source = ["ntp_refclock.c",
84			   "ntp_wrapdate.c",
85                           "refclock_conf.c"
86                           ]
87
88        ctx(
89            target="refclock",
90            features="c",
91            includes=[ctx.bldnode.parent.abspath(), "../include"],
92            source=refclock_source,
93        )
94        use_refclock += "refclock"
95
96        for file, define in ctx.env.REFCLOCK_SOURCE:
97            ctx(
98                defines=["%s=1" % define],
99                features="c",
100                includes=[ctx.bldnode.parent.abspath(), "../include", "../libjsmn"],
101                # XXX: These need to go into config.h
102                #      rather than the command line for the individual drivers
103                source="refclock_%s.c" % file,
104                target="refclock_%s" % file,
105            )
106            use_refclock += " refclock_%s" % file
107
108    ntpd_source = [
109        "ntp_config.c",
110        "ntp_io.c",
111        "ntp_loopfilter.c",
112        "ntp_packetstamp.c",
113        "ntp_peer.c",
114        "ntp_proto.c",
115        "ntp_sandbox.c",
116        "ntp_scanner.c",
117        "ntp_signd.c",
118        "ntp_timer.c",
119        "ntp_dns.c",
120        "ntpd.c",
121        ctx.bldnode.parent.find_node("host/ntpd/ntp_parser.tab.c")
122    ]
123
124    ctx(
125        features="c rtems_trace cprogram",
126        includes=[
127            ctx.bldnode.parent.abspath(), "../include",
128            "%s/host/ntpd/" % ctx.bldnode.parent.abspath(), "." ],
129        install_path='${SBINDIR}',
130        source=ntpd_source,
131        target="ntpd",
132        use="libntpd_obj ntp M parse RT CAP SECCOMP PTHREAD NTPD "
133            "CRYPTO SSL DNS_SD %s SOCKET NSL SCF" % use_refclock,
134    )
135
136    ctx.manpage(8, "ntpd-man.adoc")
137    ctx.manpage(5, "ntp.conf-man.adoc")
138    ctx.manpage(5, "ntp.keys-man.adoc")
139