include/ChangeLog:
[official-gcc.git] / gcc / opts.sh
blob2770f080ba0e6944c2b235076ebb0db2644bbaaf
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" > c_file
89 print "#include \"" h_file "\"" >> c_file
90 print "#include \"opts.h\"\n" >> c_file
91 print "const char * const lang_names[] =\n{" >> c_file
93 print "/* This file is auto-generated by opts.sh. */\n" > h_file
94 for (i = 0; i < n_langs; i++) {
95 macros[i] = "CL_" langs[i]
96 gsub( "[^A-Za-z0-9_]", "X", macros[i] )
97 s = substr(" ", length (macros[i]))
98 print "#define " macros[i] s " (1 << " i ")" >> h_file
99 print " \"" langs[i] "\"," >> c_file
102 print " 0\n};\n" >> c_file
103 print "const unsigned int cl_options_count = N_OPTS;\n" >> c_file
104 print "const struct cl_option cl_options[] =\n{" >> c_file
106 print "\nenum opt_code\n{" >> h_file
108 for (i = 0; i < n_opts; i++)
109 back_chain[i] = "N_OPTS";
111 for (i = 0; i < n_opts; i++) {
112 # Combine the flags of identical switches. Switches
113 # appear many times if they are handled by many front
114 # ends, for example.
115 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
116 flags[i + 1] = flags[i] " " flags[i + 1];
117 i++;
120 len = length (opts[i]);
121 enum = "OPT_" opts[i]
122 if (opts[i] == "finline-limit=")
123 enum = enum "eq"
124 gsub ("[^A-Za-z0-9]", "_", enum)
126 # If this switch takes joined arguments, back-chain all
127 # subsequent switches to it for which it is a prefix. If
128 # a later switch S is a longer prefix of a switch T, T
129 # will be back-chained to S in a later iteration of this
130 # for() loop, which is what we want.
131 if (flags[i] ~ "Joined") {
132 for (j = i + 1; j < n_opts; j++) {
133 if (substr (opts[j], 1, len) != opts[i])
134 break;
135 back_chain[j] = enum;
139 s = substr(" ", length (opts[i]))
140 if (i + 1 == n_opts)
141 comma = ""
143 printf(" %s,%s/* -%s */\n", enum, s, opts[i]) >> h_file
144 printf(" { \"%s\", (unsigned short) %s, %u,\n\t%s }%s\n",
145 opts[i], back_chain[i], len, switch_flags(flags[i]),
146 comma) >> c_file
149 print " N_OPTS\n};" >> h_file
150 print "};" >> c_file