[EMAIL PROTECTED] (Dan Sugalski) writes: > We could really use the capability of specifying per-C-file flags in > the make procedure, something that can be built into Configure. Right > now we build without optimizations on, which is fine, but I'd like to > turn them on in the future. > > They can't be turned on unconditionally, since tsq.c *can't* have any > optimizations turned on for it. (That's the thread-safe queue module, > something that is annoyingly execution-order-dependent because it has > to operate safely as interrupt code potentially interrupting itself as > non-interrupt code) And, if Perl 5 is any guide (and I think it is) > there will be some platform/compiler combinations that won't be able > to compile one or more source modules with the highest optimization > level, but will be able to manage with a lower one. > > So... Configure.pl needs to be able to build a makefile that has > per-C-file flags, and those flags need to be overridable per-file at > configure time by the platform configuration module.
I've taken this very simple approach to the problem. A perl-wrapper for the CC lines in makefiles/root.in .c$(O) : $(PERL) tools/dev/cc_flags.pl $(CC) $(CFLAGS) ${cc_o_out}$@ -c $< that takes a rules-based approach to removing or adding options to the command-line, based on the filename of the .c-file. This gives some overhead while building, but it keeps the complexity of the solution down a lot. Right now, the configure system has nothing to do with it, but it'd be fairly simple to make it write a file like following example: ---------------------------------------------------------------------- # File: CFLAGS # [ filename | {regex} ] -{removed option} +{added option} ... spf_render.c -{-Wformat-nonliteral} {^core} +{-O3} ---------------------------------------------------------------------- What're peoples opinion? Script: ---------------------------------------------------------------------- #!/usr/bin/perl -w use strict; if (open F, "CFLAGS") { my @options; while (<F>) { chomp; s/#.*//; next unless /\S/; my $regex; if (s/^\{(.+?)\}\s*//) { $regex = qr/$1/; } elsif (s/^(\S+)\s*//) { $regex = qr/^\Q$1\E$/; } else { die "syntax error in CFLAGS: line $., $_\n"; } while (s/^([-+])\{(.+?)\}\s*//) { push @options, [ $regex, $1, $2 ]; } if (/\S/) { die "syntax error in CFLAGS: line $., $_\n"; } } my ($cfile) = grep /\.c$/, @ARGV; foreach my $option (@options) { if ($cfile =~ $option->[0]) { if ($option->[1] eq '+') { splice @ARGV, 1, 0, $option->[2]; } else { @ARGV = grep { $_ ne $option->[2] } @ARGV; } } } } print "@ARGV\n"; exec @ARGV; __END__ Cheers, -- Lars Balker Rasmussen Consult::Perl