Move clipboard API from libc to a separate library
[helenos.git] / uspace / meson.build
blobfdccab6d82006ca35f325189e2ff72dff1df9767
2 # Copyright (c) 2005 Martin Decky
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
9 # - Redistributions of source code must retain the above copyright
10 #   notice, this list of conditions and the following disclaimer.
11 # - Redistributions in binary form must reproduce the above copyright
12 #   notice, this list of conditions and the following disclaimer in the
13 #   documentation and/or other materials provided with the distribution.
14 # - The name of the author may not be used to endorse or promote products
15 #   derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # FIXME: somehow disabling link map makes tools/mkext4.py crash
30 link_map = true
31 disassemble = CONFIG_LINE_DEBUG
32 install_nonessential_data = not CONFIG_BAREBONE
33 # TODO: Allow installing debug files.
34 # This is currently disabled due to boot image size restrictions.
35 install_debug_files = false
37 subdir('lib')
38 subdir('app')
39 subdir('srv')
40 subdir('drv')
42 dirs = []
44 foreach app : apps
45         dirs += {
46                 'subdir': join_paths('app', app),
47                 'installdir': 'app',
48         }
49 endforeach
51 foreach srv : srvs
52         _dirname = run_command(dirname, srv, check: true).stdout().strip()
54         dirs += {
55                 'subdir': join_paths('srv', srv),
56                 'installdir': _dirname == '.' ? 'srv' : ('srv' / _dirname),
57         }
58 endforeach
60 if CONFIG_BAREBONE
61         drv_list = rd_essential_drv
62 else
63         drv_list = rd_drv
64 endif
66 foreach drv : drvs
67         _basename = run_command(basename, drv, check: true).stdout().strip()
68         _dirname = run_command(dirname, drv, check: true).stdout().strip()
70         dirs += {
71                 'subdir': 'drv' / drv,
72                 'installdir': 'drv' / _basename,
73         }
75         # Install driver metadata.
76         if drv_list.contains('drv' / drv)
77                 _src = meson.current_source_dir() / 'drv' / drv / _basename + '.ma'
78                 _dstdir = 'drv' / _basename
79                 install_files += [[ _dstdir, _src, _basename + '.ma' ]]
80                 install_deps += files(_src)
81         endif
82 endforeach
84 bin_targets = []
86 foreach appdirs : dirs
87         src = []
88         test_src = []
89         includes = []
90         deps = []
91         c_args = []
92         link_args = []
93         language = 'c'
94         installed_data = []
95         platform_specific = false
97         subdir(appdirs.get('subdir'))
99         dir = appdirs.get('subdir')
100         installdir = appdirs.get('installdir')
102         is_drv = (dir.split('/')[0] == 'drv')
104         if is_drv
105                 # Drivers are installed based on rd_[essential_]drv list
106                 install = drv_list.contains(dir)
107         else
108                 #
109                 # Servers and applications are installed all (unless
110                 # platform-specific) or based on rd_essential in case
111                 # of barebone build or platform-specific
112                 #
113                 install = (not CONFIG_BAREBONE and not platform_specific) \
114                     or rd_essential.contains(dir)
115         endif
117         if install
118                 # Install data files, if any.
119                 foreach _f : installed_data
120                         _dstdir = _f.get('dir')
121                         _src = meson.current_source_dir() / dir / _f.get('name')
122                         install_files += [[ _dstdir, _src, _f.get('name') ]]
123                         install_deps += files(_src)
124                 endforeach
125         endif
127         # basename/dirname will be is useful later.
128         _basename = run_command(basename, dir, check: true).stdout().strip()
129         _dirname = run_command(dirname, dir, check: true).stdout().strip()
131         # Extra linker flags
133         # TODO: only strip after disassembly
134         if CONFIG_STRIP_BINARIES
135                 link_args += [ '-s' ]
136         endif
138         # Init binaries need to always be linked statically.
139         static_build = (not CONFIG_USE_SHARED_LIBS) or rd_init.contains(dir)
141         # Add the corresponding standard libraries to dependencies.
143         deps += [ 'c' ]
145         if language == 'cpp'
146                 deps += 'cpp'
147         endif
149         # Binaries in the 'drv' subdirectory link libdrv by default.
152         if is_drv
153                 deps += [ 'drv' ]
154         endif
156         # Convert strings to dependency objects
158         _deps = []
159         foreach s : deps
160                 _deps += get_variable('lib' + s).get(static_build ? 'static' : 'any')
161         endforeach
163         # Build executable
165         if src.length() > 0
166                 bin_targets += {
167                         'src': src,
168                         'dirname': _dirname,
169                         'basename': _basename,
170                         'install': install,
171                         'install_dir': installdir,
172                         'includes': includes,
173                         'dependencies': _deps,
174                         'c_args': c_args,
175                         'link_args': link_args + (static_build ? [ '-static' ] : []),
176                         'init': rd_init.contains(dir),
177                 }
178         endif
180         # Build test executable, if any
182         if test_src.length() > 0
183                 bin_targets += {
184                         'src': test_src,
185                         'dirname': _dirname,
186                         'basename': 'test-' + installdir.underscorify() + (is_drv ? '' : ('_' + _basename)),
187                         'install': install and CONFIG_PCUT_TESTS,
188                         'install_dir': 'test',
189                         'includes': includes,
190                         'dependencies': [ _deps, libpcut.get('any') ],
191                         'c_args': c_args,
192                         'link_args': link_args,
193                         'init': false,
194                 }
195         endif
196 endforeach
198 foreach tst : bin_targets
199         _ldargs = tst.get('link_args')
200         _src = tst.get('src')
202         _install = tst.get('install')
203         _install_dir = tst.get('install_dir')
204         _basename = tst.get('basename')
205         _full_install_path = _install_dir / _basename
206         _build_name = _full_install_path.underscorify()
207         _full_build_name = meson.current_build_dir() / _build_name
208         _is_init = tst.get('init')
210         if link_map
211                 # We want linker to generate link map for debugging.
212                 _ldargs += [ '-Wl,-Map,' + _full_build_name + '.map' ]
213         endif
215         _bin = executable(_build_name, _src,
216                 include_directories: tst.get('includes'),
217                 dependencies: tst.get('dependencies'),
218                 link_whole: libstartfiles,
219                 c_args: arch_uspace_c_args + tst.get('c_args'),
220                 cpp_args: arch_uspace_c_args + tst.get('c_args'),
221                 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
222                 implicit_include_directories: true,
223                 build_by_default: true,
224         )
226         if _is_init
227                 rd_init_binaries += [[ _bin, _full_install_path ]]
228         endif
230         if disassemble
231                 _disasm = custom_target(_build_name + '.disasm',
232                         command: [ objdump, '-S', '@INPUT@' ],
233                         input: _bin,
234                         output: _build_name + '.disasm',
235                         capture: true,
236                         build_by_default: true,
237                 )
238         endif
240         if _install
241                 # Due to certain quirks of our build, executables need to be built with a different name than what they are installed with.
242                 # Meson doesn't support renaming installed files (at least not as of mid-2019) so we do it manually.
244                 install_files += [[ _install_dir, _full_build_name, _basename ]]
245                 install_deps += [ _bin ]
247                 if install_debug_files
248                         if disassemble
249                                 install_files += [[ 'debug' / _install_dir, _full_build_name + '.disasm', _basename + '.disasm' ]]
250                                 install_deps += [ _disasm ]
251                         endif
252                         if link_map
253                                 install_files += [[ 'debug' / _install_dir, _full_build_name + '.map', _basename + '.map' ]]
254                         endif
255                 endif
256         endif
257 endforeach