| 1 |
# Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 2 |
# |
| 3 |
# This file is part of GCC. |
| 4 |
# |
| 5 |
# GCC is free software; you can redistribute it and/or modify it under |
| 6 |
# the terms of the GNU General Public License as published by the Free |
| 7 |
# Software Foundation; either version 3, or (at your option) any later |
| 8 |
# version. |
| 9 |
# |
| 10 |
# GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
# for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with GCC; see the file COPYING3. If not see |
| 17 |
# <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
################################################################## |
| 20 |
# |
| 21 |
# Transform Core/Device Information from avr-mcus.def to a |
| 22 |
# Representation that is understood by GCC's multilib Machinery. |
| 23 |
# |
| 24 |
# The Script works as a Filter from STDIN to STDOUT. |
| 25 |
# It generates a Makefile Snippet that sets some |
| 26 |
# MULTILIB_* Variables as needed. |
| 27 |
# |
| 28 |
################################################################## |
| 29 |
|
| 30 |
BEGIN { |
| 31 |
FS ="[(, \t]+" |
| 32 |
option[""] = "" |
| 33 |
comment = 1 |
| 34 |
cols_expected = -1 |
| 35 |
|
| 36 |
dir_tiny = "tiny-stack" |
| 37 |
opt_tiny = "msp8" |
| 38 |
|
| 39 |
dir_rcall = "short-calls" |
| 40 |
opt_rcall = "mshort-calls" |
| 41 |
|
| 42 |
# awk Variable Makefile Variable |
| 43 |
# ------------------------------------------ |
| 44 |
# m_options <-> MULTILIB_OPTIONS |
| 45 |
# m_dirnames <-> MULTILIB_DIRNAMES |
| 46 |
# m_required <-> MULTILIB_REQUIRED |
| 47 |
# m_reuse <-> MULTILIB_REUSE |
| 48 |
m_sep = "" |
| 49 |
m_options = "\nMULTILIB_OPTIONS = " |
| 50 |
m_dirnames = "\nMULTILIB_DIRNAMES =" |
| 51 |
m_required = "\nMULTILIB_REQUIRED =" |
| 52 |
m_reuse = "\nMULTILIB_REUSE =" |
| 53 |
|
| 54 |
have_long_double_is_double = (HAVE_LONG_DOUBLE_IS_DOUBLE \ |
| 55 |
== "HAVE_LONG_DOUBLE_IS_DOUBLE") |
| 56 |
have_double32 = (HAVE_DOUBLE32 == "HAVE_DOUBLE32") |
| 57 |
have_double64 = (HAVE_DOUBLE64 == "HAVE_DOUBLE64") |
| 58 |
have_long_double32 = (HAVE_LONG_DOUBLE32 == "HAVE_LONG_DOUBLE32") |
| 59 |
have_long_double64 = (HAVE_LONG_DOUBLE64 == "HAVE_LONG_DOUBLE64") |
| 60 |
|
| 61 |
have_double_multi = (have_double32 && have_double64) |
| 62 |
have_long_double_multi = (! have_long_double_is_double \ |
| 63 |
&& have_long_double32 && have_long_double64) |
| 64 |
|
| 65 |
# How to switch away from the default. |
| 66 |
dir_double = "double" (96 - with_double) |
| 67 |
opt_double = "mdouble=" (96 - with_double) |
| 68 |
|
| 69 |
dir_long_double = "long-double" (96 - with_long_double) |
| 70 |
opt_long_double = "mlong-double=" (96 - with_long_double) |
| 71 |
|
| 72 |
if (with_multilib_list != "") |
| 73 |
{ |
| 74 |
split(with_multilib_list, multilib_list, ",") |
| 75 |
|
| 76 |
for (i in multilib_list) |
| 77 |
{ |
| 78 |
multilibs[multilib_list[i]] = 1 |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
################################################################## |
| 84 |
# Add some Comments to the generated Files and copy-paste |
| 85 |
# Copyright Notice from above. |
| 86 |
################################################################## |
| 87 |
|
| 88 |
/^#/ { |
| 89 |
if (!comment) |
| 90 |
next |
| 91 |
else if (comment == 1) |
| 92 |
{ |
| 93 |
print "# Auto-generated Makefile Snip" |
| 94 |
print "# Generated by : ./gcc/config/avr/genmultilib.awk" |
| 95 |
print "# Generated from : ./gcc/config/avr/avr-mcus.def" |
| 96 |
print "# Used by : tmake_file from Makefile and genmultilib" |
| 97 |
print "" |
| 98 |
} |
| 99 |
|
| 100 |
comment = 2; |
| 101 |
|
| 102 |
print |
| 103 |
} |
| 104 |
|
| 105 |
/^$/ { |
| 106 |
# The first empty line stops copy-pasting the GPL comments |
| 107 |
# from this file to the generated file. |
| 108 |
|
| 109 |
if (comment) |
| 110 |
{ |
| 111 |
print |
| 112 |
|
| 113 |
if (have_double_multi) |
| 114 |
{ |
| 115 |
print "# dir_double = " dir_double |
| 116 |
print "# opt_double = -" opt_double |
| 117 |
} |
| 118 |
else |
| 119 |
print "# No multilib for double." |
| 120 |
|
| 121 |
if (have_long_double_multi) |
| 122 |
{ |
| 123 |
print "# dir_long_double = " dir_long_double |
| 124 |
print "# opt_long_double = -" opt_long_double |
| 125 |
} |
| 126 |
else |
| 127 |
print "# No multilib for long double." |
| 128 |
} |
| 129 |
comment = 0 |
| 130 |
} |
| 131 |
|
| 132 |
################################################################## |
| 133 |
# Run over all AVR_MCU Lines. If we encounter a required multilib |
| 134 |
# variant, add according combination of options to m_required, |
| 135 |
# but onyl once. Add encountered cores to m_dirnames and |
| 136 |
# according -mmcu= options to m_options. |
| 137 |
################################################################## |
| 138 |
|
| 139 |
/^AVR_MCU/ { |
| 140 |
line = $0 |
| 141 |
gsub (/\(/, ",", line) |
| 142 |
gsub (/[ \t")]/, "", line) |
| 143 |
n_cols = split (line, col, ",") |
| 144 |
|
| 145 |
# Now we have col[] something like: |
| 146 |
# col[1] = AVR_MCU |
| 147 |
# col[2] = avr2 # Device name |
| 148 |
# col[3] = ARCH_AVR2 # Core |
| 149 |
# col[4] = AVR_ERRATA_SKIP # Device Attributes |
| 150 |
# col[5] = NULL # Device Macro like __AVR_ATtiny22__ |
| 151 |
# col[6] = 0x0060 # Tdata |
| 152 |
# col[7] = 0x0 # Ttext |
| 153 |
# col[8] = 0x60000 # Flash Size |
| 154 |
# col[9] = 0 # PM Offset |
| 155 |
|
| 156 |
# Sanity check the number of columns. |
| 157 |
if (cols_expected == -1) |
| 158 |
cols_expected = n_cols |
| 159 |
else if (n_cols != cols_expected) |
| 160 |
{ |
| 161 |
msg = "genmultilib.awk: error: wrong number of columns" |
| 162 |
print msg | "cat 1>&2" |
| 163 |
print $0 | "cat 1>&2" |
| 164 |
exit 1 |
| 165 |
} |
| 166 |
|
| 167 |
name = col[2] |
| 168 |
|
| 169 |
if (col[5] == "NULL") |
| 170 |
{ |
| 171 |
core = name |
| 172 |
|
| 173 |
# avr1 is supported for Assembler only: It gets no multilib |
| 174 |
if (core == "avr1") |
| 175 |
next |
| 176 |
|
| 177 |
if (with_multilib_list != "" && !(core in multilibs)) |
| 178 |
next |
| 179 |
|
| 180 |
option[core] = "mmcu=" core |
| 181 |
|
| 182 |
m_options = m_options m_sep option[core] |
| 183 |
m_dirnames = m_dirnames " " core |
| 184 |
m_sep = "/" |
| 185 |
|
| 186 |
next |
| 187 |
} |
| 188 |
|
| 189 |
# avr1 is supported for Assembler only: Its Devices are ignored |
| 190 |
if (core == "avr1") |
| 191 |
next |
| 192 |
|
| 193 |
if (with_multilib_list != "" && !(core in multilibs)) |
| 194 |
next |
| 195 |
|
| 196 |
opts = option[core] |
| 197 |
|
| 198 |
# split device specific feature list |
| 199 |
n = split (col[4], dev_attribute, "|") |
| 200 |
|
| 201 |
for (i = 1; i <= n; i++) |
| 202 |
{ |
| 203 |
if (dev_attribute[i] == "AVR_SHORT_SP") |
| 204 |
opts = opts "/" opt_tiny |
| 205 |
if (dev_attribute[i] == "AVR_ISA_RCALL") |
| 206 |
opts = opts "/" opt_rcall |
| 207 |
} |
| 208 |
|
| 209 |
if (!have[opts]) |
| 210 |
{ |
| 211 |
have[opts] = 1 |
| 212 |
# Some special handling for the default mmcu: Remove a |
| 213 |
# leading "mmcu=avr2/" in order not to confuse genmultilib. |
| 214 |
gsub (/^mmcu=avr2\//, "", opts) |
| 215 |
if (opts != "mmcu=avr2") |
| 216 |
{ |
| 217 |
m_required = m_required " \\\n\t" opts |
| 218 |
if (have_double_multi && have_long_double_multi) |
| 219 |
{ |
| 220 |
m_required = m_required " \\\n\t" opts "/" opt_double |
| 221 |
m_required = m_required " \\\n\t" opts "/" opt_long_double |
| 222 |
|
| 223 |
# We have only 3 different combinations because -mdouble=64 |
| 224 |
# implies -mlong-double=64, and -mlong-double=32 implies |
| 225 |
# -mdouble=32, hence add respective reuses. The reuse is |
| 226 |
# not needed in the case with_double != with_long_double |
| 227 |
# which means with_double=32 with_long_double=64 because |
| 228 |
# the driver will rectify combining -mdouble=64 and |
| 229 |
# -mlong-double=32. |
| 230 |
if (with_double == with_long_double) |
| 231 |
{ |
| 232 |
d_opts = with_double == 32 ? opt_double : opt_long_double |
| 233 |
d_opts = opts "/" d_opts |
| 234 |
d_reuse = opts "/" opt_double "/" opt_long_double |
| 235 |
gsub (/=/, ".", d_opts) |
| 236 |
gsub (/=/, ".", d_reuse) |
| 237 |
m_reuse = m_reuse " \\\n\t" d_opts "=" d_reuse |
| 238 |
} |
| 239 |
} |
| 240 |
else if (have_double_multi) |
| 241 |
m_required = m_required " \\\n\t" opts "/" opt_double |
| 242 |
else if (have_long_double_multi) |
| 243 |
m_required = m_required " \\\n\t" opts "/" opt_long_double |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
################################################################## |
| 249 |
# |
| 250 |
################################################################## |
| 251 |
|
| 252 |
END { |
| 253 |
############################################################ |
| 254 |
# Output that Stuff |
| 255 |
############################################################ |
| 256 |
|
| 257 |
# Intended Target: $(top_builddir)/gcc/t-multilib-avr |
| 258 |
|
| 259 |
if (have_double_multi && have_long_double_multi) |
| 260 |
{ |
| 261 |
print m_options " " opt_tiny " " opt_rcall " " opt_double "/" opt_long_double |
| 262 |
print m_dirnames " " dir_tiny " " dir_rcall " " dir_double " " dir_long_double |
| 263 |
# Notice that the ./double* and ./long-double* variants cannot |
| 264 |
# be copied by t-avrlibc because the . default multilib is built |
| 265 |
# after all the others. |
| 266 |
m_required = m_required " \\\n\t" opt_double |
| 267 |
m_required = m_required " \\\n\t" opt_long_double |
| 268 |
if (with_double == with_long_double) |
| 269 |
{ |
| 270 |
d_opts = with_double == 32 ? opt_double : opt_long_double |
| 271 |
d_reuse = opt_double "/" opt_long_double |
| 272 |
gsub (/=/, ".", d_opts) |
| 273 |
gsub (/=/, ".", d_reuse) |
| 274 |
m_reuse = m_reuse " \\\n\t" d_opts "=" d_reuse |
| 275 |
|
| 276 |
} |
| 277 |
} |
| 278 |
else if (have_double_multi) |
| 279 |
{ |
| 280 |
print m_options " " opt_tiny " " opt_rcall " " opt_double |
| 281 |
print m_dirnames " " dir_tiny " " dir_rcall " " dir_double |
| 282 |
m_required = m_required " \\\n\t" opt_double |
| 283 |
} |
| 284 |
else if (have_long_double_multi) |
| 285 |
{ |
| 286 |
print m_options " " opt_tiny " " opt_rcall " " opt_long_double |
| 287 |
print m_dirnames " " dir_tiny " " dir_rcall " " dir_long_double |
| 288 |
m_required = m_required " \\\n\t" opt_long_double |
| 289 |
} |
| 290 |
else |
| 291 |
{ |
| 292 |
print m_options " " opt_tiny " " opt_rcall |
| 293 |
print m_dirnames " " dir_tiny " " dir_rcall |
| 294 |
} |
| 295 |
|
| 296 |
print m_required |
| 297 |
print m_reuse |
| 298 |
} |