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