# Automatic configuration of the UCW Library
# (c) 2005 Martin Mares <mj@ucw.cz>
-Set("CC" => "gcc-3.0");
+### Compiler and its Options ###
+
+# Default compiler
+Test("CC", "Checking for C compiler", sub { return "gcc"; });
+
+# GCC version
+Test("GCCVER", "Checking for GCC version", sub {
+ my $gcc = Get("CC");
+ my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
+ chomp $ver;
+ Fail "Unable to determine GCC version" if $? || $ver eq "";
+ return $ver;
+});
# C flags: tell the compiler we're speaking C99
Set("CLANG" => "-std=gnu99");
Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
# Extra switches depending on GCC version:
-# [FIXME]
-#GCCVER:=$(shell $(CC) --version | sed '2,$$d; s/^\(.* \)\?\([0-9]*\.[0-9]*\).*/\2/')
-#ifeq ($(GCCVER),3.3)
-#CWARNS+=-Wundef -Wredundant-decls
-#COPT+=-finline-limit=20000 --param max-inline-insns-auto=1000
-#endif
-#ifeq ($(GCCVER),3.4)
-#CWARNS+=-Wundef -Wredundant-decls
-#COPT+=-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400
-#endif
-
-# If debugging:
-Set("CDEBUG" => '-DDEBUG_ASSERTS -ggdb');
-#CDEBUG+=-DDEBUG_DIE_BY_ABORT
+if (Get("GCCVER") eq "3.0") {
+} elsif (Get("GCCVER") eq "3.3") {
+ Append("CWARNS" => "-Wundef -Wredundant-decls");
+ Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
+} elsif (Get("GCCVER") eq "3.4") {
+ Append("CWARNS" => "-Wundef -Wredundant-decls");
+ Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
+} else {
+ Log "WARNING: Don't know anything about this GCC version, using default switches.\n";
+}
+
+if (IsSet("CONFIG_DEBUG")) {
+ # If debugging:
+ Set("DEBUG_ASSERTS");
+ Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
+ Set("CDEBUG" => "-ggdb");
+} else {
+ # If building a release version:
+ Append("COPT" => "-fomit-frame-pointer");
+ Append("LOPT" => "-s");
+}
# If debugging memory allocations:
#LIBS+=-lefence
#CDEBUG+=-DDEBUG_DMALLOC
#LIBS+=-ldmalloc
-# If building release versions:
-#CDEBUG=
-#COPT+=-fomit-frame-pointer
-#LOPT+=-s
-
### CPU Type and Features ###
-Set("CPU_ARCH" => 'i686');
+Set("CPU_ARCH" => 'i686') if !IsSet("CPU_ARCH");
Set("CPU_I386");
Set("CPU_LITTLE_ENDIAN");
#CPU_BIG_ENDIAN=1
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
$VERSION = 1.0;
@ISA = qw(Exporter);
- @EXPORT = qw(&Init &Log &Fail &IsSet &Set &UnSet &Override &Get &Test &Include &Finish &FindFile &TryFindFile);
+ @EXPORT = qw(&Init &Log &Notice &Fail &IsSet &Set &UnSet &Append &Override &Get &Test &Include &Finish &FindFile &TryFindFile);
@EXPORT_OK = qw();
%EXPORT_TAGS = ();
}
print @_;
}
+sub Notice($) {
+ print @_ if $vars{"VERBOSE"};
+}
+
sub Fail($) {
Log((shift @_) . "\n");
exit 1;
delete $vars{$x} unless $overriden{$x};
}
+sub Append($$) {
+ my ($x,$y) = @_;
+ Set($x, (IsSet($x) ? (Get($x) . " $y") : $y));
+}
+
sub Override($;$) {
my ($x,$y) = @_;
$y=1 unless defined $y;
sub Test($$$) {
my ($var,$msg,$sub) = @_;
- Log "$msg... ";
+ Log "$msg ... ";
if (!IsSet($var)) {
Set $var, &$sub();
}
sub Include($) {
my ($f) = @_;
$f = FindFile($f);
- Log "Loading configuration $f\n";
+ Notice "Loading configuration $f\n";
require $f;
}
-d "obj/lib" or mkdir("obj/lib", 0777) or Fail "Cannot create obj/lib directory: $!";
Log "done\n";
- Log "Generating autoconf.h... ";
+ Log "Generating autoconf.h ... ";
open X, ">obj/lib/autoconf.h" or Fail $!;
print X "/* Generated automatically by $0, please don't touch manually. */\n";
foreach my $x (sort keys %vars) {
close X;
Log "done\n";
- Log "Generating config.mk... ";
+ Log "Generating config.mk ... ";
open X, ">obj/config.mk" or Fail $!;
print X "# Generated automatically by $0, please don't touch manually.\n";
foreach my $x (sort keys %vars) {