]> mj.ucw.cz Git - libucw.git/blob - lib/autoconf.cfg
Added bit_array_assign(), replaced BIT_ARRAY_ALLOC by functions.
[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("ARCH", "Checking for machine 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                 return "i386";
44         } elsif ($mach =~ /^(x86[_-]|amd)64$/) {
45                 return "amd64";
46         } else {
47                 return "unknown";
48         }
49 });
50
51 Test("CPU_ARCH", "Checking for CPU architecture", sub {
52         my $mach = Get("ARCH");
53         if ($mach eq "i386") {
54                 Set("CPU_I386");
55                 UnSet("CPU_64BIT_POINTERS");
56                 Set("CPU_LITTLE_ENDIAN");
57                 UnSet("CPU_BIG_ENDIAN");
58                 Set("CPU_ALLOW_UNALIGNED");
59                 Set("CPU_STRUCT_ALIGN" => 4);
60                 my $arch = "";
61                 if (IsSet("CONFIG_EXACT_CPU") && IsSet("CONFIG_LINUX") && open X, "/proc/cpuinfo") {
62                         my %pc = ();
63                         while (<X>) {
64                                 chomp;
65                                 /^$/ && last;
66                                 /^([^\t]+)\t+:\s*(.*)$/ and $pc{$1}=$2;
67                         }
68                         close X;
69
70                         # Try to understand CPU vendor, family and model [inspired by MPlayer's configure script]
71                         my $vendor = $pc{'vendor_id'} || "";
72                         my $family = $pc{'cpu family'} || 0;
73                         my $model  = $pc{'model'} || 0;
74                         if ($vendor eq "AuthenticAMD") {
75                                 if ($family >= 6) {
76                                         if ($model >= 31 && $gccver >= 3004) { $arch = "athlon64"; }
77                                         elsif ($model >= 6 && $gccver >= 3003) { $arch = "athlon-xp"; }
78                                         else { $arch = "athlon"; }
79                                 }
80                         } elsif ($vendor eq "GenuineIntel") {
81                                 # We don't recognize Prescott and Nocona cores yet (gcc-3.4+)
82                                 if ($family >= 15 && $gccver >= 3003) { $arch = "pentium4"; }
83                                 elsif ($family >= 6 && $gccver >= 3003) {
84                                         if ($model >= 7) { $arch = "pentium3"; }
85                                         elsif ($model >= 3) { $arch = "pentium2"; }
86                                 }
87                         }
88
89                         # No match on vendor, try the family
90                         if ($arch eq "") {
91                                 if ($family >= 6) {
92                                         $arch = "i686";
93                                 } elsif ($family >= 3) {
94                                         $arch = "i${family}86";
95                                 }
96                         }
97                         if ($arch ne "") {
98                                 Log "(using /proc/cpuinfo) ";
99                         } else {
100                                 Log "(don't understand /proc/cpuinfo) ";
101                         }
102                 }
103                 return $arch ? $arch : "i386";
104         } elsif ($mach eq "amd64") {
105                 Set("CPU_AMD64");
106                 Set("CPU_64BIT_POINTERS");
107                 Set("CPU_LITTLE_ENDIAN");
108                 UnSet("CPU_BIG_ENDIAN");
109                 Set("CPU_ALLOW_UNALIGNED");
110                 Set("CPU_STRUCT_ALIGN" => 8);
111                 return "x86-64";
112         } else {
113                 return undef;
114         }
115 });
116
117 if (!IsSet("CPU_ARCH")) { Warn "CPU type not recognized, using defaults, keep fingers crossed."; }
118
119 ### Compiler and its Options ###
120
121 # C flags: tell the compiler we're speaking C99
122 Set("CLANG" => "-std=gnu99");
123
124 # C optimizations
125 Set("COPT" => '-O2');
126 Append("COPT", '-march=$(CPU_ARCH)') if IsSet("CPU_ARCH");
127
128 # C optimizations for highly exposed code
129 Set("COPT2" => '-O3');
130
131 # Warnings
132 Set("CWARNS" => '-Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline');
133 Set("CWARNS_OFF" => '');
134
135 # Linker flags
136 Set("LOPT" => "");
137
138 # Extra libraries
139 Set("LIBS" => "");
140
141 # Extra flags for compiling and linking shared libraries
142 Set("CSHARED" => '-fPIC');
143 Set("LSHARED" => '-shared -Wl,-soname,lib/$(@F)');
144
145 # Extra switches depending on GCC version:
146 if ($gccver == 3000) {
147         Append("COPT" => "-fstrict-aliasing");
148 } elsif ($gccver == 3003) {
149         Append("CWARNS" => "-Wundef -Wredundant-decls");
150         Append("COPT" => "-finline-limit=20000 --param max-inline-insns-auto=1000");
151 } elsif ($gccver == 3004) {
152         Append("CWARNS" => "-Wundef -Wredundant-decls");
153         Append("COPT" => "-finline-limit=2000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
154 } elsif ($gccver == 4000) {
155         Append("CWARNS" => "-Wundef -Wredundant-decls -Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers");
156         Append("CWARNS_OFF" => "-Wno-pointer-sign");
157         Append("COPT" => "-finline-limit=5000 --param large-function-insns=5000 --param inline-unit-growth=200 --param large-function-growth=400");
158 } else {
159         Warn "Don't know anything about this GCC version, using default switches.\n";
160 }
161
162 if (IsSet("CONFIG_DEBUG")) {
163         # If debugging:
164         Set("DEBUG_ASSERTS");
165         Set("DEBUG_DIE_BY_ABORT") if Get("CONFIG_DEBUG") > 1;
166         Set("CDEBUG" => "-ggdb");
167 } else {
168         # If building a release version:
169         Append("COPT" => "-fomit-frame-pointer");
170         Append("LOPT" => "-s");
171 }
172
173 # Decide how will lib/partmap.c work
174 Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
175
176 # If debugging memory allocations:
177 #LIBS+=-lefence
178 #CDEBUG+=-DDEBUG_DMALLOC
179 #LIBS+=-ldmalloc
180
181 # Return success
182 1;