]> mj.ucw.cz Git - libucw.git/commitdiff
Configure: Introduce AtWrite hooks and handle autoconf.h by them.
authorMartin Mares <mj@ucw.cz>
Thu, 30 Oct 2008 21:24:46 +0000 (22:24 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 30 Oct 2008 21:24:46 +0000 (22:24 +0100)
ucw/perl/UCW/Configure.pm
ucw/perl/UCW/Configure/C.pm

index 2657a6309e2a152493567e216c6c41895f62ea3c..27e9a364422b1c712d0c572661a10dc2ec79f832 100644 (file)
@@ -1,6 +1,6 @@
 #      Perl module for UCW Configure Scripts
 #
-#      (c) 2005 Martin Mares <mj@ucw.cz>
+#      (c) 2005--2008 Martin Mares <mj@ucw.cz>
 #
 #      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($) {
index fbfab6318a2d6abb7974207915d23a362bff2b7b..eb30caee8ff467535cb7dd5960146ec46be7cbe4 100644 (file)
@@ -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;