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