genmultilib.awk revision 1.7
1# Copyright (C) 2011-2018 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
30BEGIN {
31    FS ="[(, \t]+"
32    option[""] = ""
33    comment = 1
34
35    dir_tiny = "tiny-stack"
36    opt_tiny = "msp8"
37
38    dir_rcall = "short-calls"
39    opt_rcall = "mshort-calls"
40
41    #    awk Variable         Makefile Variable  
42    #  ------------------------------------------
43    #    m_options     <->    MULTILIB_OPTIONS
44    #    m_dirnames    <->    MULTILIB_DIRNAMES
45    #    m_required    <->    MULTILIB_REQUIRED
46    m_sep = ""
47    m_options    = "\nMULTILIB_OPTIONS = "
48    m_dirnames   = "\nMULTILIB_DIRNAMES ="
49    m_required   = "\nMULTILIB_REQUIRED ="
50}
51
52##################################################################
53# Add some Comments to the generated Files and copy-paste
54# Copyright Notice from above.
55##################################################################
56
57/^#/ {
58    if (!comment)
59	next
60    else if (comment == 1)
61    {
62	print "# Auto-generated Makefile Snip"
63	print "# Generated by    : ./gcc/config/avr/genmultilib.awk"
64	print "# Generated from  : ./gcc/config/avr/avr-mcus.def"
65	print "# Used by         : tmake_file from Makefile and genmultilib"
66	print ""
67    }
68
69    comment = 2;
70
71    print
72}
73
74/^$/ {
75    # The first empty line stops copy-pasting the GPL comments
76    # from this file to the generated file.
77
78    comment = 0
79}
80
81##################################################################
82# Run over all AVR_MCU Lines.  If we encounter a required multilib
83# variant, add according combination of options to m_required,
84# but onyl once.  Add encountered cores to m_dirnames and
85# according -mmcu= options to m_options.
86##################################################################
87
88/^AVR_MCU/ {
89    name = $2
90    gsub ("\"", "", name)
91
92    if ($5 == "NULL")
93    {
94	core = name
95
96	# avr1 is supported for Assembler only:  It gets no multilib
97	if (core == "avr1")
98	    next
99
100	option[core] = "mmcu=" core
101
102	m_options  = m_options m_sep option[core]
103	m_dirnames = m_dirnames " " core
104	m_sep = "/"
105
106	next
107    }
108
109    # avr1 is supported for Assembler only:  Its Devices are ignored
110    if (core == "avr1")
111	next
112
113    opts = option[core]
114
115    # split device specific feature list
116    n = split($4,dev_attribute,"|")
117
118    for (i=1; i <= n; i++)
119    {
120      if (dev_attribute[i] == "AVR_SHORT_SP")
121        opts = opts "/" opt_tiny
122      if (dev_attribute[i] == "AVR_ISA_RCALL")
123        opts = opts "/" opt_rcall
124    }
125
126    if (!have[opts])
127    {
128	have[opts] = 1
129	# Some special handling for the default mmcu: Remove a
130	# leading "mmcu=avr2/" in order not to confuse genmultilib.
131	gsub (/^mmcu=avr2\//, "", opts)
132	if (opts != "mmcu=avr2")
133	    m_required = m_required " \\\n\t" opts
134    }
135}
136
137##################################################################
138# 
139##################################################################
140
141END {
142    ############################################################
143    # Output that Stuff
144    ############################################################
145
146    # Intended Target: ./gcc/config/avr/t-multilib
147
148    print m_options  " " opt_tiny " " opt_rcall
149    print m_dirnames " " dir_tiny " " dir_rcall
150    print m_required
151}
152