1 # Copyright (C) 2011-2025 Free Software Foundation, Inc.
3 # This file is part of GCC.
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
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
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/>.
19 ##################################################################
21 # Transform Core/Device Information from avr-mcus.def to a
22 # Representation that is understood by GCC's multilib Machinery.
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.
28 ##################################################################
35 dir_tiny =
"tiny-stack"
38 dir_rcall =
"short-calls"
39 opt_rcall =
"mshort-calls"
41 # awk Variable Makefile Variable
42 # ------------------------------------------
43 # m_options <-> MULTILIB_OPTIONS
44 # m_dirnames <-> MULTILIB_DIRNAMES
45 # m_required <-> MULTILIB_REQUIRED
46 # m_reuse <-> MULTILIB_REUSE
48 m_options =
"\nMULTILIB_OPTIONS = "
49 m_dirnames =
"\nMULTILIB_DIRNAMES ="
50 m_required =
"\nMULTILIB_REQUIRED ="
51 m_reuse =
"\nMULTILIB_REUSE ="
53 have_long_double_is_double =
(HAVE_LONG_DOUBLE_IS_DOUBLE \
54 ==
"HAVE_LONG_DOUBLE_IS_DOUBLE")
55 have_double32 =
(HAVE_DOUBLE32 ==
"HAVE_DOUBLE32")
56 have_double64 =
(HAVE_DOUBLE64 ==
"HAVE_DOUBLE64")
57 have_long_double32 =
(HAVE_LONG_DOUBLE32 ==
"HAVE_LONG_DOUBLE32")
58 have_long_double64 =
(HAVE_LONG_DOUBLE64 ==
"HAVE_LONG_DOUBLE64")
60 have_double_multi =
(have_double32
&& have_double64
)
61 have_long_double_multi =
(! have_long_double_is_double \
62 && have_long_double32
&& have_long_double64
)
64 # How to switch away from the default.
65 dir_double =
"double" (96 - with_double
)
66 opt_double =
"mdouble=" (96 - with_double
)
68 dir_long_double =
"long-double" (96 - with_long_double
)
69 opt_long_double =
"mlong-double=" (96 - with_long_double
)
71 if (with_multilib_list
!= "")
73 split(with_multilib_list
, multilib_list
, ",")
75 for (i in multilib_list
)
77 multilibs
[multilib_list
[i
]] =
1
82 ##################################################################
83 # Add some Comments to the generated Files and copy-paste
84 # Copyright Notice from above.
85 ##################################################################
90 else if (comment ==
1)
92 print "# Auto-generated Makefile Snip"
93 print "# Generated by : ./gcc/config/avr/genmultilib.awk"
94 print "# Generated from : ./gcc/config/avr/avr-mcus.def"
95 print "# Used by : tmake_file from Makefile and genmultilib"
105 # The first empty line stops copy-pasting the GPL comments
106 # from this file to the generated file.
112 if (have_double_multi
)
114 print "# dir_double = " dir_double
115 print "# opt_double = -" opt_double
118 print "# No multilib for double."
120 if (have_long_double_multi
)
122 print "# dir_long_double = " dir_long_double
123 print "# opt_long_double = -" opt_long_double
126 print "# No multilib for long double."
131 ##################################################################
132 # Run over all AVR_MCU Lines. If we encounter a required multilib
133 # variant, add according combination of options to m_required,
134 # but onyl once. Add encountered cores to m_dirnames and
135 # according -mmcu= options to m_options.
136 ##################################################################
140 gsub ("\"", "", name
)
146 # avr1 is supported for Assembler only: It gets no multilib
150 if (with_multilib_list
!= "" && !
(core in multilibs
))
153 option
[core
] =
"mmcu=" core
155 m_options = m_options m_sep option
[core
]
156 m_dirnames = m_dirnames
" " core
162 # avr1 is supported for Assembler only: Its Devices are ignored
166 if (with_multilib_list
!= "" && !
(core in multilibs
))
171 # split device specific feature list
172 n =
split($
4,dev_attribute
,"|")
174 for (i=
1; i
<= n
; i
++)
176 if (dev_attribute
[i
] ==
"AVR_SHORT_SP")
177 opts = opts
"/" opt_tiny
178 if (dev_attribute
[i
] ==
"AVR_ISA_RCALL")
179 opts = opts
"/" opt_rcall
185 # Some special handling for the default mmcu: Remove a
186 # leading "mmcu=avr2/" in order not to confuse genmultilib.
187 gsub (/^mmcu=avr2\
//, "", opts
)
188 if (opts
!= "mmcu=avr2")
190 m_required = m_required
" \\\n\t" opts
191 if (have_double_multi
&& have_long_double_multi
)
193 m_required = m_required
" \\\n\t" opts
"/" opt_double
194 m_required = m_required
" \\\n\t" opts
"/" opt_long_double
196 # We have only 3 different combinations because -mdouble=64
197 # implies -mlong-double=64, and -mlong-double=32 implies
198 # -mdouble=32, hence add respective reuses. The reuse is
199 # not needed in the case with_double != with_long_double
200 # which means with_double=32 with_long_double=64 because
201 # the driver will rectify combining -mdouble=64 and
203 if (with_double == with_long_double
)
205 d_opts = with_double ==
32 ? opt_double
: opt_long_double
206 d_opts = opts
"/" d_opts
207 d_reuse = opts
"/" opt_double
"/" opt_long_double
208 gsub (/=
/, ".", d_opts
)
209 gsub (/=
/, ".", d_reuse
)
210 m_reuse = m_reuse
" \\\n\t" d_opts
"=" d_reuse
213 else if (have_double_multi
)
214 m_required = m_required
" \\\n\t" opts
"/" opt_double
215 else if (have_long_double_multi
)
216 m_required = m_required
" \\\n\t" opts
"/" opt_long_double
221 ##################################################################
223 ##################################################################
226 ############################################################
228 ############################################################
230 # Intended Target: $(top_builddir)/gcc/t-multilib-avr
232 if (have_double_multi
&& have_long_double_multi
)
234 print m_options
" " opt_tiny
" " opt_rcall
" " opt_double
"/" opt_long_double
235 print m_dirnames
" " dir_tiny
" " dir_rcall
" " dir_double
" " dir_long_double
236 # Notice that the ./double* and ./long-double* variants cannot
237 # be copied by t-avrlibc because the . default multilib is built
238 # after all the others.
239 m_required = m_required
" \\\n\t" opt_double
240 m_required = m_required
" \\\n\t" opt_long_double
241 if (with_double == with_long_double
)
243 d_opts = with_double ==
32 ? opt_double
: opt_long_double
244 d_reuse = opt_double
"/" opt_long_double
245 gsub (/=
/, ".", d_opts
)
246 gsub (/=
/, ".", d_reuse
)
247 m_reuse = m_reuse
" \\\n\t" d_opts
"=" d_reuse
251 else if (have_double_multi
)
253 print m_options
" " opt_tiny
" " opt_rcall
" " opt_double
254 print m_dirnames
" " dir_tiny
" " dir_rcall
" " dir_double
255 m_required = m_required
" \\\n\t" opt_double
257 else if (have_long_double_multi
)
259 print m_options
" " opt_tiny
" " opt_rcall
" " opt_long_double
260 print m_dirnames
" " dir_tiny
" " dir_rcall
" " dir_long_double
261 m_required = m_required
" \\\n\t" opt_long_double
265 print m_options
" " opt_tiny
" " opt_rcall
266 print m_dirnames
" " dir_tiny
" " dir_rcall