1 # Perl module for UCW Configure Scripts
3 # (c) 2005 Martin Mares <mj@ucw.cz>
5 # This software may be freely distributed and used according to the terms
6 # of the GNU Lesser General Public License.
8 package UCW::Configure;
14 # The somewhat hairy Perl export mechanism
16 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19 @EXPORT = qw(&Init &Log &Fail &IsSet &Set &UnSet &Override &Get &Test &Include);
32 Log((shift @_) . "\n");
38 return exists $vars{$x};
48 $y=1 unless defined $y;
49 $vars{$x}=$y unless $overriden{$x};
54 delete $vars{$x} unless $overriden{$x};
59 $y=1 unless defined $y;
65 my ($var,$msg,$sub) = @_;
77 } elsif ($f !~ /^\// && -f (Get("SRCDIR")."/$f")) {
78 return Get("SRCDIR")."/$f";
87 defined ($F = TryFindFile($f)) or Fail "Cannot find file $f";
92 my ($srcdir,$defconfig) = @_;
93 if ((!defined $defconfig && !@ARGV) || @ARGV && $ARGV[0] eq "--help") {
94 print STDERR "Usage: [<srcdir>/]configure " . (defined $defconfig ? "[" : "") . "<config-name>" . (defined $defconfig ? "]" : "") .
95 " [<option>[=<value>] | -<option>] ...\n";
98 if (@ARGV && $ARGV[0] !~ /=/) {
99 Set('CONFIG' => shift @ARGV);
101 Set('CONFIG' => $defconfig);
103 Set("SRCDIR", $srcdir);
105 foreach my $x (@ARGV) {
106 if ($x =~ /^(\w+)=(.*)/) {
108 } elsif ($x =~ /^-(\w+)$/) {
111 } elsif ($x =~ /^(\w+)$/) {
114 print STDERR "Invalid option $_\n";
119 if (!TryFindFile(Get("CONFIG"))) {
120 TryFindFile(Get("CONFIG")."/config") or Fail "Cannot find configuration " . Get("CONFIG");
121 Override("CONFIG" => Get("CONFIG")."/config");
128 Log "Loading configuration $f\n";