1 # Copyright (C) 2003,2004 Free Software Foundation, Inc.
2 # Contributed by Kelley Cook, June 2004.
3 # Original code from Neil Booth, May 2003.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # This Awk script reads in the option records generated from
20 # opt-gather.awk, combines the flags of duplicat options and generates a
23 # This program uses functions from opt-functions.awk
25 # Usage: awk -f opt-functions.awk -f optc-gen.awk \
26 # [-v header_name=header.h] < inputfile > options.c
34 # Default the name of header created from opth-gen.awk to options.h
35 if (header_name ==
"") header_name=
"options.h"
38 # Collect the text and flags of each option into an array
40 if ($
1 ==
"Language") {
45 name = opt_args
("Mask", $
1)
55 # Dump that array of options into a C file.
57 print "/* This file is auto-generated by opts.sh. */"
59 n_headers =
split(header_name
, headers
, " ")
60 for (i =
1; i
<= n_headers
; i
++)
61 print "#include " quote headers
[i
] quote
62 print "#include " quote
"opts.h" quote
63 print "#include " quote
"intl.h" quote
66 for (i =
0; i
< n_opts
; i
++) {
67 name = var_name
(flags
[i
]);
71 if (flag_set_p
("VarExists", flags
[i
]))
74 init = opt_args
("Init", flags
[i
])
77 else if (name in var_seen
)
80 print "/* Set by -" opts
[i
] "."
81 print " " help
[i
] " */"
82 print var_type
(flags
[i
]) name init
";"
89 print "const char * const lang_names[] =\n{"
90 for (i =
0; i
< n_langs
; i
++) {
91 macros
[i
] =
"CL_" langs
[i
]
92 gsub( "[^A-Za-z0-9_]", "X", macros
[i
] )
93 s =
substr(" ", length (macros
[i
]))
94 print " " quote langs
[i
] quote
","
98 print "const unsigned int cl_options_count = N_OPTS;\n"
100 print "const struct cl_option cl_options[] =\n{"
102 for (i =
0; i
< n_opts
; i
++)
103 back_chain
[i
] =
"N_OPTS";
105 for (i =
0; i
< n_opts
; i
++) {
106 # Combine the flags of identical switches. Switches
107 # appear many times if they are handled by many front
109 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
110 flags
[i
+ 1] = flags
[i
] " " flags
[i
+ 1];
114 len =
length (opts
[i
]);
115 enum =
"OPT_" opts
[i
]
116 if (opts
[i
] ==
"finline-limit=")
118 gsub ("[^A-Za-z0-9]", "_", enum
)
120 # If this switch takes joined arguments, back-chain all
121 # subsequent switches to it for which it is a prefix. If
122 # a later switch S is a longer prefix of a switch T, T
123 # will be back-chained to S in a later iteration of this
124 # for() loop, which is what we want.
125 if (flag_set_p
("Joined.*", flags
[i
])) {
126 for (j = i
+ 1; j
< n_opts
; j
++) {
127 if (substr (opts
[j
], 1, len
) != opts
[i
])
129 back_chain
[j
] = enum
;
133 s =
substr(" ", length (opts
[i
]))
140 hlp = quote help
[i
] quote
;
142 printf(" { %c-%s%c,\n %s,\n %s, %u,\n",
143 quote
, opts
[i
], quote
, hlp
, back_chain
[i
], len
)
144 condition = opt_args
("Condition", flags
[i
])
145 cl_flags = switch_flags
(flags
[i
])
152 condition
, cl_flags
, cl_flags
)
154 printf(" %s,\n", cl_flags
)
155 printf(" %s, %s }%s\n", var_ref
(flags
[i
]), var_set
(flags
[i
]), comma
)