PR target/11183
[official-gcc.git] / gcc / opts.sh
blob4d59dc5b592f47b1e54b8ed62c2395458ddea712
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 BEGIN{ RS=""; FS="\n" }
38 # Ignore comments and blank lines
39 /^[ \t]*(;|$)/ { next }
40 /^[^ \t]/ { gsub ("\n", "\034", $0); print }
41 ' "$@" | ${SORT} | ${AWK} '
42 function switch_flags (langs, flags)
44 langs = ":" langs ":"
45 gsub( " ", ":", langs)
46 flags = "0"
47 if (langs ~ ":C:") flags = flags " | CL_C"
48 if (langs ~ ":ObjC:") flags = flags " | CL_OBJC"
49 if (langs ~ ":C\\+\\+:") flags = flags " | CL_CXX"
50 if (langs ~ ":ObjC\\+\\+:") flags = flags " | CL_OBJCXX"
51 if (langs ~ ":F77:") flags = flags " | CL_F77"
52 if (langs ~ ":Java:") flags = flags " | CL_JAVA"
53 if (langs ~ ":Ada:") flags = flags " | CL_ADA"
54 if (langs ~ ":Tree:") flags = flags " | CL_TREELANG"
55 if (langs ~ ":Common:") flags = flags " | CL_COMMON"
56 if (langs ~ ":Joined:") flags = flags " | CL_JOINED"
57 if (langs ~ ":Separate:") flags = flags " | CL_SEPARATE"
58 if (langs ~ ":RejectNegative:") flags = flags " | CL_REJECT_NEGATIVE"
59 sub( "^0 \\| ", "", flags )
60 return flags
63 BEGIN {
64 FS = "\034"
65 n_opts = 0
68 # Collect the text and flags of each option into an array
70 opts[n_opts] = $1
71 flags[n_opts] = $2
72 n_opts++;
75 # Dump out an enumeration into a .h file, and an array of options into a
76 # C file. Combine the flags of duplicate options.
77 END {
78 c_file = "'${C_FILE}'"
79 h_file = "'${H_FILE}'"
80 comma = ","
82 print "/* This file is auto-generated by opts.sh. */\n" > h_file
83 print "enum opt_code\n{" >> h_file
85 print "/* This file is auto-generated by opts.sh. */\n" > c_file
86 print "#include \"" h_file "\"" >> c_file
87 print "#include \"opts.h\"\n" >> c_file
88 print "const unsigned int cl_options_count = N_OPTS;\n" >> c_file
89 print "const struct cl_option cl_options[] =\n{" >> c_file
91 for (i = 0; i < n_opts; i++) {
92 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
93 flags[i + 1] = flags[i] " " flags[i + 1];
94 i++;
97 enum = "OPT_" opts[i]
98 gsub( "[^A-Za-z0-9]", "_", enum)
99 s = substr(" ", length (opts[i]))
100 if (i + 1 == n_opts)
101 comma = ""
103 printf(" %s,%s/* -%s */\n", enum, s, opts[i]) >> h_file
104 printf(" { \"%s\", %u, %s }%s\n", opts[i], \
105 length(opts[i]), switch_flags(flags[i]), comma) >> c_file
108 print " N_OPTS\n};" >> h_file
109 print "};" >> c_file