Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 1 | project('mosys', 'c') |
| 2 | |
| 3 | # Include common. This is passed to all subdir build files as well |
| 4 | include_common = include_directories(['include']) |
| 5 | |
| 6 | # Config data used for creating a config header and including it |
| 7 | conf_data = configuration_data() |
| 8 | |
| 9 | # Set for all platforms |
| 10 | conf_data.set('PROGRAM', '"mosys"') |
| 11 | conf_data.set('VERSION', '"1.2.03"') |
| 12 | conf_data.set('CONFIG_LITTLE_ENDIAN', 1) |
| 13 | conf_data.set('CONFIG_LOGLEVEL', 4) |
| 14 | conf_data.set('CONFIG_PLATFORM_EXPERIMENTAL', 1) |
Jason D. Clinton | a7fd67d | 2018-04-17 13:34:08 -0600 | [diff] [blame] | 15 | use_cros_config = get_option('use_cros_config') == true |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 16 | if use_cros_config |
| 17 | conf_data.set('CONFIG_CROS_CONFIG', 1) |
| 18 | endif |
| 19 | |
| 20 | # Setting on a per-arch basis |
| 21 | arch = get_option('arch') |
| 22 | if arch == 'x86' or arch == 'x86_64' or arch == 'amd64' |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 23 | conf_data.set('CONFIG_PLATFORM_ARCH_X86', 1) |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 24 | elif arch == 'mip' |
| 25 | conf_data.set('CONFIG_PLATFORM_ARCH_MIPSEL', 1) |
| 26 | elif arch == 'arm' |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 27 | conf_data.set('CONFIG_PLATFORM_ARCH_ARMEL', 1) |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 28 | endif |
| 29 | |
| 30 | # Create the config header file and include it by default while compiling |
| 31 | configure_file( |
| 32 | output : 'config.h', |
| 33 | configuration : conf_data, |
| 34 | ) |
| 35 | add_global_arguments('-include', 'config.h', language: 'c') |
Jason D. Clinton | a7fd67d | 2018-04-17 13:34:08 -0600 | [diff] [blame] | 36 | add_global_arguments('-std=gnu99', language : 'c') |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 37 | |
Brian Norris | e11e08f | 2018-04-30 10:46:48 -0700 | [diff] [blame] | 38 | cc = meson.get_compiler('c') |
| 39 | if (cc.has_argument('-Wno-address-of-packed-member')) |
| 40 | add_global_arguments(['-Wno-address-of-packed-member'], language: 'c') |
| 41 | endif |
Brian Norris | 402d832 | 2018-04-30 14:22:51 -0700 | [diff] [blame^] | 42 | add_global_arguments('-Werror', language : 'c') |
Brian Norris | e11e08f | 2018-04-30 10:46:48 -0700 | [diff] [blame] | 43 | |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 44 | # External libs used by Mosys |
| 45 | fmap_dep = dependency('fmap') |
| 46 | uuid_dep = dependency('uuid') |
| 47 | |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 48 | libmosys_src = files() |
| 49 | |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 50 | # Subdirs with source to link against |
| 51 | subdir('core') |
| 52 | subdir('drivers') |
| 53 | subdir('intf') |
| 54 | subdir('lib') |
| 55 | subdir('platform') |
| 56 | |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 57 | deps = [ |
| 58 | fmap_dep, |
| 59 | uuid_dep, |
| 60 | ] |
| 61 | link_whole = [] |
Jason D. Clinton | a236cdf | 2018-04-22 18:32:02 -0600 | [diff] [blame] | 62 | objects = [] |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 63 | |
| 64 | # Cros config is a special snowflake. |
| 65 | if use_cros_config |
| 66 | libmosys_src += mosys_lib_cros_config_src |
| 67 | fdt_dep = meson.get_compiler('c').find_library('fdt') |
| 68 | deps += fdt_dep |
| 69 | dtb_lib = static_library( |
| 70 | 'cros_config_dtb', |
| 71 | cros_config_dtb_src, |
| 72 | c_args: [ |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 73 | '-D__ASSEMBLY__', |
| 74 | '-c', |
| 75 | ], |
| 76 | link_args: [ |
| 77 | '-znoexecstack', |
| 78 | '-r', |
| 79 | ], |
| 80 | ) |
| 81 | link_whole += dtb_lib |
Jason D. Clinton | a236cdf | 2018-04-22 18:32:02 -0600 | [diff] [blame] | 82 | objects = dtb_lib.extract_all_objects() |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 83 | endif |
| 84 | |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 85 | # Lib momsys shared library target |
| 86 | libmosys = static_library( |
| 87 | 'mosys', |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 88 | libmosys_src, |
| 89 | dependencies: deps, |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 90 | include_directories: include_common, |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 91 | link_whole: link_whole, |
Jason D. Clinton | a236cdf | 2018-04-22 18:32:02 -0600 | [diff] [blame] | 92 | objects: objects, |
Jason D. Clinton | 3a2b39c | 2018-04-16 11:42:49 -0600 | [diff] [blame] | 93 | pic: true, |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 94 | ) |
| 95 | |
| 96 | # Add static linking if static is set |
| 97 | link_args = [] |
Jason D. Clinton | a7fd67d | 2018-04-17 13:34:08 -0600 | [diff] [blame] | 98 | if get_option('static') == true |
Alec Thilenius | f79f52b | 2017-12-22 12:10:17 -0700 | [diff] [blame] | 99 | link_args += '-static' |
| 100 | endif |
| 101 | |
| 102 | # Mosys dynamic executable |
| 103 | executable( |
| 104 | 'mosys', |
| 105 | ['mosys.c'], |
| 106 | include_directories: include_common, |
| 107 | link_args: link_args, |
| 108 | link_with: [libmosys], |
| 109 | install: true, |
| 110 | install_dir: '/usr/sbin', |
| 111 | ) |
| 112 | |
| 113 | # Mosys static executable. This will be removed by the ebuild if static is not |
| 114 | # set, but is always built and installed first. |
| 115 | executable( |
| 116 | 'mosys_s', |
| 117 | ['mosys.c'], |
| 118 | include_directories: include_common, |
| 119 | link_args: ['-static'], |
| 120 | link_with: [libmosys], |
| 121 | install: true, |
| 122 | install_dir: '/usr/sbin', |
| 123 | ) |