]> mj.ucw.cz Git - leo.git/blob - perl/UCW/Configure/LibUCW.pm
Updated UCW::Configure to the version from current LibUCW
[leo.git] / perl / UCW / Configure / LibUCW.pm
1 # UCW Library configuration system: parameters of the library
2 # (c) 2005--2012 Martin Mares <mj@ucw.cz>
3 # (c) 2006 Robert Spalek <robert@ucw.cz>
4 # (c) 2008 Michal Vaner <vorner@ucw.cz>
5
6 package UCW::Configure::LibUCW;
7 use UCW::Configure;
8
9 use strict;
10 use warnings;
11
12 # Turn on debugging support if CONFIG_DEBUG
13 if (Get("CONFIG_DEBUG")) {
14         Set("CONFIG_UCW_DEBUG");
15 }
16
17 # Determine page size
18 Test("CPU_PAGE_SIZE", "Determining page size", sub {
19         my $p;
20         if (IsSet("CONFIG_DARWIN")) {
21                 $p = `sysctl -n hw.pagesize`;
22                 defined $p or Fail "sysctl hw.pagesize failed";
23         } elsif (IsSet("CONFIG_LINUX")) {
24                 $p = `getconf PAGE_SIZE`;
25                 defined $p or Fail "getconf PAGE_SIZE failed";
26         }
27         chomp $p;
28         return $p;
29 });
30
31 # Decide how will ucw/partmap.c work
32 Set("CONFIG_UCW_PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS");
33
34 # Option for ucw/mempool.c
35 Set("CONFIG_UCW_POOL_IS_MMAP");
36
37 # Guess optimal bit width of the radix-sorter
38 Test("CONFIG_UCW_RADIX_SORTER_BITS", "Determining radix sorter bucket width", sub {
39         if (Get("CPU_AMD64")) {
40                 # All amd64 CPUs have large enough L1 cache
41                 return 12;
42         } else {
43                 # This should be safe everywhere
44                 return 10;
45         }
46 });
47
48 # Detect if thread-local storage is supported
49 if (Get("CONFIG_UCW_THREADS")) {
50         TestBool("CONFIG_UCW_TLS", "Checking if GCC supports thread-local storage", sub {
51                 if (UCW::Configure::C::TestCompile("__thread", "__thread int i;\nint main(void) { return 0; }\n")) {
52                         return 1;
53                 } else {
54                         return 0;
55                 }
56         });
57 }
58
59 # Detect if we have the epoll() syscall
60 TestBool("CONFIG_UCW_EPOLL", "Checking for epoll", sub {
61         return UCW::Configure::C::TestCompile("epoll", <<'FINIS' ) ? 1 : 0;
62 #include <sys/epoll.h>
63 int main(void)
64 {
65         epoll_create(256);
66         return 0;
67 }
68 FINIS
69 });
70
71 # Check if we want to use monotonic clock
72 TestBool("CONFIG_UCW_MONOTONIC_CLOCK", "Checking for monotonic clock", sub {
73         return Get("CONFIG_LINUX");
74 });
75
76 if (IsSet("CONFIG_DARWIN")) {
77         # Darwin does not support BSD regexes, fix up
78         if (!IsSet("CONFIG_UCW_POSIX_REGEX") && !IsSet("CONFIG_UCW_PCRE")) {
79                 Set("CONFIG_UCW_POSIX_REGEX" => 1);
80                 Warn "BSD regex library on Darwin isn't compatible, using POSIX regex.\n";
81         }
82
83         # Fill in some constants not found in the system header files
84         Set("SOL_TCP" => 6);            # missing in /usr/include/netinet/tcp.h
85         if (IsGiven("CONFIG_UCW_DIRECT_IO") && IsSet("CONFIG_UCW_DIRECT_IO")) {
86                 Fail("Direct I/O is not available on darwin");
87         } else {
88                 UnSet("CONFIG_UCW_DIRECT_IO");
89         }
90 }
91
92 PostConfig {
93         AtWrite {
94                 UCW::Configure::C::ConfigHeader("ucw/autoconf.h", [
95                         # Included symbols
96                         '^CONFIG_UCW_' => 1,
97                         '^CPU_' => 1,
98                         '^UCW_VERSION(_|$)' => 1,
99                 ]);
100         } if Get("CONFIG_INSTALL_API");
101
102         # Include direct FB?
103         if (!IsSet("CONFIG_UCW_THREADS") || !IsSet("CONFIG_UCW_DIRECT_IO")) {
104                 if (IsGiven("CONFIG_UCW_FB_DIRECT") && IsSet("CONFIG_UCW_FB_DIRECT")) {
105                         if (!IsSet("CONFIG_UCW_THREADS")) {
106                                 Fail("CONFIG_UCW_FB_DIRECT needs CONFIG_UCW_THREADS");
107                         } else {
108                                 Fail("CONFIG_UCW_FB_DIRECT needs CONFIG_UCW_DIRECT_IO");
109                         }
110                 }
111                 UnSet("CONFIG_UCW_FB_DIRECT");
112         }
113 };
114
115 # We succeeded
116 1;