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 | # This file sets the architecture-independent compiler flags used throughout
|
---|
30 | # this repository.
|
---|
31 | # For architecture-specific flags, see $srcroot/meson/cross/$arch.
|
---|
32 |
|
---|
33 | add_project_arguments(
|
---|
34 | # TODO: Remove from project arguments and only use where necessary.
|
---|
35 | # Any change in config forces everything to rebuild due to lack of granularity here.
|
---|
36 | '-imacros', meson.build_root() / 'config.h',
|
---|
37 | language : [ 'c' ],
|
---|
38 | )
|
---|
39 |
|
---|
40 | add_project_link_arguments(
|
---|
41 | '-Wl,--gc-sections',
|
---|
42 | '-Wl,--warn-common',
|
---|
43 | '-Wl,--fatal-warnings',
|
---|
44 | '-Wl,-z,text',
|
---|
45 | language : [ 'c', 'cpp' ],
|
---|
46 | )
|
---|
47 |
|
---|
48 | # TODO: enable more warnings
|
---|
49 | # FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
|
---|
50 | # We should investigate what's going on there.
|
---|
51 |
|
---|
52 | extra_common_flags = [
|
---|
53 | '-O' + OPTIMIZATION,
|
---|
54 | '-fexec-charset=UTF-8',
|
---|
55 | '-finput-charset=UTF-8',
|
---|
56 |
|
---|
57 | '-D_HELENOS_SOURCE',
|
---|
58 |
|
---|
59 | '-Wa,--fatal-warnings',
|
---|
60 | '-Wl,-z,text',
|
---|
61 |
|
---|
62 | '-Wall',
|
---|
63 | '-Wextra',
|
---|
64 | '-Wwrite-strings',
|
---|
65 | '-Wunknown-pragmas',
|
---|
66 |
|
---|
67 | '-Wno-unused-parameter',
|
---|
68 |
|
---|
69 | '-pipe',
|
---|
70 |
|
---|
71 | '-ffunction-sections',
|
---|
72 | '-fdata-sections',
|
---|
73 | '-fno-common',
|
---|
74 | '-fdebug-prefix-map=' + meson.source_root() + '/=',
|
---|
75 | '-fdebug-prefix-map=../../=',
|
---|
76 | ]
|
---|
77 |
|
---|
78 | if cc.get_id() != 'clang'
|
---|
79 | # Clang's own headers emit macro redefinition warnings.
|
---|
80 | extra_common_flags += '-Wsystem-headers'
|
---|
81 | endif
|
---|
82 |
|
---|
83 | if UARCH != 'ia64'
|
---|
84 | extra_common_flags += [ '-fvar-tracking-assignments' ]
|
---|
85 | endif
|
---|
86 |
|
---|
87 | if CONFIG_DEBUG
|
---|
88 | extra_common_flags += [ '-Werror' ]
|
---|
89 | endif
|
---|
90 |
|
---|
91 | if CONFIG_LINE_DEBUG
|
---|
92 | extra_common_flags += [ '-gdwarf-5', '-g3' ]
|
---|
93 | endif
|
---|
94 |
|
---|
95 | extra_cflags = extra_common_flags + [
|
---|
96 | '-Wmissing-prototypes',
|
---|
97 | '-Werror-implicit-function-declaration',
|
---|
98 |
|
---|
99 | '-Wno-missing-braces',
|
---|
100 | '-Wno-missing-field-initializers',
|
---|
101 | '-Wno-unused-command-line-argument',
|
---|
102 | '-Wno-unused-parameter',
|
---|
103 | '-Wno-typedef-redefinition',
|
---|
104 | '-Wno-clobbered',
|
---|
105 | '-Wno-nonnull-compare',
|
---|
106 |
|
---|
107 | '-fno-builtin-strftime',
|
---|
108 | ]
|
---|
109 |
|
---|
110 | if CONFIG_UBSAN
|
---|
111 | extra_cflags += '-fsanitize=undefined'
|
---|
112 | endif
|
---|
113 |
|
---|
114 | extra_cppflags = extra_common_flags + [
|
---|
115 | '-fno-exceptions',
|
---|
116 | '-Wno-misleading-indentation',
|
---|
117 | '-frtti',
|
---|
118 | ]
|
---|
119 |
|
---|
120 | w_flags = {
|
---|
121 | 'c': extra_cflags,
|
---|
122 | 'cpp': extra_cppflags,
|
---|
123 | }
|
---|
124 |
|
---|
125 | # TODO: To remove noise in Meson output, we may want to cut down on
|
---|
126 | # the explicitly checked flags and just enable those supported by
|
---|
127 | # both gcc and clang unconditionally.
|
---|
128 |
|
---|
129 | # Process flags. Only sets those that compiler supports.
|
---|
130 | foreach lang : [ 'c', 'cpp' ]
|
---|
131 | extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
|
---|
132 | add_project_arguments(extra_cflags, language : [ lang ])
|
---|
133 | add_project_link_arguments(extra_cflags, language : [ lang ])
|
---|
134 | endforeach
|
---|
135 |
|
---|
136 | # This flag is needed at several places, hence we define it here.
|
---|
137 | #
|
---|
138 | # For backwards compatibility we try to detect --no-warn-rwx-segments.
|
---|
139 | # However, the autodetection done by Meson also results in
|
---|
140 | # "cannot find entry symbol _start; defaulting to 00000000004000b0"
|
---|
141 | # thus the option is never supported alone. So when detecting we also
|
---|
142 | # specify --entry=main so that the stub source provided by Meson is build
|
---|
143 | # correctly.
|
---|
144 | ldflags_ignore_rwx_segments = []
|
---|
145 | if cc.has_link_argument('-Wl,--no-warn-rwx-segments,--entry=main')
|
---|
146 | ldflags_ignore_rwx_segments += ['-Wl,--no-warn-rwx-segments']
|
---|
147 | endif
|
---|