1# Copyright 2021 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#      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
15ncsid_headers = include_directories('.')
16
17fmt_dep = dependency('fmt', required: false)
18if not fmt_dep.found()
19  fmt_proj = import('cmake').subproject(
20    'fmt',
21    cmake_options: [
22      '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
23      '-DMASTER_PROJECT=OFF'
24    ],
25    required: false)
26  assert(fmt_proj.found(), 'fmtlib is required')
27  fmt_dep = fmt_proj.dependency('fmt')
28endif
29
30ncsid_deps = [
31  fmt_dep,
32  dependency('sdbusplus', fallback: ['sdbusplus', 'sdbusplus_dep']),
33  dependency('stdplus', fallback: ['stdplus', 'stdplus_dep']),
34]
35
36ncsid_lib = static_library(
37  'ncsid',
38  [
39    'net_config.cpp',
40    'net_iface.cpp',
41    'net_sockio.cpp',
42    'ncsi_sockio.cpp',
43    'ncsi_state_machine.cpp',
44    'platforms/nemora/portable/ncsi_fsm.c',
45    'platforms/nemora/portable/ncsi_client.c',
46    'platforms/nemora/portable/ncsi_server.c',
47  ],
48  include_directories: ncsid_headers,
49  implicit_include_directories: false,
50  dependencies: ncsid_deps)
51
52ncsid = declare_dependency(
53  dependencies: ncsid_deps,
54  include_directories: ncsid_headers,
55  link_with: ncsid_lib)
56
57executable(
58  'ncsid',
59  'ncsid.cpp',
60  implicit_include_directories: false,
61  dependencies: ncsid,
62  install: true,
63  install_dir: get_option('libexecdir'))
64
65normalize_ip = executable(
66  'normalize_ip',
67  'normalize_ip.c',
68  implicit_include_directories: false,
69  install: true)
70
71normalize_mac = executable(
72  'normalize_mac',
73  'normalize_mac.c',
74  implicit_include_directories: false,
75  install: true)
76
77install_data(
78  'ncsid_udhcpc4.script',
79  'ncsid_udhcpc6.script',
80  'update_ra_gw.sh',
81  'update_ra_neighbor.sh',
82  'update_static_neighbors.sh',
83  install_mode: 'rwxr-xr-x',
84  install_dir: get_option('libexecdir'))
85
86install_data(
87  'ncsid_lib.sh',
88  install_mode: 'rw-r--r--',
89  install_dir: get_option('libexecdir'))
90
91systemd = dependency('systemd')
92systemunitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
93
94libexecdir = get_option('prefix') / get_option('libexecdir')
95
96configure_file(
97  configuration: {'BIN': libexecdir / 'ncsid'},
98  input: 'ncsid@.service.in',
99  output: 'ncsid@.service',
100  install_mode: 'rw-r--r--',
101  install_dir: systemunitdir)
102
103configure_file(
104  configuration: {'BIN': libexecdir / 'update_ra_gw.sh'},
105  input: 'update-ra-gw@.service.in',
106  output: 'update-ra-gw@.service',
107  install_mode: 'rw-r--r--',
108  install_dir: systemunitdir)
109
110configure_file(
111  configuration: {'BIN': libexecdir / 'update_ra_neighbor.sh'},
112  input: 'update-ra-neighbor@.service.in',
113  output: 'update-ra-neighbor@.service',
114  install_mode: 'rw-r--r--',
115  install_dir: systemunitdir)
116
117configure_file(
118  configuration: {'BIN': libexecdir / 'update_static_neighbors.sh'},
119  input: 'update-static-neighbors@.service.in',
120  output: 'update-static-neighbors@.service',
121  install_mode: 'rw-r--r--',
122  install_dir: systemunitdir)
123
124configure_file(
125  configuration: {
126    'SCRIPT': libexecdir / 'ncsid_udhcpc4.script'},
127  input: 'dhcp4@.service.in',
128  output: 'dhcp4@.service',
129  install_mode: 'rw-r--r--',
130  install_dir: systemunitdir)
131
132configure_file(
133  configuration: {
134    'SCRIPT': libexecdir / 'ncsid_udhcpc6.script'},
135  input: 'dhcp6@.service.in',
136  output: 'dhcp6@.service',
137  install_mode: 'rw-r--r--',
138  install_dir: systemunitdir)
139
140install_data(
141  'nic-hostful@.target',
142  'nic-hostless@.target',
143  'update-ra-neighbor@.timer',
144  'update-static-neighbors@.timer',
145  install_mode: 'rw-r--r--',
146  install_dir: systemunitdir)
147