1 # Automatic configuration of the UCW Library
2 # (c) 2005 Martin Mares <mj@ucw.cz>
6 Test("OS", "Checking on which OS we run", sub {
9 Fail "Unable to determine OS type" if $? || $os eq "";
13 if (Get("OS") eq "Linux") {
16 Fail "Don't know how to run on this operating system.";
21 Test("CPU_ARCH", "Checking for CPU architecture", sub {
22 my $mach = `uname -m`;
24 Fail "Unable to determine machine type" if $? || $mach eq "";
25 if ($mach =~ /^i[0-9]86$/) {
28 if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
33 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
36 if ($pc{'vendor_id'} eq "AuthenticAMD" && $pc{'cpu family'} >= 6) {
40 Log "(according to /proc/cpuinfo) ";
42 Log "(don't understand /proc/cpuinfo) ";
45 return $arch ? $arch : "i386";
50 if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
52 ### Compiler and its Options ###
55 Test("CC", "Checking for C compiler", sub { return "gcc"; });
58 Test("GCCVER", "Checking for GCC version", sub {
60 my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
62 Fail "Unable to determine GCC version" if $? || $ver eq "";
66 # C flags: tell the compiler we're speaking C99
67 Set("CLANG" => "-std=gnu99");
70 Set("COPT" => '-O2 -fstrict-aliasing -march=$(CPU_ARCH)');
71 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
73 # C optimizations for highly exposed code
74 Set("COPT2" => '-O3');
77 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
85 # Extra flags for compiling and linking shared libraries
86 Set("CSHARED" => '-fPIC');
87 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
89 # Extra switches depending on GCC version:
90 if (Get("GCCVER") eq "3.0") {
91 } elsif (Get("GCCVER") eq "3.3") {
92 Append("CWARNS" => "-Wundef -Wredundant-decls");
93 Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
94 } elsif (Get("GCCVER") eq "3.4") {
95 Append("CWARNS" => "-Wundef -Wredundant-decls");
96 Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
98 Warn "Don't know anything about this GCC version, using default switches.\n";
101 if (IsSet("CONFIG_DEBUG")) {
103 Set("DEBUG_ASSERTS");
104 Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
105 Set("CDEBUG" => "-ggdb");
107 # If building a release version:
108 Append("COPT" => "-fomit-frame-pointer");
109 Append("LOPT" => "-s");
112 # If debugging memory allocations:
114 #CDEBUG+=-DDEBUG_DMALLOC
117 ### CPU Type and Features ###
119 Set("CPU_LITTLE_ENDIAN");
121 Set("CPU_ALLOW_UNALIGNED");
122 Set("CPU_STRUCT_ALIGN" => 4);
123 Set("CPU_64BIT_POINTERS");