source: mainline/uspace/lib/meson.build@ 7749646

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7749646 was 7749646, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Add tools/export.sh to replace make export

  • Property mode set to 100644
File size: 8.5 KB
RevLine 
[667c3fc]1always_static = not CONFIG_BUILD_SHARED_LIBS
[5fd05862]2
3# Which libraries are installed when CONFIG_DEVEL_FILES is enabled
4installed_libs = [
5 'c',
6 'math',
7 'gui',
8 'draw',
9 'softrend',
10 'posix',
11]
12
13# IMPORTANT: Dependencies must be listed before libs that depend on them.
14libs = [
15 'c',
16
17 'block',
18 'clui',
19 'compress',
20 'cpp',
21 'crypto',
22 'dltest',
23 'fdisk',
24 'fmtutil',
25 'fs',
26 'graph',
27 'http',
28 'label',
29 'math',
30 'minix',
31 'nettl',
32 'pcm',
33 'pcut',
34 'posix',
35 'scsi',
36 'sif',
37 'softrend',
38 'trackmod',
39 'untar',
40 'uri',
41
42 'bithenge',
43 'draw',
44 'drv',
45 'ext4',
46 'gui',
47 'hound',
48 'nic',
49 'usb',
50 'usbdev',
51 'usbhid',
52 'usbhost',
53 'usbvirt',
54 'virtio',
55
56 'ieee80211',
57]
58
59# Generated list of include directory paths
60include_paths = []
61
62# Generated list of test sources
63testfiles = []
64
[5852a5a]65# Text of the install script.
[7749646]66uspace_lib_devel_install_script_text = []
[5852a5a]67
[5fd05862]68foreach l : libs
69 # Variables that might be defined in library meson files:
70
71 # List of source files.
72 # To set it correctly, use files('list.c', 'of.c', 'files.c')
73 # Often this is the only variable that needs to be set.
74 src = files()
75
76 # Public include directories. These are used by everyone who depends
77 # on this library.
78 # Use include_directories('include_dir1', 'include_dir2') to set this.
79 # If the variable is omitted, it defaults to 'include' subdirectory
80 # if it exists, or the source directory otherwise.
81 # If the library has no headers, you can use
82 # includes += include_directories()
83 includes = []
84
85 # Private include directories.
86 # Unnecessary if you always include private headers using relative
87 # paths, but may be useful if you need to override system headers.
88 private_includes = []
89
90 # List of dependency names.
91 # E.g. to use libnic and libuntar use
92 # `deps = [ 'nic', 'untar' ]`
93 deps = []
94
95 # Extra arguments for the C compiler.
96 # Don't use for arguments involving file paths.
97 c_args = []
98
99 # Shared object version of the library.
100 version = '0.0'
101
102 # Sources of unit tests.
103 # Automatically get compiled into a test binary,
104 # but not into the library itself.
105 test_src = []
106
107 # Language of the library.
108 # Currently supported options are 'c' and 'cpp', with 'c' being default.
109 language = 'c'
110
111 # Whether the library can be dynamically linked.
112 # Eventually, all libraries will be shared by default and this will go away.
113 allow_shared = false
114
115 subdir(l)
116
117 # Add `include` or `.` subdirectory to include dirs if needed.
118 if includes.length() == 0
119 incdir = join_paths(l, 'include')
120 if run_command('[', '-d', incdir, ']').returncode() == 0
121 includes += include_directories(incdir)
122
[7749646]123 if installed_libs.contains(l)
[d63c842]124 _sdir = meson.current_source_dir() / l / 'include'
[7749646]125 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
[5fd05862]126 endif
127 else
128 includes += include_directories(l)
[d63c842]129
[7749646]130 if installed_libs.contains(l)
[d63c842]131 _sdir = meson.current_source_dir() / l
[7749646]132 uspace_lib_devel_install_script_text += 'mkdir -p "${DESTDIR}include/lib@0@"'.format(l)
133 uspace_lib_devel_install_script_text += 'cp -L -t "${DESTDIR}include/lib@0@" "@1@"/*.h || true'.format(l, _sdir)
[d63c842]134 endif
[5fd05862]135 endif
136 endif
137
138 # Pretty much everything depends on libc.
139 if l != 'c'
140 deps += 'c'
141 endif
142
143 if language == 'cpp' and l != 'cpp'
144 deps += 'cpp'
145 endif
146
147 mapfile = meson.current_build_dir() / 'lib' + l + '.map'
148
149 link_args = [ '-Wl,--no-undefined,--no-allow-shlib-undefined' ]
150 # We want linker to generate link map for debugging.
151 link_args += [ '-Wl,-Map,' + mapfile ]
152
153 # Convert strings to dependency objects
154 # TODO: this dependency business is way too convoluted due to issues in current Meson
155 _any_deps = []
156 _static_deps = []
157 _shared_deps = []
158 _include_deps = []
159 foreach s : deps
160 _any_deps += get_variable('lib' + s).get('any')
161 _static_deps += get_variable('lib' + s).get('static')
162 if not always_static
163 _shared_deps += get_variable('lib' + s).get('shared')
164 endif
165 _include_deps += get_variable('lib' + s).get('include')
166 endforeach
167
168 install_static_lib = CONFIG_DEVEL_FILES and installed_libs.contains(l)
169 install_shared_lib = allow_shared
170
171 _shared_dep = disabler()
172
173 if src.length() > 0
174 if not always_static
[68b892a]175 _libname = 'lib' + l + '.so.' + version.split('.')[0]
176
[5fd05862]177 _shared_lib = shared_library(l, src,
178 # TODO: Include private headers using #include "quoted",
179 # and get rid of private_includes.
180 include_directories: [ private_includes, includes ],
181 dependencies: _shared_deps,
[63660a3]182 c_args: arch_uspace_c_args + c_args,
183 cpp_args: arch_uspace_c_args + c_args,
184 link_args: arch_uspace_c_args + arch_uspace_link_args + link_args,
[5fd05862]185 version: version,
186 build_by_default: true,
187 )
188
[68b892a]189 if install_shared_lib
190 install_files += [[ 'lib', _shared_lib.full_path(), _libname ]]
191 install_deps += [ _shared_lib ]
192 endif
193
194 if install_shared_lib and install_debug_files
195 install_files += [[ 'debug/lib', mapfile, _libname + '.map' ]]
196 endif
197
[5fd05862]198 if disassemble
[68b892a]199 _disasm = custom_target('lib' + l + '.disasm',
[5fd05862]200 command: [ objdump, '-S', '@INPUT@' ],
201 input: _shared_lib,
202 output: 'lib' + l + '.disasm',
203 capture: true,
204 build_by_default: true,
205 )
[68b892a]206
207 if install_shared_lib and install_debug_files
208 install_files += [[ 'debug/lib', _disasm.full_path(), _libname + '.disasm' ]]
209 install_deps += [ _disasm ]
210 endif
[5fd05862]211 endif
212
213 _shared_dep = declare_dependency(
214 link_with: _shared_lib,
215 # TODO: Always use `include` subdirectory for public headers,
216 # and ditch the variable.
217 include_directories: includes,
218 dependencies: _shared_deps,
219 )
220 endif
221
222 _static_lib = static_library(l, src,
223 # TODO: Include private headers using #include "quoted",
224 # and get rid of private_includes.
225 include_directories: [ private_includes, includes ],
226 dependencies: _include_deps,
[63660a3]227 c_args: arch_uspace_c_args + c_args,
228 cpp_args: arch_uspace_c_args + c_args,
[5fd05862]229 )
230
[68b892a]231 if install_static_lib
232 install_files += [[ 'lib', _static_lib.full_path(), 'lib' + l + '.a' ]]
233 install_deps += [ _static_lib ]
234 endif
235
[5fd05862]236 _static_dep = declare_dependency(
237 link_with: _static_lib,
238 # TODO: Always use `include` subdirectory for public headers,
239 # and ditch the variable.
240 include_directories: includes,
241 dependencies: _static_deps,
242 )
243
244 if always_static or not allow_shared
245 _any_dep = declare_dependency(
246 link_with: _static_lib,
247 # TODO: Always use `include` subdirectory for public headers,
248 # and ditch the variable.
249 include_directories: includes,
250 dependencies: _any_deps,
251 )
252 else
253 _any_dep = declare_dependency(
254 link_with: _shared_lib,
255 # TODO: Always use `include` subdirectory for public headers,
256 # and ditch the variable.
257 include_directories: includes,
258 dependencies: _any_deps,
259 )
260 endif
261
262 _include_dep = declare_dependency(
263 # TODO: Always use `include` subdirectory for public headers,
264 # and ditch the variable.
265 include_directories: includes,
266 dependencies: _include_deps,
267 )
268 else
269 # Header-only library.
270 _any_dep = declare_dependency(
271 include_directories: includes,
272 dependencies: _any_deps,
273 )
274 _static_dep = declare_dependency(
275 include_directories: includes,
276 dependencies: _static_deps,
277 )
278 endif
279
280 if test_src.length() > 0
281 testfiles += [ {
282 'name': l,
283 'src': test_src,
284 'includes': [ private_includes, includes ],
285 } ]
286 endif
287
288 set_variable('lib' + l, {
289 'any': _any_dep,
290 'static': _static_dep,
291 'shared': _shared_dep,
292 'include': _include_dep,
293 })
294endforeach
295
296if not CONFIG_PCUT_TESTS
297 subdir_done()
298endif
299
300# Test binaries
301foreach test : testfiles
302 _testname = test['name']
303 _libname = _testname.split('-')[0]
304 _ldargs = []
305 _test_binname = 'test-lib' + _testname
306
307 if link_map
308 # We want linker to generate link map for debugging.
309 _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _test_binname + '.map' ]
310 endif
311
312 _bin = executable(_test_binname, test.get('src'),
313 include_directories: test.get('includes'),
314 dependencies: [ get_variable('lib' + _libname).get('any'), libpcut.get('any') ],
[71069a9]315 link_whole: libstartfiles,
[63660a3]316 c_args: arch_uspace_c_args,
317 cpp_args: arch_uspace_c_args,
318 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
[740e952]319 build_by_default: true,
[5fd05862]320 )
321
[68b892a]322 install_files += [[ 'test', _bin.full_path(), _test_binname ]]
323 install_deps += [ _bin ]
324
[5fd05862]325 if disassemble
[68b892a]326 _disasm = custom_target(_test_binname + '.disasm',
[5fd05862]327 command: [ objdump, '-S', '@INPUT@' ],
328 input: _bin,
329 output: _test_binname + '.disasm',
330 capture: true,
[740e952]331 build_by_default: true,
[5fd05862]332 )
[68b892a]333
[740e952]334 if install_debug_files
335 install_files += [[ 'debug/test', _disasm.full_path(), _test_binname + '.disasm' ]]
336 install_deps += [ _disasm ]
337 endif
[5fd05862]338 endif
339endforeach
Note: See TracBrowser for help on using the repository browser.