# 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.
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 = ();
}
our %vars;
our %overriden;
our @postconfigs;
+our @atwrites;
sub debPrint() {
print "VARS:\n";
unshift @postconfigs, $_[0];
}
+sub AtWrite(&) {
+ unshift @atwrites, $_[0];
+}
+
sub Finish() {
for my $post (@postconfigs) {
&$post();
-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";
print X "o=obj\n";
close X;
Log "done\n";
+
+ for my $wr (@atwrites) {
+ &$wr();
+ }
}
sub TryCmd($) {
### OS ###
-package UCW::Configure::Autoconf;
+package UCW::Configure::C;
use UCW::Configure;
Test("OS", "Checking on which OS we run", sub {
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;