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