| 1 | # TODO: Use vcs_tag() to generate version string
|
|---|
| 2 | # TODO: jobfile
|
|---|
| 3 | # TODO: lto
|
|---|
| 4 | # TODO: CONFIG_BUILD_SHARED_LIBS
|
|---|
| 5 | # TODO: fix clang build
|
|---|
| 6 |
|
|---|
| 7 | project(
|
|---|
| 8 | 'HelenOS',
|
|---|
| 9 | [ 'c', 'cpp' ],
|
|---|
| 10 | default_options : ['buildtype=plain', 'c_std=gnu11', 'cpp_std=c++17', 'warning_level=3', 'werror=false', 'b_staticpic=false', 'default_library=shared', 'prefix=/' ],
|
|---|
| 11 | )
|
|---|
| 12 |
|
|---|
| 13 | cc = meson.get_compiler('c')
|
|---|
| 14 | basename = find_program('basename')
|
|---|
| 15 | dirname = find_program('dirname')
|
|---|
| 16 | find = find_program('find')
|
|---|
| 17 | grep = find_program('grep')
|
|---|
| 18 | mkarray = find_program('tools/mkarray_for_meson.sh')
|
|---|
| 19 | objdump = find_program('objdump')
|
|---|
| 20 | sed = find_program('sed')
|
|---|
| 21 | unzip = find_program('unzip')
|
|---|
| 22 | which = find_program('which')
|
|---|
| 23 |
|
|---|
| 24 | autocheck = generator(find_program('tools/autocheck.awk'),
|
|---|
| 25 | arguments: [ '@INPUT@' ],
|
|---|
| 26 | output: '@PLAINNAME@.check.c',
|
|---|
| 27 | capture: true,
|
|---|
| 28 | )
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | if get_option('default_library') == 'both'
|
|---|
| 32 | error('You must use either shared or static for default_library.')
|
|---|
| 33 | endif
|
|---|
| 34 |
|
|---|
| 35 | debug_options = false
|
|---|
| 36 |
|
|---|
| 37 | # Output compiler flags for use by third-party builds.
|
|---|
| 38 | # NOTE: See $srcroot/meson/cross/$arch for architecture-specific compiler flags.
|
|---|
| 39 |
|
|---|
| 40 | if debug_options
|
|---|
| 41 | message('Cross c_args:')
|
|---|
| 42 | message(meson.get_cross_property('c_args'))
|
|---|
| 43 | message('Cross cpp_args:')
|
|---|
| 44 | message(meson.get_cross_property('cpp_args'))
|
|---|
| 45 | message('Cross c_link_args:')
|
|---|
| 46 | message(meson.get_cross_property('c_link_args'))
|
|---|
| 47 | message('Cross cpp_link_args:')
|
|---|
| 48 | message(meson.get_cross_property('cpp_link_args'))
|
|---|
| 49 | endif
|
|---|
| 50 |
|
|---|
| 51 | # Read some variables from Makefile.common
|
|---|
| 52 | config_variables = [
|
|---|
| 53 | # Uspace and kernel
|
|---|
| 54 | 'CONFIG_BAREBONE',
|
|---|
| 55 | 'CONFIG_BUILD_SHARED_LIBS',
|
|---|
| 56 | 'CONFIG_DEBUG',
|
|---|
| 57 | 'CONFIG_DEVEL_FILES',
|
|---|
| 58 | 'CONFIG_FPU',
|
|---|
| 59 | 'CONFIG_LINE_DEBUG',
|
|---|
| 60 | 'CONFIG_PCUT_SELF_TESTS',
|
|---|
| 61 | 'CONFIG_PCUT_TESTS',
|
|---|
| 62 | 'CONFIG_RTLD',
|
|---|
| 63 | 'CONFIG_STRIP_BINARIES',
|
|---|
| 64 | 'CONFIG_UBSAN',
|
|---|
| 65 | 'CONFIG_USE_SHARED_LIBS',
|
|---|
| 66 | 'CROSS_TARGET',
|
|---|
| 67 | 'OPTIMIZATION',
|
|---|
| 68 | 'PROCESSOR',
|
|---|
| 69 | 'QUADFLOAT',
|
|---|
| 70 | 'RDFMT',
|
|---|
| 71 |
|
|---|
| 72 | # Kernel only
|
|---|
| 73 | 'CONFIG_ACPI',
|
|---|
| 74 | 'CONFIG_AM335X_TIMERS',
|
|---|
| 75 | 'CONFIG_ASID',
|
|---|
| 76 | 'CONFIG_ASID_FIFO',
|
|---|
| 77 | 'CONFIG_AT_KBD',
|
|---|
| 78 | 'CONFIG_BCM2835_MAILBOX',
|
|---|
| 79 | 'CONFIG_DSRLNIN',
|
|---|
| 80 | 'CONFIG_DSRLNOUT',
|
|---|
| 81 | 'CONFIG_EGA',
|
|---|
| 82 | 'CONFIG_FB',
|
|---|
| 83 | 'CONFIG_GICV2',
|
|---|
| 84 | 'CONFIG_I8042',
|
|---|
| 85 | 'CONFIG_I8259',
|
|---|
| 86 | 'CONFIG_IOMAP_BITMAP',
|
|---|
| 87 | 'CONFIG_IOMAP_DUMMY',
|
|---|
| 88 | 'CONFIG_KCONSOLE',
|
|---|
| 89 | 'CONFIG_MAC_KBD',
|
|---|
| 90 | 'CONFIG_MULTIBOOT',
|
|---|
| 91 | 'CONFIG_NS16550',
|
|---|
| 92 | 'CONFIG_OFW_PCI',
|
|---|
| 93 | 'CONFIG_OFW_TREE',
|
|---|
| 94 | 'CONFIG_OMAP_UART',
|
|---|
| 95 | 'CONFIG_PAGE_HT',
|
|---|
| 96 | 'CONFIG_PAGE_PT',
|
|---|
| 97 | 'CONFIG_PC_KBD',
|
|---|
| 98 | 'CONFIG_PL011_UART',
|
|---|
| 99 | 'CONFIG_PL050',
|
|---|
| 100 | 'CONFIG_S3C24XX_IRQC',
|
|---|
| 101 | 'CONFIG_S3C24XX_UART',
|
|---|
| 102 | 'CONFIG_SMP',
|
|---|
| 103 | 'CONFIG_SOFTINT',
|
|---|
| 104 | 'CONFIG_SRLN',
|
|---|
| 105 | 'CONFIG_SUN_KBD',
|
|---|
| 106 | 'CONFIG_SYMTAB',
|
|---|
| 107 | 'CONFIG_TEST',
|
|---|
| 108 | 'CONFIG_TRACE',
|
|---|
| 109 | 'CONFIG_TSB',
|
|---|
| 110 | 'CONFIG_UDEBUG',
|
|---|
| 111 | 'CONFIG_VIA_CUDA',
|
|---|
| 112 | 'MACHINE',
|
|---|
| 113 | 'MEMORY_MODEL',
|
|---|
| 114 |
|
|---|
| 115 | 'UARCH',
|
|---|
| 116 | 'KARCH',
|
|---|
| 117 | ]
|
|---|
| 118 |
|
|---|
| 119 | foreach varname : config_variables
|
|---|
| 120 | result = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'Makefile.config')
|
|---|
| 121 | if result.returncode() != 0
|
|---|
| 122 | # TODO: Output negative/inapplicable variables too in config, so that we can check for typos here.
|
|---|
| 123 | #warning('Missing configuration variable ' + varname + ' in Makefile.config')
|
|---|
| 124 | set_variable(varname, false)
|
|---|
| 125 | continue
|
|---|
| 126 | endif
|
|---|
| 127 |
|
|---|
| 128 | value = result.stdout().split('\n')[0].strip().split('=')[1].strip()
|
|---|
| 129 | if value == 'y'
|
|---|
| 130 | value = true
|
|---|
| 131 | elif value == 'n'
|
|---|
| 132 | value = false
|
|---|
| 133 | endif
|
|---|
| 134 |
|
|---|
| 135 | set_variable(varname, value)
|
|---|
| 136 | if debug_options
|
|---|
| 137 | message([ varname, value ])
|
|---|
| 138 | endif
|
|---|
| 139 | endforeach
|
|---|
| 140 |
|
|---|
| 141 | # Also read version information.
|
|---|
| 142 | version_variables = [
|
|---|
| 143 | 'COPYRIGHT',
|
|---|
| 144 | 'NAME',
|
|---|
| 145 | 'PATCHLEVEL',
|
|---|
| 146 | 'SUBLEVEL',
|
|---|
| 147 | 'VERSION',
|
|---|
| 148 | ]
|
|---|
| 149 |
|
|---|
| 150 | foreach varname : version_variables
|
|---|
| 151 | line = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'version', check: true).stdout().strip()
|
|---|
| 152 | value = line.split('=')[1].strip()
|
|---|
| 153 | set_variable('HELENOS_' + varname, value)
|
|---|
| 154 | if debug_options
|
|---|
| 155 | message([ 'HELENOS_' + varname, value ])
|
|---|
| 156 | endif
|
|---|
| 157 | endforeach
|
|---|
| 158 |
|
|---|
| 159 | HELENOS_RELEASE = HELENOS_VERSION + '.' + HELENOS_PATCHLEVEL + '.' + HELENOS_SUBLEVEL
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | meson.add_install_script('install.sh', CONFIG_DEVEL_FILES.to_string())
|
|---|
| 163 |
|
|---|
| 164 | add_project_arguments(
|
|---|
| 165 | # TODO: Remove from project arguments and only use where needed.
|
|---|
| 166 | '-imacros', join_paths(meson.source_root(), 'config.h'),
|
|---|
| 167 | language : [ 'c' ],
|
|---|
| 168 | )
|
|---|
| 169 |
|
|---|
| 170 | add_project_link_arguments(
|
|---|
| 171 | cc.get_supported_link_arguments([
|
|---|
| 172 | '-Wl,--gc-sections',
|
|---|
| 173 | '-Wl,--warn-common',
|
|---|
| 174 | ]),
|
|---|
| 175 | '-Wl,--fatal-warnings',
|
|---|
| 176 | language : [ 'c', 'cpp' ],
|
|---|
| 177 | )
|
|---|
| 178 |
|
|---|
| 179 | # TODO: enable more warnings
|
|---|
| 180 | # FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
|
|---|
| 181 | # We should investigate what's going on there.
|
|---|
| 182 |
|
|---|
| 183 | extra_common_flags = [
|
|---|
| 184 | '-O' + OPTIMIZATION,
|
|---|
| 185 | '-fexec-charset=UTF-8',
|
|---|
| 186 | '-finput-charset=UTF-8',
|
|---|
| 187 |
|
|---|
| 188 | '-D_HELENOS_SOURCE',
|
|---|
| 189 | '-Wa,--fatal-warnings',
|
|---|
| 190 |
|
|---|
| 191 | '-Wall',
|
|---|
| 192 | '-Wextra',
|
|---|
| 193 |
|
|---|
| 194 | '-Werror-implicit-function-declaration',
|
|---|
| 195 |
|
|---|
| 196 | '-Wwrite-strings',
|
|---|
| 197 | '-Wsystem-headers',
|
|---|
| 198 | '-Wunknown-pragmas',
|
|---|
| 199 |
|
|---|
| 200 | '-Wno-unused-parameter',
|
|---|
| 201 |
|
|---|
| 202 | '-pipe',
|
|---|
| 203 | '-ffunction-sections',
|
|---|
| 204 |
|
|---|
| 205 | '-fno-common',
|
|---|
| 206 |
|
|---|
| 207 | '-fdebug-prefix-map=' + meson.source_root() + '=.',
|
|---|
| 208 | ]
|
|---|
| 209 |
|
|---|
| 210 | if UARCH != 'ia64'
|
|---|
| 211 | extra_common_flags += [ '-fvar-tracking-assignments' ]
|
|---|
| 212 | endif
|
|---|
| 213 |
|
|---|
| 214 | if CONFIG_DEBUG
|
|---|
| 215 | extra_common_flags += [ '-Werror' ]
|
|---|
| 216 | endif
|
|---|
| 217 |
|
|---|
| 218 | if CONFIG_LINE_DEBUG
|
|---|
| 219 | extra_common_flags += [ '-gdwarf-4', '-g3' ]
|
|---|
| 220 | endif
|
|---|
| 221 |
|
|---|
| 222 | extra_cflags = extra_common_flags + [
|
|---|
| 223 | '-Wmissing-prototypes',
|
|---|
| 224 |
|
|---|
| 225 | '-Wno-missing-braces',
|
|---|
| 226 | '-Wno-missing-field-initializers',
|
|---|
| 227 | '-Wno-unused-command-line-argument',
|
|---|
| 228 | '-Wno-unused-parameter',
|
|---|
| 229 | '-Wno-typedef-redefinition',
|
|---|
| 230 | '-Wno-clobbered',
|
|---|
| 231 | '-Wno-nonnull-compare',
|
|---|
| 232 |
|
|---|
| 233 | '-fno-builtin-strftime',
|
|---|
| 234 | ]
|
|---|
| 235 |
|
|---|
| 236 | if CONFIG_UBSAN
|
|---|
| 237 | extra_cflags += '-fsanitize=undefined'
|
|---|
| 238 | endif
|
|---|
| 239 |
|
|---|
| 240 | extra_cppflags = extra_common_flags + [
|
|---|
| 241 | '-fno-exceptions',
|
|---|
| 242 | '-frtti',
|
|---|
| 243 | ]
|
|---|
| 244 |
|
|---|
| 245 | w_flags = {
|
|---|
| 246 | 'c': extra_cflags,
|
|---|
| 247 | 'cpp': extra_cppflags,
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | # Process flags. Only sets those that compiler supports.
|
|---|
| 251 | foreach lang : [ 'c', 'cpp' ]
|
|---|
| 252 | extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
|
|---|
| 253 | add_project_arguments(extra_cflags, language : [ lang ])
|
|---|
| 254 | add_project_link_arguments(extra_cflags, language : [ lang ])
|
|---|
| 255 | endforeach
|
|---|
| 256 |
|
|---|
| 257 | # Init binaries.
|
|---|
| 258 | rd_init = [
|
|---|
| 259 | 'app/init',
|
|---|
| 260 | 'srv/bd/rd',
|
|---|
| 261 | 'srv/fs/' + RDFMT,
|
|---|
| 262 | 'srv/loader',
|
|---|
| 263 | 'srv/locsrv',
|
|---|
| 264 | 'srv/logger',
|
|---|
| 265 | 'srv/ns',
|
|---|
| 266 | 'srv/vfs',
|
|---|
| 267 | ]
|
|---|
| 268 |
|
|---|
| 269 | # Binaries allowed on the initrd image when CONFIG_BAREBONE is enabled.
|
|---|
| 270 | rd_essential = rd_init + [
|
|---|
| 271 | 'app/bdsh',
|
|---|
| 272 | 'app/getterm',
|
|---|
| 273 | 'app/kio',
|
|---|
| 274 |
|
|---|
| 275 | 'srv/devman',
|
|---|
| 276 | 'srv/fs/locfs',
|
|---|
| 277 | 'srv/hid/console',
|
|---|
| 278 | 'srv/hid/input',
|
|---|
| 279 | 'srv/hid/output',
|
|---|
| 280 | 'srv/klog',
|
|---|
| 281 |
|
|---|
| 282 | 'drv/root/root',
|
|---|
| 283 | 'drv/root/virt',
|
|---|
| 284 | 'drv/fb/kfb',
|
|---|
| 285 | ]
|
|---|
| 286 |
|
|---|
| 287 | if CONFIG_FB
|
|---|
| 288 | rd_essential += [
|
|---|
| 289 | 'app/vlaunch',
|
|---|
| 290 | 'app/vterm',
|
|---|
| 291 |
|
|---|
| 292 | 'srv/hid/compositor',
|
|---|
| 293 | ]
|
|---|
| 294 | endif
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 | ## The at-sign
|
|---|
| 298 | #
|
|---|
| 299 | # The `atsign` variable holds the ASCII character representing the at-sign
|
|---|
| 300 | # ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
|
|---|
| 301 | # don't use '@' for starting a comment, `atsign` is merely '@'. However, on
|
|---|
| 302 | # those that do use it for starting a comment (e.g. arm32), `atsign` must be
|
|---|
| 303 | # defined as the percentile-sign ('%') in the architecture-dependent files.
|
|---|
| 304 | #
|
|---|
| 305 | atsign = '@'
|
|---|
| 306 |
|
|---|
| 307 | ## Some architectures need a particular string at the beginning of assembly files.
|
|---|
| 308 | kernel_as_prolog = ''
|
|---|
| 309 | uspace_as_prolog = ''
|
|---|
| 310 |
|
|---|
| 311 | subdir('meson' / 'arch' / UARCH)
|
|---|
| 312 |
|
|---|
| 313 | subdir('kernel')
|
|---|
| 314 | subdir('uspace')
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 | ## Generate config.mk
|
|---|
| 318 |
|
|---|
| 319 | # Get the directory where the compiler resides.
|
|---|
| 320 |
|
|---|
| 321 | cc_fullname = run_command(which, meson.get_compiler('c').cmd_array()[0].split(' ')[0], check: true).stdout().strip()
|
|---|
| 322 | cc_path = run_command(dirname, cc_fullname, check: true).stdout().strip()
|
|---|
| 323 |
|
|---|
| 324 | message(['Compiler directory is:', cc_path])
|
|---|
| 325 |
|
|---|
| 326 | export_cppflags = [
|
|---|
| 327 | '-isystem', '$(HELENOS_EXPORT_ROOT)/include/posix',
|
|---|
| 328 | '-isystem', '$(HELENOS_EXPORT_ROOT)/include/libc',
|
|---|
| 329 | '-idirafter', '$(HELENOS_EXPORT_ROOT)/include',
|
|---|
| 330 | ]
|
|---|
| 331 |
|
|---|
| 332 | export_ldflags = [
|
|---|
| 333 | '-nostdlib',
|
|---|
| 334 | '-L$(HELENOS_EXPORT_ROOT)/lib',
|
|---|
| 335 | '-Wl,--whole-archive',
|
|---|
| 336 | '$(HELENOS_EXPORT_ROOT)/lib/libstartfiles.a',
|
|---|
| 337 | '-Wl,--no-whole-archive',
|
|---|
| 338 | ]
|
|---|
| 339 |
|
|---|
| 340 | export_ldlibs = [
|
|---|
| 341 | '-Wl,--as-needed',
|
|---|
| 342 | '-lposix',
|
|---|
| 343 | '-lmath',
|
|---|
| 344 | '-lc',
|
|---|
| 345 | '-lgcc',
|
|---|
| 346 | '-Wl,--no-as-needed',
|
|---|
| 347 | ]
|
|---|
| 348 |
|
|---|
| 349 | cc_arch = meson.get_cross_property('cc_arch')
|
|---|
| 350 |
|
|---|
| 351 | conf_data = configuration_data({
|
|---|
| 352 | 'HELENOS_CROSS_PATH' : cc_path,
|
|---|
| 353 | 'HELENOS_ARCH' : cc_arch,
|
|---|
| 354 | 'HELENOS_CFLAGS' : ' '.join(arch_uspace_c_args),
|
|---|
| 355 | 'HELENOS_CXXFLAGS' : ' '.join(arch_uspace_c_args),
|
|---|
| 356 | 'HELENOS_CPPFLAGS' : ' '.join(export_cppflags),
|
|---|
| 357 | 'HELENOS_LDFLAGS' : ' '.join(export_ldflags),
|
|---|
| 358 | 'HELENOS_LDLIBS' : ' '.join(export_ldlibs),
|
|---|
| 359 | 'HELENOS_TARGET' : cc_arch + '-helenos',
|
|---|
| 360 | })
|
|---|
| 361 |
|
|---|
| 362 | config_mk = configure_file(
|
|---|
| 363 | input: 'config.mk.in',
|
|---|
| 364 | output: 'config.mk',
|
|---|
| 365 | configuration: conf_data,
|
|---|
| 366 | install: true,
|
|---|
| 367 | install_dir: 'config',
|
|---|
| 368 | )
|
|---|
| 369 |
|
|---|
| 370 | custom_target('config.sh',
|
|---|
| 371 | input: config_mk,
|
|---|
| 372 | output: 'config.sh',
|
|---|
| 373 | command: [ sed, 's:$(HELENOS_EXPORT_ROOT):${HELENOS_EXPORT_ROOT}:g', '@INPUT@' ],
|
|---|
| 374 | capture: true,
|
|---|
| 375 | install: true,
|
|---|
| 376 | install_dir: 'config',
|
|---|
| 377 | )
|
|---|
| 378 |
|
|---|
| 379 | install_data('Makefile.common', 'Makefile.config', install_dir: 'config')
|
|---|