| 1 | # | 
|---|
| 2 | # Copyright (c) 2019 Jiří Zárevúcky | 
|---|
| 3 | # All rights reserved. | 
|---|
| 4 | # | 
|---|
| 5 | # Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | # modification, are permitted provided that the following conditions | 
|---|
| 7 | # are met: | 
|---|
| 8 | # | 
|---|
| 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. | 
|---|
| 16 | # | 
|---|
| 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. | 
|---|
| 27 | # | 
|---|
| 28 |  | 
|---|
| 29 | # Read variables from config file generated by config.py, | 
|---|
| 30 | # and version information from repository. | 
|---|
| 31 |  | 
|---|
| 32 | # Workaround for current Meson (0.51.1) not producing dependency | 
|---|
| 33 | # on files outside source dir when just files() is used. | 
|---|
| 34 | _config_file = configure_file( | 
|---|
| 35 | input: meson.build_root() / 'Makefile.config', | 
|---|
| 36 | output: 'Makefile.config', | 
|---|
| 37 | copy: true, | 
|---|
| 38 | ) | 
|---|
| 39 |  | 
|---|
| 40 | _version_file = files(meson.source_root() / 'version') | 
|---|
| 41 |  | 
|---|
| 42 | _config_variables = [ | 
|---|
| 43 | # Uspace and kernel | 
|---|
| 44 | 'CONFIG_BAREBONE', | 
|---|
| 45 | 'CONFIG_BUILD_SHARED_LIBS', | 
|---|
| 46 | 'CONFIG_DEBUG', | 
|---|
| 47 | 'CONFIG_DEVEL_FILES', | 
|---|
| 48 | 'CONFIG_FPU', | 
|---|
| 49 | 'CONFIG_LINE_DEBUG', | 
|---|
| 50 | 'CONFIG_LTO', | 
|---|
| 51 | 'CONFIG_PCUT_SELF_TESTS', | 
|---|
| 52 | 'CONFIG_PCUT_TESTS', | 
|---|
| 53 | 'CONFIG_RTLD', | 
|---|
| 54 | 'CONFIG_STRIP_BINARIES', | 
|---|
| 55 | 'CONFIG_UBSAN', | 
|---|
| 56 | 'CONFIG_USE_SHARED_LIBS', | 
|---|
| 57 | 'CROSS_TARGET', | 
|---|
| 58 | 'MACHINE', | 
|---|
| 59 | 'OPTIMIZATION', | 
|---|
| 60 | 'PLATFORM', | 
|---|
| 61 | 'PROCESSOR', | 
|---|
| 62 | 'QUADFLOAT', | 
|---|
| 63 | 'RDFMT', | 
|---|
| 64 |  | 
|---|
| 65 | # Kernel only | 
|---|
| 66 | 'CONFIG_ACPI', | 
|---|
| 67 | 'CONFIG_AM335X_TIMERS', | 
|---|
| 68 | 'CONFIG_ASID', | 
|---|
| 69 | 'CONFIG_ASID_FIFO', | 
|---|
| 70 | 'CONFIG_AT_KBD', | 
|---|
| 71 | 'CONFIG_BCM2835_MAILBOX', | 
|---|
| 72 | 'CONFIG_DSRLNIN', | 
|---|
| 73 | 'CONFIG_DSRLNOUT', | 
|---|
| 74 | 'CONFIG_EGA', | 
|---|
| 75 | 'CONFIG_FB', | 
|---|
| 76 | 'CONFIG_GICV2', | 
|---|
| 77 | 'CONFIG_I8042', | 
|---|
| 78 | 'CONFIG_I8259', | 
|---|
| 79 | 'CONFIG_IOMAP_BITMAP', | 
|---|
| 80 | 'CONFIG_IOMAP_DUMMY', | 
|---|
| 81 | 'CONFIG_KCONSOLE', | 
|---|
| 82 | 'CONFIG_MAC_KBD', | 
|---|
| 83 | 'CONFIG_MULTIBOOT', | 
|---|
| 84 | 'CONFIG_NS16550', | 
|---|
| 85 | 'CONFIG_OFW_PCI', | 
|---|
| 86 | 'CONFIG_OFW_TREE', | 
|---|
| 87 | 'CONFIG_OMAP_UART', | 
|---|
| 88 | 'CONFIG_PAGE_HT', | 
|---|
| 89 | 'CONFIG_PAGE_PT', | 
|---|
| 90 | 'CONFIG_PC_KBD', | 
|---|
| 91 | 'CONFIG_PL011_UART', | 
|---|
| 92 | 'CONFIG_PL050', | 
|---|
| 93 | 'CONFIG_S3C24XX_IRQC', | 
|---|
| 94 | 'CONFIG_S3C24XX_UART', | 
|---|
| 95 | 'CONFIG_SMP', | 
|---|
| 96 | 'CONFIG_SOFTINT', | 
|---|
| 97 | 'CONFIG_SRLN', | 
|---|
| 98 | 'CONFIG_SUN_KBD', | 
|---|
| 99 | 'CONFIG_SYMTAB', | 
|---|
| 100 | 'CONFIG_TEST', | 
|---|
| 101 | 'CONFIG_TRACE', | 
|---|
| 102 | 'CONFIG_TSB', | 
|---|
| 103 | 'CONFIG_UDEBUG', | 
|---|
| 104 | 'CONFIG_VIA_CUDA', | 
|---|
| 105 | 'MEMORY_MODEL', | 
|---|
| 106 |  | 
|---|
| 107 | 'UARCH', | 
|---|
| 108 | 'KARCH', | 
|---|
| 109 | 'BARCH', | 
|---|
| 110 | 'GRUB_ARCH', | 
|---|
| 111 | 'UIMAGE_OS', | 
|---|
| 112 | 'CONFIG_COMPRESSED_INIT', | 
|---|
| 113 | ] | 
|---|
| 114 |  | 
|---|
| 115 | foreach _varname : _config_variables | 
|---|
| 116 | _c = run_command(grep, '^' + _varname + '\\b', _config_file) | 
|---|
| 117 | if _c.returncode() != 0 | 
|---|
| 118 | # TODO: Output negative/inapplicable variables too in config, so that we can check for typos here. | 
|---|
| 119 | #warning('Missing configuration variable ' + _varname + ' in Makefile.config') | 
|---|
| 120 | set_variable(_varname, false) | 
|---|
| 121 | continue | 
|---|
| 122 | endif | 
|---|
| 123 |  | 
|---|
| 124 | _val = _c.stdout().split('\n')[0].strip().split('=')[1].strip() | 
|---|
| 125 | if _val == 'y' | 
|---|
| 126 | _val = true | 
|---|
| 127 | elif _val == 'n' | 
|---|
| 128 | _val = false | 
|---|
| 129 | endif | 
|---|
| 130 |  | 
|---|
| 131 | set_variable(_varname, _val) | 
|---|
| 132 | if debug_options | 
|---|
| 133 | message([ _varname, get_variable(_varname) ]) | 
|---|
| 134 | endif | 
|---|
| 135 | endforeach | 
|---|
| 136 |  | 
|---|
| 137 | # Also read version information. | 
|---|
| 138 | _version_variables = [ | 
|---|
| 139 | 'HELENOS_COPYRIGHT', | 
|---|
| 140 | 'HELENOS_CODENAME', | 
|---|
| 141 | 'HELENOS_RELEASE', | 
|---|
| 142 | ] | 
|---|
| 143 |  | 
|---|
| 144 | foreach _varname : _version_variables | 
|---|
| 145 | _line = run_command(grep, '^' + _varname + '\\b', _version_file, check: true).stdout().strip() | 
|---|
| 146 | _val = _line.split('=')[1].strip() | 
|---|
| 147 |  | 
|---|
| 148 | set_variable(_varname, _val) | 
|---|
| 149 | if debug_options | 
|---|
| 150 | message([ _varname, get_variable(_varname) ]) | 
|---|
| 151 | endif | 
|---|
| 152 | endforeach | 
|---|
| 153 |  | 
|---|
| 154 | # Check whether PLATFORM/MACHINE is unchanged | 
|---|
| 155 |  | 
|---|
| 156 | _profile = '@0@/@1@'.format(PLATFORM, MACHINE) | 
|---|
| 157 | _profile_file = meson.build_root() / 'prev_profile' | 
|---|
| 158 |  | 
|---|
| 159 | _cmd = run_command('cat', _profile_file) | 
|---|
| 160 | if _cmd.returncode() == 0 | 
|---|
| 161 | _prev_profile = _cmd.stdout().strip() | 
|---|
| 162 |  | 
|---|
| 163 | if _prev_profile != _profile | 
|---|
| 164 | error('This build directory was initially configured for ' + _prev_profile + | 
|---|
| 165 | ', but now is configured for ' + _profile + '. This is not supported.') | 
|---|
| 166 | endif | 
|---|
| 167 | else | 
|---|
| 168 | run_command('sh', '-c', 'echo "' + _profile + '" > ' + _profile_file, check: true) | 
|---|
| 169 | endif | 
|---|