2 ################################################################################
3 # Copyright (C) 2001-2003, Parrot Foundation.
5 ################################################################################
9 tools/dev/cc_flags.pl - Process compiler flags
13 % perl tools/dev/cc_flags.pl transform compiler flags
17 This script is used in a F<Makefile> to process the flags to pass to the
18 compiler for each C file.
20 See F<config/gen/makefiles/CFLAGS.in> for the transformation file format.
24 F<config/gen/cflags/root.in>.
28 ################################################################################
36 if ($ARGV[0] eq '--return-only') {
41 if ($ARGV[0] eq '-v') {
48 open my $F, '<', $cflags or die "open $cflags: $!\n";
58 if (s/^\{(.*?)\}\s*//) {
62 elsif (s/^(\S+)\s*//) {
63 $regex = qr/^\Q$1\E$/;
66 die "syntax error in $cflags: line $., $_\n";
70 if (s/^([-+])\{(.*?)\}\s*//) {
72 my ( $sign, $options ) = ( $1, $2 );
73 foreach my $option ( split ' ', $options ) {
74 push @options, [ $regex, $sign, $option ];
77 elsif (s{s(.)(.*?)\1(.*?)\1([imsx]*)\s*}{}) {
81 push @options, [ $regex, 's', "$mod$2", $3 ];
84 die "syntax error in $cflags: line $., $_\n";
92 my ($cfile) = grep /\.c$/, @ARGV;
94 my ( $inject_point, $where );
102 # Found a "" - remove it
103 splice @ARGV, $where, 1;
104 $inject_point = $where;
111 foreach my $option (@options) {
112 if ( $cfile =~ $option->[0] ) {
113 if ( $option->[1] eq '+' ) {
114 splice @ARGV, $inject_point, 0, $option->[2];
116 elsif ( $option->[1] eq '-' ) {
117 @ARGV = grep { $_ ne $option->[2] } @ARGV;
120 foreach my $arg (@ARGV) {
121 $arg =~ s/$option->[2]/$option->[3]/;
129 # Visual C++ already prints the source file name...
130 if ( $ARGV[0] =~ /cl(?:\.exe)?/i ) {
132 # ...but only the file name, so we print the path
133 # to the directory first
134 if ( $cfile =~ /(.*[\/\\])/ ) {
144 print join ' ', @ARGV;
149 print join ' ', @ARGV;
152 exit system(@ARGV) / 256;
156 # cperl-indent-level: 4
159 # vim: expandtab shiftwidth=4: