(read_braced_string): Check for EOF. If encountered issue an error message.
[official-gcc.git] / gcc / opts.sh
blob2bedcfc9e005c70859e02bb9744d5bef9717635d
1 #!/bin/sh
3 # Copyright (C) 2003 Free Software Foundation, Inc.
4 # Contributed by Neil Booth, May 2003.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2, or (at your option) any
9 # later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # Usage: opts.sh outfile.c outfile.h file1.opt [file2.opt, ...]
22 # Always operate in the C locale.
23 LANG=C
24 LANGUAGE=C
25 LC_ALL=C
26 export LANG LANGUAGE LC_ALL
28 # Set AWK if environment has not already set it.
29 AWK=${AWK-awk}
31 SORT=sort # Could be /bin/sort or /usr/bin/sort
33 C_FILE=$1; shift
34 H_FILE=$1; shift
36 ${AWK} '
37 # Ignore comments and blank lines
38 /^[ \t]*(;|$)/ { next }
39 # Note that RS="" falls foul of gawk 3.1.2 bugs
40 /^[^ \t]/ { getline tmp; print $0 "\034" tmp}
41 ' "$@" | ${SORT} | ${AWK} '
42 function switch_flags (flags, result)
44 flags = " " flags " "
45 result = "0"
46 for (j = 0; j < n_langs; j++) {
47 regex = " " langs[j] " "
48 gsub ( "\\+", "\\+", regex )
49 if (flags ~ regex)
50 result = result " | " macros[j]
52 if (flags ~ " Common ") result = result " | CL_COMMON"
53 if (flags ~ " Joined ") result = result " | CL_JOINED"
54 if (flags ~ " JoinedOrMissing ") \
55 result = result " | CL_JOINED | CL_MISSING_OK"
56 if (flags ~ " Separate ") result = result " | CL_SEPARATE"
57 if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
58 if (flags ~ " UInteger ") result = result " | CL_UINTEGER"
59 sub( "^0 \\| ", "", result )
60 return result
63 BEGIN {
64 FS = "\034"
65 n_opts = 0
66 n_langs = 0
69 # Collect the text and flags of each option into an array
71 if ($1 == "Language") {
72 langs[n_langs] = $2
73 n_langs++;
74 } else {
75 opts[n_opts] = $1
76 flags[n_opts] = $2
77 n_opts++;
81 # Dump out an enumeration into a .h file, and an array of options into a
82 # C file. Combine the flags of duplicate options.
83 END {
84 c_file = "'${C_FILE}'"
85 h_file = "'${H_FILE}'"
86 comma = ","
88 print "/* This file is auto-generated by opts.sh. */\n" > h_file
89 for (i = 0; i < n_langs; i++) {
90 macros[i] = "CL_" langs[i]
91 gsub( "[^A-Za-z0-9_]", "X", macros[i] )
92 s = substr(" ", length (macros[i]))
93 print "#define " macros[i] s " (1 << " i ")" >> h_file
95 print "\nenum opt_code\n{" >> h_file
97 print "/* This file is auto-generated by opts.sh. */\n" > c_file
98 print "#include \"" h_file "\"" >> c_file
99 print "#include \"opts.h\"\n" >> c_file
100 print "const unsigned int cl_options_count = N_OPTS;\n" >> c_file
101 print "const struct cl_option cl_options[] =\n{" >> c_file
103 for (i = 0; i < n_opts; i++)
104 back_chain[i] = "N_OPTS";
106 for (i = 0; i < n_opts; i++) {
107 # Combine the flags of identical switches. Switches
108 # appear many times if they are handled by many front
109 # ends, for example.
110 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
111 flags[i + 1] = flags[i] " " flags[i + 1];
112 i++;
115 len = length (opts[i]);
116 enum = "OPT_" opts[i]
117 if (opts[i] == "finline-limit=")
118 enum = enum "eq"
119 gsub ("[^A-Za-z0-9]", "_", enum)
121 # If this switch takes joined arguments, back-chain all
122 # subsequent switches to it for which it is a prefix. If
123 # a later switch S is a longer prefix of a switch T, T
124 # will be back-chained to S in a later iteration of this
125 # for() loop, which is what we want.
126 if (flags[i] ~ "Joined") {
127 for (j = i + 1; j < n_opts; j++) {
128 if (substr (opts[j], 1, len) != opts[i])
129 break;
130 back_chain[j] = enum;
134 s = substr(" ", length (opts[i]))
135 if (i + 1 == n_opts)
136 comma = ""
138 printf(" %s,%s/* -%s */\n", enum, s, opts[i]) >> h_file
139 printf(" { \"%s\", (unsigned short) %s, %u,\n\t%s }%s\n",
140 opts[i], back_chain[i], len, switch_flags(flags[i]),
141 comma) >> c_file
144 print " N_OPTS\n};" >> h_file
145 print "};" >> c_file