OSDN Git Service

* config/i386/i386.md (expsf2, expdf2, expxf2): New patterns to
[pf3gnuchains/gcc-fork.git] / gcc / opts.sh
1 #!/bin/sh
2 #
3 #  Copyright (C) 2003 Free Software Foundation, Inc.
4 #  Contributed by Neil Booth, May 2003.
5 #
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.
10
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.
15
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.
19 #
20 # Usage: opts.sh outfile.c outfile.h file1.opt [file2.opt, ...]
21
22 # Always operate in the C locale.
23 LANG=C
24 LANGUAGE=C
25 LC_ALL=C
26 export LANG LANGUAGE LC_ALL
27
28 # Set AWK if environment has not already set it.
29 AWK=${AWK-awk}
30
31 SORT=sort               # Could be /bin/sort or /usr/bin/sort
32
33 C_FILE=$1; shift
34 H_FILE=$1; shift
35
36 # Must unset this, so that the gawk extension RS="" works.
37 unset POSIXLY_CORRECT
38
39 ${AWK} '
40         BEGIN{ RS=""; FS="\n" }
41         # Ignore comments and blank lines
42         /^[ \t]*(;|$)/  { next }
43         /^[^ \t]/       { gsub ("\n", "\034", $0); print }
44 ' "$@" | ${SORT} | ${AWK} '
45     function switch_flags (langs,   flags)
46     {
47         langs = ":" langs ":"
48         gsub( " ", ":", langs)
49         flags = "0"
50         if (langs ~ ":C:") flags = flags " | CL_C"
51         if (langs ~ ":ObjC:") flags = flags " | CL_OBJC"
52         if (langs ~ ":C\\+\\+:") flags = flags " | CL_CXX"
53         if (langs ~ ":ObjC\\+\\+:") flags = flags " | CL_OBJCXX"
54         if (langs ~ ":F77:") flags = flags " | CL_F77"
55         if (langs ~ ":Java:") flags = flags " | CL_JAVA"
56         if (langs ~ ":Ada:") flags = flags " | CL_ADA"
57         if (langs ~ ":Tree:") flags = flags " | CL_TREELANG"
58         if (langs ~ ":Common:") flags = flags " | CL_COMMON"
59         if (langs ~ ":Joined:") flags = flags " | CL_JOINED"
60         if (langs ~ ":Separate:") flags = flags " | CL_SEPARATE"
61         if (langs ~ ":RejectNegative:") flags = flags " | CL_REJECT_NEGATIVE"
62         sub( "^0 \\| ", "", flags )
63         return flags
64     }
65
66     BEGIN {
67         FS = "\034"
68         n_opts = 0
69     }
70
71 # Collect the text and flags of each option into an array
72     {
73         opts[n_opts] = $1
74         flags[n_opts] = $2
75         n_opts++;
76     }
77
78 # Dump out an enumeration into a .h file, and an array of options into a
79 # C file.  Combine the flags of duplicate options.
80     END {
81         c_file = "'${C_FILE}'"
82         h_file = "'${H_FILE}'"
83         comma = ","
84
85         print "/* This file is auto-generated by opts.sh.  */\n" > h_file
86         print "enum opt_code\n{"                        >> h_file
87
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 unsigned int cl_options_count = N_OPTS;\n" >> c_file
92         print "const struct cl_option cl_options[] =\n{" >> c_file
93
94         for (i = 0; i < n_opts; i++) {
95             while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
96                 flags[i + 1] = flags[i] " " flags[i + 1];
97                 i++;
98             }
99
100             enum = "OPT_" opts[i]
101             gsub( "[^A-Za-z0-9]", "_", enum)
102             s = substr("                                  ", length (opts[i]))
103             if (i + 1 == n_opts)
104                 comma = ""
105
106             printf("  %s,%s/* -%s */\n", enum, s, opts[i]) >> h_file
107             printf("  { \"%s\", %u, %s }%s\n", opts[i], \
108                 length(opts[i]), switch_flags(flags[i]), comma) >> c_file
109         }
110
111         print "  N_OPTS\n};"                            >> h_file
112         print "};"                                      >> c_file
113     }
114 '