OSDN Git Service

* Makefile.in (c-opts.o, c-options.h): Update dependencies.
[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 AWK=/usr/bin/awk
23 SORT=/usr/bin/sort
24
25 C_FILE=$1; shift
26 H_FILE=$1; shift
27
28 cat "$@" | ${AWK} '
29         BEGIN{ RS=""; FS="\n" }
30         # Ignore comments and blank lines
31         /^[ \t]*(;|$)/  { next }
32         /^[^ \t]/       { gsub ("\n", "\034", $0); print }
33 ' | LANG=C ${SORT} | ${AWK} '
34     function switch_flags (langs,   flags)
35     {
36         langs = ":" langs ":"
37         gsub( " ", ":", langs)
38         flags = "0"
39         if (langs ~ ":C:") flags = flags " | CL_C"
40         if (langs ~ ":ObjC:") flags = flags " | CL_OBJC"
41         if (langs ~ ":C\\+\\+:") flags = flags " | CL_CXX"
42         if (langs ~ ":ObjC\\+\\+:") flags = flags " | CL_OBJCXX"
43         if (langs ~ ":Joined") flags = flags " | CL_JOINED"
44         if (langs ~ ":Separate") flags = flags " | CL_SEPARATE"
45         sub( "^0 \\| ", "", flags )
46         return flags
47     }
48
49     BEGIN {
50         c_file = "'${C_FILE}'"
51         h_file = "'${H_FILE}'"
52         FS = "\034"
53         print "/* This file is auto-generated by opts.sh.  */\n" > h_file
54         print "/* This file is auto-generated by opts.sh.  */\n" > c_file
55         print "struct cl_option\n{"                     >> h_file
56         print "  const char *opt_text;"                 >> h_file
57         print "  unsigned char opt_len;"                >> h_file
58         print "  unsigned char flags;"                  >> h_file
59         print "};\n"                                    >> h_file
60         print "enum opt_code\n{"                        >> h_file
61         print "static const struct cl_option cl_options[] =\n{" >> c_file
62     }
63
64     {
65         opt = $1
66         gsub ( "[^A-Za-z0-9]", "_", opt)
67         s = substr ("                                  ", length (opt))
68         enum = "OPT_" opt
69         printf ("  %s,%s/* -%s */\n", enum, s, $1 )     >> h_file
70         printf ("  { \"%s\", %u, %s },\n", $1, \
71             length ($1), switch_flags($2))              >> c_file
72     }
73
74     END {
75         print "  N_OPTS\n};"                            >> h_file
76         print "};"                                      >> c_file
77     }
78 '