2016-11-10 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / config / avr / genmultilib.awk
blobe6b372885fb5026d7c5558745f3b8e629f1ec249
1 # Copyright (C) 2011-2016 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
8 # version.
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.
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.
26 # FORMAT = "Makefile": Generate Makefile Snipet that sets some
27 # MULTILIB_* Variables as needed.
29 ##################################################################
31 BEGIN {
32 FS ="[(, \t]+"
33 option[""] = ""
34 tiny_stack[""] = 1
35 comment = 1
36 n_mcu = 0
37 n_cores = 0
39 mtiny[0] = ""
40 mtiny[1] = "tiny-stack"
41 option["tiny-stack"] = "msp8"
44 ##################################################################
45 # Add some Comments to the generated Files and copy-paste
46 # Copyright Notice from above.
47 ##################################################################
49 /^#/ {
50 if (!comment)
51 next
52 else if (comment == 1)
54 if (FORMAT == "Makefile")
56 print "# Auto-generated Makefile Snip"
57 print "# Generated by : ./gcc/config/avr/genmultilib.awk"
58 print "# Generated from : ./gcc/config/avr/avr-mcus.def"
59 print "# Used by : tmake_file from Makefile and genmultilib"
60 print ""
64 comment = 2;
66 print
69 /^$/ {
70 # The first empty line stops copy-pasting the GPL comments
71 # from this file to the generated file.
73 comment = 0
76 ##################################################################
77 # Run over all AVR_MCU Lines and gather Information:
78 # cores[] : Enumerates the Cores (avr2, avr25, ...)
79 # mcu[] : Enumerates the Devices
80 # tiny_stack[]: Maps Core/Device to 0 (2-byte SP) or 1 (1-byte SP)
81 # option[] : Maps Core/Device to the mmcu= option to get it
82 # toCore[] : Maps Device to its Core
83 ##################################################################
85 /^AVR_MCU/ {
86 name = $2
87 gsub ("\"", "", name)
89 if ($5 == "NULL")
91 core = name
93 # avr1 is supported for Assembler only: It gets no multilib
94 if (core == "avr1")
95 next
97 cores[n_cores] = core
98 n_cores++
99 tiny_stack[core] = 0
100 option[core] = "mmcu=" core
102 next
105 # avr1 is supported for Assembler only: Its Devices are ignored
106 if (core == "avr1")
107 next
109 # split device specific feature list
110 n = split($4,dev_attribute,"|")
112 # set tiny_stack false by default
113 tiny_stack[name] = 0
114 for (i=1; i <= n; i++)
115 if (dev_attribute[i] == "AVR_SHORT_SP") {
116 tiny_stack[name] = 1
117 break
120 mcu[n_mcu] = name
121 n_mcu++
122 option[name] = "mmcu=" name
123 toCore[name] = core
125 if (tiny_stack[name] == 1)
126 tiny_stack[core] = 1
129 ##################################################################
131 # We gathered all the Information, now build/output the following:
133 # awk Variable target Variable FORMAT
134 # -----------------------------------------------------------
135 # m_options <-> MULTILIB_OPTIONS Makefile
136 # m_dirnames <-> MULTILIB_DIRNAMES "
137 # m_exceptions <-> MULTILIB_EXCEPTIONS "
139 ##################################################################
141 END {
142 m_options = "\nMULTILIB_OPTIONS = "
143 m_dirnames = "\nMULTILIB_DIRNAMES ="
144 m_exceptions = "\nMULTILIB_EXCEPTIONS ="
146 ##############################################################
147 # Compose MULTILIB_OPTIONS. This represents the Cross-Product
148 # (avr2, avr25, ...) x msp8
150 sep = ""
151 for (c = 0; c < n_cores; c++)
153 m_options = m_options sep option[cores[c]]
154 sep = "/"
157 # The ... x msp8
158 m_options = m_options " " option[mtiny[1]]
160 ##############################################################
161 # Map Device to its multilib
163 for (t = 0; t < n_mcu; t++)
165 core = toCore[mcu[t]]
167 line = option[core] ":" option[mcu[t]]
168 gsub ("=", "?", line)
169 gsub (":", "=", line)
172 ####################################################################
173 # Compose MULTILIB_DIRNAMES and MULTILIB_EXEPTIONS
175 n_mtiny = 2
176 for (t = 0; t < n_mtiny; t++)
177 for (c = -1; c < n_cores; c++)
179 if (c == -1)
180 core = ""
181 else
182 core = cores[c]
184 # The Directory Name for this multilib
186 if (core != "" && mtiny[t] != "")
188 mdir = core "/" mtiny[t]
189 mopt = option[core] "/" option[mtiny[t]]
191 else
193 mdir = core mtiny[t]
194 mopt = option[core] option[mtiny[t]]
197 if (core != "" && tiny_stack[core] == 0 && mtiny[t] != "")
199 # There's not a single SP = 8 Devices for this Core:
200 # Don't build respective multilib
201 m_exceptions = m_exceptions " \\\n\t" mopt
202 continue
205 if (core != "avr2" || mtiny[t] == "")
206 m_dirnames = m_dirnames " " mdir
209 ############################################################
210 # Output that Stuff
211 ############################################################
213 if (FORMAT == "Makefile")
215 # Intended Target: ./gcc/config/avr/t-multilib
217 print m_options
218 print m_dirnames
219 print m_exceptions