]> mj.ucw.cz Git - libucw.git/blob - ucw/perl/UCW/Configure/LibUCW.pm
Config: Regularized configuration of regex libs
[libucw.git] / ucw / perl / UCW / Configure / LibUCW.pm
1 # UCW Library configuration system: parameters of the library
2 # (c) 2005--2010 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 if (Get("CPU_ARCH") eq "default" || Get("CPU_ARCH") =~ /^i[345]86$/) {
39         # This should be safe everywhere
40         Set("CONFIG_UCW_RADIX_SORTER_BITS" => 10);
41 } else {
42         # Use this on modern CPU's
43         Set("CONFIG_UCW_RADIX_SORTER_BITS" => 12);
44 }
45
46 # Detect if thread-local storage is supported
47 if (Get("CONFIG_UCW_THREADS")) {
48         TestBool("CONFIG_UCW_TLS", "Checking if GCC supports thread-local storage", sub {
49                 if (UCW::Configure::C::TestCompile("__thread", "__thread int i;\nint main(void) { return 0; }\n")) {
50                         return 1;
51                 } else {
52                         return 0;
53                 }
54         });
55 }
56
57 # Detect if we have the epoll() syscall
58 TestBool("CONFIG_UCW_EPOLL", "Checking for epoll", sub {
59         return UCW::Configure::C::TestCompile("epoll", <<'FINIS' ) ? 1 : 0;
60 #include <sys/epoll.h>
61 int main(void)
62 {
63         epoll_create(256);
64         return 0;
65 }
66 FINIS
67 });
68
69 # Darwin does not support BSD regexes, fix up
70 if (IsSet("CONFIG_DARWIN")) {
71         if (!IsSet("CONFIG_UCW_POSIX_REGEX") && !IsSet("CONFIG_UCW_PCRE")) {
72                 Set("CONFIG_UCW_POSIX_REGEX" => 1);
73                 Warn "BSD regex library on Darwin isn't compatible, using POSIX regex.\n";
74         }
75 }
76
77 PostConfig {
78         AtWrite {
79                 UCW::Configure::C::ConfigHeader("ucw/autoconf.h", [
80                         # Included symbols
81                         '^CONFIG_UCW_' => 1,
82                         '^CPU_' => 1,
83                         '^(SHERLOCK|UCW)_VERSION(_|$)' => 1,
84
85                 ]);
86         } if Get("CONFIG_INSTALL_API");
87
88         # Include direct FB?
89         if (!IsSet("CONFIG_UCW_THREADS") || !IsSet("CONFIG_UCW_DIRECT_IO")) {
90                 if (IsGiven("CONFIG_UCW_FB_DIRECT") && IsSet("CONFIG_UCW_FB_DIRECT")) {
91                         if (!IsSet("CONFIG_UCW_THREADS")) {
92                                 Fail("CONFIG_UCW_FB_DIRECT needs CONFIG_UCW_THREADS");
93                         } else {
94                                 Fail("CONFIG_UCW_FB_DIRECT needs CONFIG_UCW_DIRECT_IO");
95                         }
96                 }
97                 UnSet("CONFIG_UCW_FB_DIRECT");
98         }
99 };
100
101 # We succeeded
102 1;