Changeset 200b211 in mainline


Ignore:
Timestamp:
2019-08-17T12:49:44Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eb9c598
Parents:
5139663
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-07-15 14:47:53)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-08-17 12:49:44)
Message:

Reorganize main meson.build script

I split most of it into separate subdirs, so that the overall organization
is easier to follow.

Files:
7 added
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • meson.build

    r5139663 r200b211  
    1414debug_shell_scripts = false
    1515
    16 if not meson.is_cross_build()
    17         subdir('doxygen')
    18         subdir_done()
    19 endif
    20 
    21 cc = meson.get_compiler('c')
    22 basename = find_program('basename')
    23 cp = find_program('cp')
    24 dirname = find_program('dirname')
    25 find = find_program('find')
    26 grep = find_program('grep')
    27 mkarray = find_program('tools/mkarray_for_meson.sh')
    28 mkext4 = find_program('tools/mkext4.py')
    29 mkfat = find_program('tools/mkfat.py')
    30 mkuimage = find_program('tools/mkuimage.py')
    31 config_py = find_program('tools/config.py')
    32 objcopy = find_program('objcopy')
    33 objdump = find_program('objdump')
    34 sed = find_program('sed')
    35 unzip = find_program('unzip')
    36 which = find_program('which')
    37 
    38 sh = [ find_program('sh'), '-u', '-e' ]
    39 if debug_shell_scripts
    40         sh += '-x'
    41 endif
    42 
    43 genisoimage = find_program('genisoimage', required: false)
    44 
    45 if not genisoimage.found()
    46         genisoimage = find_program('mkisofs', required: false)
    47 endif
    48 
    49 if not genisoimage.found()
    50         xorriso = find_program('xorriso', required: false)
    51 
    52         if xorriso.found()
    53                 genisoimage = [ xorriso, '-as', 'genisoimage' ]
    54         else
    55                 error('Need genisoimage, mkisofs or xorriso.')
    56         endif
    57 endif
    58 
    59 
    60 autocheck = generator(find_program('tools/autocheck.awk'),
    61         arguments: [ '@INPUT@' ],
    62         output: '@PLAINNAME@.check.c',
    63         capture: true,
    64 )
    65 
    66 # TODO: bug in Meson
    67 #gzip = generator(find_program('gzip'),
    68 #       arguments: [ '--no-name', '-9', '--stdout', '@INPUT@' ],
    69 #       output: '@PLAINNAME@.gz',
    70 #       capture: true,
    71 #)
    72 
    73 gzip = [ find_program('gzip'), '--no-name', '-9', '--stdout', '@INPUT@' ]
    74 
    75 # Tar's arguments make sure that the archive is reproducible.
    76 tar = [
    77         find_program('tar'),
    78         '-c',
    79         '-f', '@OUTPUT@',
    80         '--mtime=1970-01-01 00:00:00Z',
    81         '--group=0',
    82         '--owner=0',
    83         '--numeric-owner',
    84         '--mode=go=rX,u+rw,a-s',
    85         '--no-acls',
    86         '--no-selinux',
    87         '--no-xattrs',
    88         '--format=ustar',
    89         '--transform', 's:@OUTDIR@/::',
    90         '@INPUT@',
    91 ]
    92 
    93 # Output compiler flags for use by third-party builds.
    94 # NOTE: See $srcroot/meson/cross/$arch for architecture-specific compiler flags.
    95 
    96 if debug_options
    97         message('Cross c_args:')
    98         message(meson.get_cross_property('c_args'))
    99         message('Cross cpp_args:')
    100         message(meson.get_cross_property('cpp_args'))
    101         message('Cross c_link_args:')
    102         message(meson.get_cross_property('c_link_args'))
    103         message('Cross cpp_link_args:')
    104         message(meson.get_cross_property('cpp_link_args'))
    105 endif
    106 
    107 # Read some variables from Makefile.common
    108 config_variables = [
    109         # Uspace and kernel
    110         'CONFIG_BAREBONE',
    111         'CONFIG_BUILD_SHARED_LIBS',
    112         'CONFIG_DEBUG',
    113         'CONFIG_DEVEL_FILES',
    114         'CONFIG_FPU',
    115         'CONFIG_LINE_DEBUG',
    116         'CONFIG_LTO',
    117         'CONFIG_PCUT_SELF_TESTS',
    118         'CONFIG_PCUT_TESTS',
    119         'CONFIG_RTLD',
    120         'CONFIG_STRIP_BINARIES',
    121         'CONFIG_UBSAN',
    122         'CONFIG_USE_SHARED_LIBS',
    123         'CROSS_TARGET',
    124         'OPTIMIZATION',
    125         'PROCESSOR',
    126         'QUADFLOAT',
    127         'RDFMT',
    128 
    129         # Kernel only
    130         'CONFIG_ACPI',
    131         'CONFIG_AM335X_TIMERS',
    132         'CONFIG_ASID',
    133         'CONFIG_ASID_FIFO',
    134         'CONFIG_AT_KBD',
    135         'CONFIG_BCM2835_MAILBOX',
    136         'CONFIG_DSRLNIN',
    137         'CONFIG_DSRLNOUT',
    138         'CONFIG_EGA',
    139         'CONFIG_FB',
    140         'CONFIG_GICV2',
    141         'CONFIG_I8042',
    142         'CONFIG_I8259',
    143         'CONFIG_IOMAP_BITMAP',
    144         'CONFIG_IOMAP_DUMMY',
    145         'CONFIG_KCONSOLE',
    146         'CONFIG_MAC_KBD',
    147         'CONFIG_MULTIBOOT',
    148         'CONFIG_NS16550',
    149         'CONFIG_OFW_PCI',
    150         'CONFIG_OFW_TREE',
    151         'CONFIG_OMAP_UART',
    152         'CONFIG_PAGE_HT',
    153         'CONFIG_PAGE_PT',
    154         'CONFIG_PC_KBD',
    155         'CONFIG_PL011_UART',
    156         'CONFIG_PL050',
    157         'CONFIG_S3C24XX_IRQC',
    158         'CONFIG_S3C24XX_UART',
    159         'CONFIG_SMP',
    160         'CONFIG_SOFTINT',
    161         'CONFIG_SRLN',
    162         'CONFIG_SUN_KBD',
    163         'CONFIG_SYMTAB',
    164         'CONFIG_TEST',
    165         'CONFIG_TRACE',
    166         'CONFIG_TSB',
    167         'CONFIG_UDEBUG',
    168         'CONFIG_VIA_CUDA',
    169         'MACHINE',
    170         'MEMORY_MODEL',
    171 
    172         'UARCH',
    173         'KARCH',
    174         'BARCH',
    175         'GRUB_ARCH',
    176         'UIMAGE_OS',
    177         'CONFIG_COMPRESSED_INIT',
    178 ]
    179 
    180 CONFIG_MAKEFILE = files(meson.build_root() / 'Makefile.config')
    181 
    182 foreach varname : config_variables
    183         result = run_command(grep, '^' + varname + '\\b', CONFIG_MAKEFILE)
    184         if result.returncode() != 0
    185                 # TODO: Output negative/inapplicable variables too in config, so that we can check for typos here.
    186                 #warning('Missing configuration variable ' + varname + ' in Makefile.config')
    187                 set_variable(varname, false)
    188                 continue
    189         endif
    190 
    191         value = result.stdout().split('\n')[0].strip().split('=')[1].strip()
    192         if value == 'y'
    193                 value = true
    194         elif value == 'n'
    195                 value = false
    196         endif
    197 
    198         set_variable(varname, value)
    199         if debug_options
    200                 message([ varname, value ])
    201         endif
    202 endforeach
    203 
    204 # Also read version information.
    205 version_variables = [
    206         'COPYRIGHT',
    207         'NAME',
    208         'PATCHLEVEL',
    209         'SUBLEVEL',
    210         'VERSION',
    211 ]
    212 
    213 foreach varname : version_variables
    214         line = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'version', check: true).stdout().strip()
    215         value = line.split('=')[1].strip()
    216         set_variable('HELENOS_' + varname, value)
    217         if debug_options
    218                 message([ 'HELENOS_' + varname, value ])
    219         endif
    220 endforeach
    221 
    222 HELENOS_RELEASE = HELENOS_VERSION + '.' + HELENOS_PATCHLEVEL + '.' + HELENOS_SUBLEVEL
    223 
    224 add_project_arguments(
    225         # TODO: Remove from project arguments and only use where necessary.
    226         # Any change in config forces everything to rebuild due to lack of granularity here.
    227         '-imacros', meson.build_root() / 'config.h',
    228         language : [ 'c' ],
    229 )
    230 
    231 add_project_link_arguments(
    232         cc.get_supported_link_arguments([
    233                 '-Wl,--gc-sections',
    234                 '-Wl,--warn-common',
    235         ]),
    236         '-Wl,--fatal-warnings',
    237         language : [ 'c', 'cpp' ],
    238 )
    239 
    240 # TODO: enable more warnings
    241 # FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
    242 # We should investigate what's going on there.
    243 
    244 extra_common_flags = [
    245         '-O' + OPTIMIZATION,
    246         '-fexec-charset=UTF-8',
    247         '-finput-charset=UTF-8',
    248 
    249         '-D_HELENOS_SOURCE',
    250 
    251         '-Wa,--fatal-warnings',
    252 
    253         '-Wall',
    254         '-Wextra',
    255         '-Werror-implicit-function-declaration',
    256         '-Wwrite-strings',
    257         '-Wunknown-pragmas',
    258 
    259         '-Wno-unused-parameter',
    260 
    261         '-pipe',
    262 
    263         '-ffunction-sections',
    264         '-fno-common',
    265         '-fdebug-prefix-map=' + meson.source_root() + '=.',
    266 ]
    267 
    268 if cc.get_id() != 'clang'
    269         # Clang's own headers emit macro redefinition warnings.
    270         extra_common_flags += '-Wsystem-headers'
    271 endif
    272 
    273 if UARCH != 'ia64'
    274         extra_common_flags += [ '-fvar-tracking-assignments' ]
    275 endif
    276 
    277 if CONFIG_DEBUG
    278         extra_common_flags += [ '-Werror' ]
    279 endif
    280 
    281 if CONFIG_LINE_DEBUG
    282         extra_common_flags += [ '-gdwarf-4', '-g3' ]
    283 endif
    284 
    285 extra_cflags = extra_common_flags + [
    286         '-Wmissing-prototypes',
    287 
    288         '-Wno-missing-braces',
    289         '-Wno-missing-field-initializers',
    290         '-Wno-unused-command-line-argument',
    291         '-Wno-unused-parameter',
    292         '-Wno-typedef-redefinition',
    293         '-Wno-clobbered',
    294         '-Wno-nonnull-compare',
    295 
    296         '-fno-builtin-strftime',
    297 ]
    298 
    299 if CONFIG_UBSAN
    300         extra_cflags += '-fsanitize=undefined'
    301 endif
    302 
    303 extra_cppflags = extra_common_flags + [
    304         '-fno-exceptions',
    305         '-frtti',
    306 ]
    307 
    308 w_flags = {
    309         'c': extra_cflags,
    310         'cpp': extra_cppflags,
    311 }
    312 
    313 # Process flags. Only sets those that compiler supports.
    314 foreach lang : [ 'c', 'cpp' ]
    315         extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
    316         add_project_arguments(extra_cflags, language : [ lang ])
    317         add_project_link_arguments(extra_cflags, language : [ lang ])
    318 endforeach
    319 
    320 # Init binaries.
    321 rd_init = [
    322         # IMPORTANT: The order of entries is important for bootloader!
    323         'srv/ns',
    324         'srv/loader',
    325         'app/init',
    326         'srv/locsrv',
    327         'srv/bd/rd',
    328         'srv/vfs',
    329         'srv/logger',
    330         'srv/fs/' + RDFMT,
    331 ]
    332 
    333 # References to the actual binary files. Filled in by uspace.
    334 rd_init_binaries = []
    335 
    336 # Binaries allowed on the initrd image when CONFIG_BAREBONE is enabled.
    337 rd_essential = [
    338         'app/bdsh',
    339         'app/getterm',
    340         'app/kio',
    341 
    342         'srv/devman',
    343         'srv/fs/locfs',
    344         'srv/hid/console',
    345         'srv/hid/input',
    346         'srv/hid/output',
    347         'srv/klog',
    348 
    349         'drv/root/root',
    350         'drv/root/virt',
    351         'drv/fb/kfb',
    352 ]
    353 
    354 if CONFIG_FB
    355         rd_essential += [
    356                 'app/vlaunch',
    357                 'app/vterm',
    358 
    359                 'srv/hid/compositor',
    360         ]
    361 endif
    362 
     16subdir('doxygen')
     17subdir('meson/part/tools')
     18subdir('meson/part/read_config')
     19subdir('meson/part/compiler_args')
     20subdir('meson/part/initrd_manifest')
     21subdir('meson' / 'arch' / UARCH)
    36322
    36423## The at-sign
     
    37029# defined as the percentile-sign ('%') in the architecture-dependent files.
    37130#
    372 atsign = '@'
     31if not is_variable('atsign')
     32        atsign = '@'
     33endif
    37334
    37435## Some architectures need a particular string at the beginning of assembly files.
    375 kernel_as_prolog = ''
    376 uspace_as_prolog = ''
     36if not is_variable('kernel_as_prolog')
     37        kernel_as_prolog = ''
     38endif
     39if not is_variable('uspace_as_prolog')
     40        uspace_as_prolog = ''
     41endif
    37742
    378 subdir('meson' / 'arch' / UARCH)
     43# The following variables are filled in by code in the kernel and uspace subdirs.
    37944
     45# References to the actual binary artefacts that will be part of initrd image.
     46rd_init_binaries = []
     47# Installed files.
    38048install_files = []
    38149install_deps = []
     50# Install script for headers.
     51# TODO: Make a list of directories and turn into script later.
     52uspace_lib_install_script_text = []
    38253
    38354subdir('kernel')
    38455subdir('uspace')
    38556
    386 
    387 ## Generate config.mk
    388 
    389 # Get the directory where the compiler resides.
    390 
    391 cc_fullname = run_command(which, meson.get_compiler('c').cmd_array()[0].split(' ')[0], check: true).stdout().strip()
    392 cc_path = run_command(dirname, cc_fullname, check: true).stdout().strip()
    393 
    394 message(['Compiler directory is:', cc_path])
    395 
    396 export_cppflags = [
    397         '-isystem', '$(HELENOS_EXPORT_ROOT)/include/posix',
    398         '-isystem', '$(HELENOS_EXPORT_ROOT)/include/libc',
    399         '-idirafter', '$(HELENOS_EXPORT_ROOT)/include',
    400 ]
    401 
    402 export_ldflags = [
    403         '-nostdlib',
    404         '-L$(HELENOS_EXPORT_ROOT)/lib',
    405         '-Wl,--whole-archive',
    406         '$(HELENOS_EXPORT_ROOT)/lib/libstartfiles.a',
    407         '-Wl,--no-whole-archive',
    408 ]
    409 
    410 export_ldlibs = [
    411         '-Wl,--as-needed',
    412         '-lposix',
    413         '-lmath',
    414         '-lc',
    415         '-lgcc',
    416         '-Wl,--no-as-needed',
    417 ]
    418 
    419 cc_arch = meson.get_cross_property('cc_arch')
    420 
    421 conf_data = configuration_data({
    422         'HELENOS_CROSS_PATH' : cc_path,
    423         'HELENOS_ARCH' : cc_arch,
    424         'HELENOS_CFLAGS' : ' '.join(arch_uspace_c_args),
    425         'HELENOS_CXXFLAGS' : ' '.join(arch_uspace_c_args),
    426         'HELENOS_CPPFLAGS' : ' '.join(export_cppflags),
    427         'HELENOS_LDFLAGS' : ' '.join(export_ldflags),
    428         'HELENOS_LDLIBS' : ' '.join(export_ldlibs),
    429         'HELENOS_TARGET' : cc_arch + '-helenos',
    430 })
    431 
    432 config_mk = configure_file(
    433         input: 'config.mk.in',
    434         output: 'config.mk',
    435         configuration: conf_data,
    436 )
    437 
    438 config_sh = custom_target('config.sh',
    439         input: config_mk,
    440         output: 'config.sh',
    441         command: [ sed, 's:$(HELENOS_EXPORT_ROOT):${HELENOS_EXPORT_ROOT}:g', '@INPUT@' ],
    442         capture: true,
    443 )
    444 
    445 install_files += [[ 'config', meson.current_build_dir() / 'config.mk', 'config.mk' ]]
    446 install_deps += [ config_mk ]
    447 install_files += [[ 'config', meson.current_build_dir() / 'config.sh', 'config.sh' ]]
    448 install_deps += [ config_sh ]
    449 
    450 # TODO: remove
    451 install_files += [[ 'config', meson.build_root() / 'Makefile.config', 'Makefile.config' ]]
    452 install_deps += CONFIG_MAKEFILE
    453 
    454 if CONFIG_DEVEL_FILES
    455         # Also install libgcc.
    456         # We have to explicitly use gcc for this, because clang only prints
    457         # file name instead of whole path.
    458         libgcc = run_command(cc_arch + '-helenos-gcc',
    459                 arch_uspace_c_args, '-print-libgcc-file-name',
    460                 check: true,
    461         ).stdout().strip()
    462 
    463         install_files += [[ 'lib', libgcc, 'libgcc.a' ]]
    464         install_deps += [ files(libgcc) ]
    465 endif
    466 
    467 
    468 # Emit the install script.
    469 
    470 install_script_text = []
    471 
    472 # Copy uspace/dist.
    473 _uspace = meson.current_source_dir() / 'uspace'
    474 install_script_text += 'cp -r -L -T -u "@0@/dist" "${DESTDIR}"'.format(_uspace)
    475 
    476 # Copy uspace/overlay
    477 install_script_text += 'if ls @0@/overlay/* >/dev/null 2>/dev/null; then'.format(_uspace)
    478 install_script_text += 'cp -r -L @0@/overlay/* "${DESTDIR}"'.format(_uspace)
    479 install_script_text += 'fi'
    480 
    481 
    482 foreach f : install_files
    483         _cmd = 'mkdir -p "${DESTDIR}@0@" && cp -L -T "@1@" "${DESTDIR}@0@/@2@"'
    484         install_script_text += _cmd.format(f[0], f[1], f[2])
    485 endforeach
    486 
    487 install_script_text += uspace_lib_install_script_text
    488 
    489 install_script = configure_file(
    490         configuration: { 'text' : '\n'.join(install_script_text) },
    491         input: 'install.sh.in',
    492         output: 'install.sh',
    493 )
    494 
    495 # Build up dist
    496 
    497 dist_dir = meson.current_build_dir()/'dist/'
    498 
    499 dist = custom_target('DIST',
    500         output: 'dist.tag',
    501         input: [ install_script, install_deps ],
    502         command: [ sh, '@INPUT0@', '@OUTPUT@', dist_dir ],
    503 )
    504 
    505 # Build initrd image
    506 
    507 if RDFMT == 'tmpfs'
    508         initrd_cmd = [ 'tar', '-c', '-f', '@OUTPUT@', '-C', dist_dir, '.' ]
    509 elif RDFMT == 'fat'
    510         initrd_cmd = [ mkfat, '1048576', dist_dir, '@OUTPUT@' ]
    511 elif RDFMT == 'ext4fs'
    512         initrd_cmd = [ mkext4, '1048576', dist_dir, '@OUTPUT@' ]
    513 else
    514         error('Unknown RDFMT: ' + RDFMT)
    515 endif
    516 
    517 initrd_img = custom_target('initrd.img',
    518         output: 'initrd.img',
    519         input: dist,
    520         command: initrd_cmd,
    521 )
    522 
    523 rd_init_binaries += [[ initrd_img, 'boot/initrd.img' ]]
     57subdir('meson/part/exports')
     58subdir('meson/part/initrd')
    52459
    52560subdir('boot')
     61
     62# Copy the final image to the build root,
     63# and write its name to a text file `image_path`.
    52664
    52765if is_variable('POST_INPUT')
     
    54684endif
    54785
    548 run_target('config',
    549         command: [
    550                 sh,
    551                 '-c', 'cd $1 && $2 $3 $4',
    552                 '--',
    553                 meson.build_root(),
    554                 config_py.path(),
    555                 meson.source_root() / 'HelenOS.config',
    556                 meson.source_root() / 'defaults',
    557         ]
    558 )
    559 
    560 # TODO: Check when cross target has changed, since it won't work.
    561 
    562 if false
    563         # TODO: doesn't work because it changes cross target
    564         run_target('random-config',
    565                 command: [
    566                         sh,
    567                         '-c', 'cd $1 && $2 $3 $4 random',
    568                         '--',
    569                         meson.build_root(),
    570                         config_py.path(),
    571                         meson.source_root() / 'HelenOS.config',
    572                         meson.source_root() / 'defaults',
    573                 ]
    574         )
    575 endif
    576 
    577 
    578 # TODO text-xcw
    579 #ifeq ($(CONFIG_DEVEL_FILES),y)
    580 #       export PATH=$$PATH:$(abspath tools/xcw/bin) && $(MAKE) -r -C tools/xcw/demo
    581 #endif
    582 
    583 # TODO special target for posix and xcw exports, update coastline for it
     86subdir('meson/part/extra_targets')
Note: See TracChangeset for help on using the changeset viewer.