]>
Commit | Line | Data |
---|---|---|
71e45bc2 | 1 | # Copyright (C) 2011, 2012 Free Software Foundation, Inc. |
b32bc361 | 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 | # | |
26 | # FORMAT = "Makefile": Generate Makefile Snipet that sets some | |
27 | # MULTILIB_* Variables as needed. | |
28 | # | |
b32bc361 | 29 | ################################################################## |
30 | ||
31 | BEGIN { | |
32 | FS ="[(, \t]+" | |
33 | option[""] = "" | |
34 | tiny_stack[""] = 1 | |
35 | comment = 1 | |
36 | n_mcu = 0 | |
37 | n_cores = 0 | |
38 | ||
39 | mtiny[0] = "" | |
40 | mtiny[1] = "tiny-stack" | |
d32d7e3a | 41 | option["tiny-stack"] = "msp8" |
b32bc361 | 42 | } |
43 | ||
44 | ################################################################## | |
45 | # Add some Comments to the generated Files and copy-paste | |
46 | # Copyright Notice from above. | |
47 | ################################################################## | |
48 | ||
49 | /^#/ { | |
50 | if (!comment) | |
51 | next | |
52 | else if (comment == 1) | |
53 | { | |
b32bc361 | 54 | if (FORMAT == "Makefile") |
55 | { | |
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 "" | |
61 | } | |
62 | } | |
63 | ||
64 | comment = 2; | |
65 | ||
b32bc361 | 66 | |
67 | } | |
68 | ||
69 | /^$/ { | |
d32d7e3a | 70 | # The first empty line stops copy-pasting the GPL comments |
71 | # from this file to the generated file. | |
b32bc361 | 72 | |
73 | comment = 0 | |
74 | } | |
75 | ||
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 | ################################################################## | |
84 | ||
85 | /^AVR_MCU/ { | |
86 | name = $2 | |
87 | gsub ("\"", "", name) | |
88 | ||
89 | if ($4 == "NULL") | |
90 | { | |
91 | core = name | |
92 | ||
93 | # avr1 is supported for Assembler only: It gets no multilib | |
94 | if (core == "avr1") | |
95 | next | |
96 | ||
97 | cores[n_cores] = core | |
98 | n_cores++ | |
99 | tiny_stack[core] = 0 | |
100 | option[core] = "mmcu=" core | |
101 | ||
102 | next | |
103 | } | |
104 | ||
105 | # avr1 is supported for Assembler only: Its Devices are ignored | |
106 | if (core == "avr1") | |
107 | next | |
108 | ||
109 | tiny_stack[name] = $5 | |
110 | mcu[n_mcu] = name | |
111 | n_mcu++ | |
112 | option[name] = "mmcu=" name | |
113 | toCore[name] = core | |
114 | ||
115 | if (tiny_stack[name] == 1) | |
116 | tiny_stack[core] = 1 | |
117 | } | |
118 | ||
119 | ################################################################## | |
120 | # | |
121 | # We gathered all the Information, now build/output the following: | |
122 | # | |
123 | # awk Variable target Variable FORMAT | |
124 | # ----------------------------------------------------------- | |
125 | # m_options <-> MULTILIB_OPTIONS Makefile | |
126 | # m_dirnames <-> MULTILIB_DIRNAMES " | |
127 | # m_exceptions <-> MULTILIB_EXCEPTIONS " | |
128 | # m_matches <-> MULTILIB_MATCHES " | |
b32bc361 | 129 | # |
130 | ################################################################## | |
131 | ||
132 | END { | |
133 | m_options = "\nMULTILIB_OPTIONS = " | |
134 | m_dirnames = "\nMULTILIB_DIRNAMES =" | |
135 | m_exceptions = "\nMULTILIB_EXCEPTIONS =" | |
136 | m_matches = "\nMULTILIB_MATCHES =" | |
137 | ||
b32bc361 | 138 | ############################################################## |
139 | # Compose MULTILIB_OPTIONS. This represents the Cross-Product | |
d32d7e3a | 140 | # (avr2, avr25, ...) x msp8 |
b32bc361 | 141 | |
142 | sep = "" | |
143 | for (c = 0; c < n_cores; c++) | |
144 | { | |
145 | m_options = m_options sep option[cores[c]] | |
146 | sep = "/" | |
147 | } | |
148 | ||
d32d7e3a | 149 | # The ... x msp8 |
b32bc361 | 150 | m_options = m_options " " option[mtiny[1]] |
151 | ||
152 | ############################################################## | |
153 | # Map Device to its multilib | |
154 | ||
b32bc361 | 155 | for (t = 0; t < n_mcu; t++) |
156 | { | |
157 | core = toCore[mcu[t]] | |
158 | ||
d32d7e3a | 159 | line = option[core] ":" option[mcu[t]] |
160 | gsub ("=", "?", line) | |
161 | gsub (":", "=", line) | |
b32bc361 | 162 | |
d32d7e3a | 163 | m_matches = m_matches " \\\n\t" line |
b32bc361 | 164 | } |
165 | ||
166 | #################################################################### | |
d32d7e3a | 167 | # Compose MULTILIB_DIRNAMES and MULTILIB_EXEPTIONS |
b32bc361 | 168 | |
169 | n_mtiny = 2 | |
170 | for (t = 0; t < n_mtiny; t++) | |
171 | for (c = -1; c < n_cores; c++) | |
172 | { | |
173 | if (c == -1) | |
174 | core = "" | |
175 | else | |
176 | core = cores[c] | |
177 | ||
178 | # The Directory Name for this multilib | |
179 | ||
180 | if (core != "" && mtiny[t] != "") | |
181 | { | |
182 | mdir = core "/" mtiny[t] | |
183 | mopt = option[core] "/" option[mtiny[t]] | |
184 | } | |
185 | else | |
186 | { | |
187 | mdir = core mtiny[t] | |
188 | mopt = option[core] option[mtiny[t]] | |
189 | } | |
190 | ||
191 | if (core != "" && tiny_stack[core] == 0 && mtiny[t] != "") | |
192 | { | |
193 | # There's not a single SP = 8 Devices for this Core: | |
194 | # Don't build respective multilib | |
195 | m_exceptions = m_exceptions " \\\n\t" mopt | |
196 | continue | |
197 | } | |
198 | ||
199 | if (core != "avr2" || mtiny[t] == "") | |
200 | m_dirnames = m_dirnames " " mdir | |
b32bc361 | 201 | } |
202 | ||
203 | ############################################################ | |
204 | # Output that Stuff | |
205 | ############################################################ | |
206 | ||
207 | if (FORMAT == "Makefile") | |
208 | { | |
209 | # Intended Target: ./gcc/config/avr/t-multilib | |
210 | ||
211 | print m_options | |
212 | print m_dirnames | |
213 | print m_exceptions | |
214 | print m_matches | |
215 | } | |
b32bc361 | 216 | } |