| 1 | # FIXME: somehow disabling link map makes tools/mkext4.py crash
|
|---|
| 2 | link_map = true
|
|---|
| 3 | disassemble = CONFIG_LINE_DEBUG
|
|---|
| 4 | install_nonessential_data = not CONFIG_BAREBONE
|
|---|
| 5 | # TODO: Allow installing debug files.
|
|---|
| 6 | # This is currently disabled due to boot image size restrictions.
|
|---|
| 7 | install_debug_files = false
|
|---|
| 8 |
|
|---|
| 9 | subdir('lib')
|
|---|
| 10 | subdir('app')
|
|---|
| 11 | subdir('srv')
|
|---|
| 12 | subdir('drv')
|
|---|
| 13 |
|
|---|
| 14 | dirs = []
|
|---|
| 15 |
|
|---|
| 16 | foreach app : apps
|
|---|
| 17 | dirs += {
|
|---|
| 18 | 'subdir': join_paths('app', app),
|
|---|
| 19 | 'installdir': 'app',
|
|---|
| 20 | }
|
|---|
| 21 | endforeach
|
|---|
| 22 |
|
|---|
| 23 | foreach srv : srvs
|
|---|
| 24 | _dirname = run_command(dirname, srv, check: true).stdout().strip()
|
|---|
| 25 |
|
|---|
| 26 | dirs += {
|
|---|
| 27 | 'subdir': join_paths('srv', srv),
|
|---|
| 28 | 'installdir': _dirname == '.' ? 'srv' : ('srv' / _dirname),
|
|---|
| 29 | }
|
|---|
| 30 | endforeach
|
|---|
| 31 |
|
|---|
| 32 | foreach drv : drvs
|
|---|
| 33 | _basename = run_command(basename, drv, check: true).stdout().strip()
|
|---|
| 34 | _dirname = run_command(dirname, drv, check: true).stdout().strip()
|
|---|
| 35 |
|
|---|
| 36 | dirs += {
|
|---|
| 37 | 'subdir': 'drv' / drv,
|
|---|
| 38 | 'installdir': 'drv' / _basename,
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | # Install driver metadata.
|
|---|
| 42 | if not CONFIG_BAREBONE or rd_essential.contains('drv' / drv)
|
|---|
| 43 | install_data('drv' / drv / _basename + '.ma', install_dir: 'drv' / _basename)
|
|---|
| 44 | endif
|
|---|
| 45 | endforeach
|
|---|
| 46 |
|
|---|
| 47 | bin_targets = []
|
|---|
| 48 |
|
|---|
| 49 | foreach appdirs : dirs
|
|---|
| 50 | src = []
|
|---|
| 51 | test_src = []
|
|---|
| 52 | includes = []
|
|---|
| 53 | deps = []
|
|---|
| 54 | c_args = []
|
|---|
| 55 | link_args = []
|
|---|
| 56 | language = 'c'
|
|---|
| 57 |
|
|---|
| 58 | subdir(appdirs.get('subdir'))
|
|---|
| 59 |
|
|---|
| 60 | dir = appdirs.get('subdir')
|
|---|
| 61 | installdir = appdirs.get('installdir')
|
|---|
| 62 |
|
|---|
| 63 | install = not CONFIG_BAREBONE or rd_essential.contains(dir)
|
|---|
| 64 |
|
|---|
| 65 | # basename/dirname will be is useful later.
|
|---|
| 66 | _basename = run_command(basename, dir, check: true).stdout().strip()
|
|---|
| 67 | _dirname = run_command(dirname, dir, check: true).stdout().strip()
|
|---|
| 68 |
|
|---|
| 69 | # Extra linker flags
|
|---|
| 70 |
|
|---|
| 71 | # TODO: let meson do this on install instead, so that disassembly works
|
|---|
| 72 | if CONFIG_STRIP_BINARIES
|
|---|
| 73 | link_args += [ '-s' ]
|
|---|
| 74 | endif
|
|---|
| 75 |
|
|---|
| 76 | # Init binaries need to always be linked statically.
|
|---|
| 77 | static_build = (not CONFIG_USE_SHARED_LIBS) or rd_init.contains(dir)
|
|---|
| 78 |
|
|---|
| 79 | # Add the corresponding standard libraries to dependencies.
|
|---|
| 80 |
|
|---|
| 81 | deps += [ 'c' ]
|
|---|
| 82 |
|
|---|
| 83 | if language == 'cpp'
|
|---|
| 84 | deps += 'cpp'
|
|---|
| 85 | endif
|
|---|
| 86 |
|
|---|
| 87 | # Binaries in the 'drv' subdirectory link libdrv by default.
|
|---|
| 88 |
|
|---|
| 89 | is_drv = (dir.split('/')[0] == 'drv')
|
|---|
| 90 |
|
|---|
| 91 | if is_drv
|
|---|
| 92 | deps += [ 'drv' ]
|
|---|
| 93 | endif
|
|---|
| 94 |
|
|---|
| 95 | # Convert strings to dependency objects
|
|---|
| 96 |
|
|---|
| 97 | _deps = []
|
|---|
| 98 | foreach s : deps
|
|---|
| 99 | _deps += get_variable('lib' + s).get(static_build ? 'static' : 'any')
|
|---|
| 100 | endforeach
|
|---|
| 101 |
|
|---|
| 102 | # Build executable
|
|---|
| 103 |
|
|---|
| 104 | if src.length() > 0
|
|---|
| 105 | bin_targets += {
|
|---|
| 106 | 'src': src,
|
|---|
| 107 | 'dirname': _dirname,
|
|---|
| 108 | 'basename': _basename,
|
|---|
| 109 | 'install': install,
|
|---|
| 110 | 'install_dir': installdir,
|
|---|
| 111 | 'includes': includes,
|
|---|
| 112 | 'dependencies': _deps,
|
|---|
| 113 | 'c_args': c_args,
|
|---|
| 114 | 'link_args': link_args + (static_build ? [ '-static' ] : []),
|
|---|
| 115 | }
|
|---|
| 116 | endif
|
|---|
| 117 |
|
|---|
| 118 | # Build test executable, if any
|
|---|
| 119 |
|
|---|
| 120 | if test_src.length() > 0
|
|---|
| 121 | bin_targets += {
|
|---|
| 122 | 'src': test_src,
|
|---|
| 123 | 'dirname': _dirname,
|
|---|
| 124 | 'basename': 'test-' + installdir.underscorify() + (is_drv ? '' : ('_' + _basename)),
|
|---|
| 125 | 'install': install and CONFIG_PCUT_TESTS,
|
|---|
| 126 | 'install_dir': 'test',
|
|---|
| 127 | 'includes': includes,
|
|---|
| 128 | 'dependencies': [ _deps, libpcut.get('any') ],
|
|---|
| 129 | 'c_args': c_args,
|
|---|
| 130 | 'link_args': link_args,
|
|---|
| 131 | }
|
|---|
| 132 | endif
|
|---|
| 133 | endforeach
|
|---|
| 134 |
|
|---|
| 135 | foreach tst : bin_targets
|
|---|
| 136 | _ldargs = tst.get('link_args')
|
|---|
| 137 | _src = tst.get('src')
|
|---|
| 138 |
|
|---|
| 139 | _install_dir = tst.get('install_dir').split('/')
|
|---|
| 140 | _install_dir += tst.get('basename')
|
|---|
| 141 | _install = tst.get('install')
|
|---|
| 142 |
|
|---|
| 143 | if _install
|
|---|
| 144 | _install_name = 'install@' + '$'.join(_install_dir)
|
|---|
| 145 | else
|
|---|
| 146 | _install_name = '_'.join(_install_dir)
|
|---|
| 147 | endif
|
|---|
| 148 |
|
|---|
| 149 | if _install and install_debug_files
|
|---|
| 150 | _debug_name = 'install@' + '$'.join([ 'debug' ] + _install_dir)
|
|---|
| 151 | else
|
|---|
| 152 | _debug_name = '_'.join(_install_dir)
|
|---|
| 153 | endif
|
|---|
| 154 |
|
|---|
| 155 | if link_map
|
|---|
| 156 | # We want linker to generate link map for debugging.
|
|---|
| 157 | _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _debug_name + '.map' ]
|
|---|
| 158 | endif
|
|---|
| 159 |
|
|---|
| 160 | _bin = executable(_install_name, _src,
|
|---|
| 161 | include_directories: tst.get('includes'),
|
|---|
| 162 | dependencies: tst.get('dependencies'),
|
|---|
| 163 | objects: startfiles,
|
|---|
| 164 | c_args: arch_uspace_c_args + tst.get('c_args'),
|
|---|
| 165 | cpp_args: arch_uspace_c_args + tst.get('c_args'),
|
|---|
| 166 | link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
|
|---|
| 167 | implicit_include_directories: false,
|
|---|
| 168 | install: false,
|
|---|
| 169 | #install_dir: tst.get('install_dir'),
|
|---|
| 170 | build_by_default: true,
|
|---|
| 171 | )
|
|---|
| 172 |
|
|---|
| 173 | if disassemble
|
|---|
| 174 | custom_target(_debug_name + '.disasm',
|
|---|
| 175 | command: [ objdump, '-S', '@INPUT@' ],
|
|---|
| 176 | input: _bin,
|
|---|
| 177 | output: _debug_name + '.disasm',
|
|---|
| 178 | capture: true,
|
|---|
| 179 | install: false,
|
|---|
| 180 | #install_dir: 'debug' / tst.get('install_dir'),
|
|---|
| 181 | build_by_default: true,
|
|---|
| 182 | )
|
|---|
| 183 | endif
|
|---|
| 184 | endforeach
|
|---|