From: Martin Mares Date: Thu, 30 Oct 2008 21:24:46 +0000 (+0100) Subject: Configure: Introduce AtWrite hooks and handle autoconf.h by them. X-Git-Tag: holmes-import~227^2~5^2~7 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=72fed97042cf09d12c7a2445f636694bc891fa48;p=libucw.git Configure: Introduce AtWrite hooks and handle autoconf.h by them. --- diff --git a/ucw/perl/UCW/Configure.pm b/ucw/perl/UCW/Configure.pm index 2657a630..27e9a364 100644 --- a/ucw/perl/UCW/Configure.pm +++ b/ucw/perl/UCW/Configure.pm @@ -1,6 +1,6 @@ # Perl module for UCW Configure Scripts # -# (c) 2005 Martin Mares +# (c) 2005--2008 Martin Mares # # This software may be freely distributed and used according to the terms # of the GNU Lesser General Public License. @@ -16,7 +16,7 @@ BEGIN { our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.0; @ISA = qw(Exporter); - @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &IsGiven &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile &TryCmd &PkgConfig &TrivConfig &debPrint); + @EXPORT = qw(&Init &Log &Notice &Warn &Fail &IsSet &IsGiven &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile &TryCmd &PkgConfig &TrivConfig &debPrint, &PostConfig, &AtWrite); @EXPORT_OK = qw(); %EXPORT_TAGS = (); } @@ -24,6 +24,7 @@ BEGIN { our %vars; our %overriden; our @postconfigs; +our @atwrites; sub debPrint() { print "VARS:\n"; @@ -162,6 +163,10 @@ sub PostConfig(&) { unshift @postconfigs, $_[0]; } +sub AtWrite(&) { + unshift @atwrites, $_[0]; +} + sub Finish() { for my $post (@postconfigs) { &$post(); @@ -187,20 +192,6 @@ sub Finish() { -d "obj/ucw" or mkdir("obj/ucw", 0777) or Fail "Cannot create obj/ucw directory: $!"; Log "done\n"; - Log "Generating autoconf.h ... "; - open X, ">obj/autoconf.h" or Fail $!; - print X "/* Generated automatically by $0, please don't touch manually. */\n"; - foreach my $x (sort keys %vars) { - # Don't export variables which contain no underscores - next unless $x =~ /_/; - my $v = $vars{$x}; - # Try to add quotes if necessary - $v = '"' . $v . '"' unless ($v =~ /^"/ || $v =~ /^\d*$/); - print X "#define $x $v\n"; - } - close X; - Log "done\n"; - Log "Generating config.mk ... "; open X, ">obj/config.mk" or Fail $!; print X "# Generated automatically by $0, please don't touch manually.\n"; @@ -211,6 +202,10 @@ sub Finish() { print X "o=obj\n"; close X; Log "done\n"; + + for my $wr (@atwrites) { + &$wr(); + } } sub TryCmd($) { diff --git a/ucw/perl/UCW/Configure/C.pm b/ucw/perl/UCW/Configure/C.pm index fbfab631..eb30caee 100644 --- a/ucw/perl/UCW/Configure/C.pm +++ b/ucw/perl/UCW/Configure/C.pm @@ -5,7 +5,7 @@ ### OS ### -package UCW::Configure::Autoconf; +package UCW::Configure::C; use UCW::Configure; Test("OS", "Checking on which OS we run", sub { @@ -242,5 +242,40 @@ if (IsSet("CONFIG_DARWIN")) { Set("SOL_TCP" => 6); # missing in /usr/include/netinet/tcp.h } +### Writing C headers with configuration ### + +sub ConfigHeader($$) { + my ($hdr, $rules) = @_; + Log "Generating $hdr ... "; + open X, ">obj/$hdr" or Fail $!; + print X "/* Generated automatically by $0, please don't touch manually. */\n"; + + sub match_rules($) { + my ($name) = @_; + for (my $i=0; $i < scalar @$rules; $i++) { + my ($r, $v) = ($rules->[$i], $rules->[$i+1]); + return $v if $name =~ $r; + } + return 0; + } + + foreach my $x (sort keys %UCW::Configure::vars) { + next unless match_rules($x); + my $v = $UCW::Configure::vars{$x}; + # Try to add quotes if necessary + $v = '"' . $v . '"' unless ($v =~ /^"/ || $v =~ /^\d*$/); + print X "#define $x $v\n"; + } + close X; + Log "done\n"; +} + +AtWrite { + ConfigHeader("autoconf.h", [ + # Symbols with "_" anywhere in their name are exported + "_" => 1 + ]); +}; + # Return success 1;