]> mj.ucw.cz Git - libucw.git/blob - lib/autoconf.cfg
Even better CPU checks, this time taking into account GCC version.
[libucw.git] / lib / autoconf.cfg
1 # Automatic configuration of the UCW Library
2 # (c) 2005 Martin Mares <mj@ucw.cz>
3
4 ### OS ###
5
6 Test("OS", "Checking on which OS we run", sub {
7         my $os = `uname`;
8         chomp $os;
9         Fail "Unable to determine OS type" if $? || $os eq "";
10         return $os;
11 });
12
13 if (Get("OS") eq "Linux") {
14         Set("CONFIG_LINUX");
15 } else {
16         Fail "Don't know how to run on this operating system.";
17 }
18
19 ### Compiler ###
20
21 # Default compiler
22 Test("CC", "Checking for C compiler", sub { return "gcc"; });
23
24 # GCC version
25 Test("GCCVER", "Checking for GCC version", sub {
26         my $gcc = Get("CC");
27         my $ver = `$gcc --version | sed '2,\$d; s/^\\(.* \\)\\?\\([0-9]*\\.[0-9]*\\).*/\\2/'`;
28         chomp $ver;
29         Fail "Unable to determine GCC version" if $? || $ver eq "";
30         return $ver;
31 });
32 my ($gccmaj, $gccmin) = split(/\./, Get("GCCVER"));
33 my $gccver = 1000*$gccmaj + $gccmin;
34 $gccver >= 3000 or Fail "GCC older than 3.0 doesn't support C99 well enough.";
35
36 ### CPU ###
37
38 Test("CPU_ARCH", "Checking for CPU architecture", sub {
39         my $mach = `uname -m`;
40         chomp $mach;
41         Fail "Unable to determine machine type" if $? || $mach eq "";
42         if ($mach =~ /^i[0-9]86$/) {
43                 Set("CPU_I386");
44                 my $arch = "";
45                 if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
46                         my %pc = ();
47                         while (<X>) {
48                                 chomp;
49                                 /^$/ && last;
50                                 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
51                         }
52                         close X;
53
54                         # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
55                         my $vendor = $pc{'vendor_id'} || "";
56                         my $family = $pc{'cpu family'} || 0;
57                         my $model  = $pc{'model'} || 0;
58                         if ($vendor eq "AuthenticAMD") {
59                                 if ($family >= 6) {
60                                         if ($model >= 31 && $gccver >= 3003) { $arch = "athlon64"; }
61                                         elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
62                                         else { $arch = "athlon"; }
63                                 }
64                         } elsif ($vendor eq "GenuineIntel") {
65                                 # We don't recognize Prescott and Nocona cores yet (gcc-3.4+)
66                                 if ($family >= 15 && $gccver >= 3003) { $arch = "pentium4"; }
67                                 elsif ($family >= 6 && $gccver >= 3003) {
68                                         if ($model >= 7) { $arch = "pentium3"; }
69                                         elsif ($model >= 3) { $arch = "pentium2"; }
70                                 }
71                         }
72
73                         # No match on vendor, try the family
74                         if ($arch eq "") {
75                                 if ($family >= 6) {
76                                         $arch = "i686";
77                                 } elsif ($family >= 3) {
78                                         $arch = "i${family}86";
79                                 }
80                         }
81                         if ($arch ne "") {
82                                 Log "(using /proc/cpuinfo) ";
83                         } else {
84                                 Log "(don't understand /proc/cpuinfo) ";
85                         }
86                 }
87                 return $arch ? $arch : "i386";
88         } else {
89                 return "unknown";
90         }
91 });
92 if (Get("CPU_ARCH") eq "unknown") { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
93
94 ### Compiler and its Options ###
95
96 # C flags: tell the compiler we're speaking C99
97 Set("CLANG" => "-std=gnu99");
98
99 # C optimizations
100 Set("COPT" => '-O2 -fstrict-aliasing');
101 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
102
103 # C optimizations for highly exposed code
104 Set("COPT2" => '-O3');
105
106 # Warnings
107 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
108
109 # Linker flags
110 Set("LOPT" => "");
111
112 # Extra libraries
113 Set("LIBS" => "");
114
115 # Extra flags for compiling and linking shared libraries
116 Set("CSHARED" => '-fPIC');
117 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
118
119 # Extra switches depending on GCC version:
120 if ($gccver == 3000) {
121 } elsif ($gccver == 3003) {
122         Append("CWARNS" => "-Wundef -Wredundant-decls");
123         Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
124 } elsif ($gccver == 3004) {
125         Append("CWARNS" => "-Wundef -Wredundant-decls");
126         Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
127 } else {
128         Warn "Don't know anything about this GCC version, using default switches.\n";
129 }
130
131 if (IsSet("CONFIG_DEBUG")) {
132         # If debugging:
133         Set("DEBUG_ASSERTS");
134         Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
135         Set("CDEBUG" => "-ggdb");
136 } else {
137         # If building a release version:
138         Append("COPT" => "-fomit-frame-pointer");
139         Append("LOPT" => "-s");
140 }
141
142 # If debugging memory allocations:
143 #LIBS+=-lefence
144 #CDEBUG+=-DDEBUG_DMALLOC
145 #LIBS+=-ldmalloc
146
147 ### CPU Type and Features ###
148
149 Set("CPU_LITTLE_ENDIAN");
150 #CPU_BIG_ENDIAN=1
151 Set("CPU_ALLOW_UNALIGNED");
152 Set("CPU_STRUCT_ALIGN" => 4);
153 Set("CPU_64BIT_POINTERS");
154
155 # Return success
156 1;