-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.PL
262 lines (218 loc) · 6.67 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# Copyright 2022 cPanel, LLC. (copyright@cpanel.net)
# Author: Felipe Gasper
#
# Copyright (c) 2022, cPanel, LLC.
# All rights reserved.
# http://cpanel.net
#
# This is free software; you can redistribute it and/or modify it under the
# same terms as Perl itself. See L<perlartistic>.
use strict;
use warnings;
use ExtUtils::MakeMaker::CPANfile;
use ExtUtils::PkgConfig;
use ExtUtils::CBuilder;
use File::Temp;
my ($modversion, $libs, @iculibs, @inc_extra);
print "First let’s see if your pkg-config knows about “icu” …\n";
if ($libs = ExtUtils::PkgConfig->libs("icu")) {
$modversion = ExtUtils::PkgConfig->modversion('icu');
print "… found it! (ICU $modversion)\n";
@iculibs = qw(icu);
}
else {
my @LIBS = qw( i18n uc );
#push @LIBS, 'io'; # debug
print "Doesn’t look like it. How about “icu-$LIBS[0]” et al.?\n";
@iculibs = map { "icu-$_" } @LIBS;
$libs = ExtUtils::PkgConfig->libs("@iculibs");
if ($libs) {
$modversion = ExtUtils::PkgConfig->modversion($iculibs[0]);
print "… found it! (ICU $modversion)\n";
}
else{
die "Your pkg-config can’t find ICU. Is it installed?\n";
}
}
my ($major_version) = ($modversion =~ m<\A([0-9]+)>);
if ($major_version >= 59) {
print "Your ICU version ($modversion) needs C++11.\n";
@inc_extra = (
'-std=c++11',
'-Wno-c++11-extensions',
'-Wno-c++11-long-long',
);
if ($^V lt v5.20.0) {
print "Your perl ($^V) is old enough that its headers conflict with\n";
print "C++11’s user-defined literals. Disabling that feature …\n";
# In pre-5.20 perls the header files don’t always have spaces
# around macros like “UVxf”, which C++11 invalidated. So we need
# to tell the compiler to allow that:
push @inc_extra, (
'-Wno-reserved-user-defined-literal', # clang
'-Wno-literal-suffix', # g++
);
}
}
else {
print "Your ICU version ($modversion) doesn’t need C++11.\n";
}
my $cflags = ExtUtils::PkgConfig->cflags("@iculibs") || q<>;
print "cflags: $cflags\n";
print "libs: $libs\n";
my $cc = 'c++';
system $cc, '-v';
#my $basic_inc = "-Wall -I. -Werror=vla @inc_extra $cflags";
my $basic_inc = "-Wall -I. @inc_extra $cflags";
my @defines = _determine_defines($basic_inc, $libs);
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Unicode::ICU',
VERSION_FROM => 'lib/Unicode/ICU.pm', # finds $VERSION
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Unicode/ICU.pm', # retrieve abstract from module
AUTHOR => [
'cPanel, L.L.C. (CPANEL)',
],
) : ()
),
LIBS => $libs,
DEFINE => '',
INC => "@defines $basic_inc",
LICENSE => "perl_5",
CC => $cc,
LD => '$(CC)',
XSOPT => '-C++',
OBJECT => join(
q< >,
'$(BASEEXT)$(OBJ_EXT)',
'unicode_icu.o',
'unicode_icu_messagepattern.o',
),
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => 'git://github.com/cpanel/p5-Unicode-ICU.git',
web => 'https://github.com/cpanel/p5-Unicode-ICU',
},
bugtracker => {
web => 'https://github.com/cpanel/p5-Unicode-ICU/issues',
},
},
},
);
sub _determine_defines {
my $inc = shift;
my $lflags = shift;
my $builder = ExtUtils::CBuilder->new(
config => {
cc => "$cc $inc -Wno-unused-variable",
ld => $cc,
},
);
my @defines;
my @checks = (
{
label => 'UIDNA object',
define => 'UICU_HAS_UIDNA_OBJECT',
c => q[
#include <unicode/uidna.h>
int main() {
void *ptr = (void*) uidna_openUTS46;
return 0;
}
],
},
{
label => 'UIDNA_CHECK_CONTEXTO',
define => 'UICU_HAS_UIDNA_CHECK_CONTEXTO',
c => q[
#include <unicode/uidna.h>
int main() {
int foo = UIDNA_CHECK_CONTEXTO;
return 0;
}
],
},
{
label => 'MessagePattern',
define => 'UICU_HAS_MESSAGEPATTERN',
c => q[
#include <unicode/messagepattern.h>
int main() {
return 0;
}
],
},
{
label => 'UMSGPAT_ARG_TYPE_SELECTORDINAL',
define => 'UICU_HAS_UMSGPAT_ARG_TYPE_SELECTORDINAL',
c => q[
#include <unicode/messagepattern.h>
int main() {
int foo = UMSGPAT_ARG_TYPE_SELECTORDINAL;
return 0;
}
],
},
{
label => 'ListFormatter',
define => 'UICU_CAN_FORMAT_LISTS',
c => q[
#include <unicode/ulistformatter.h>
int main() {
void *p = (void*) ulistfmt_open;
return 0;
}
],
},
{
label => 'ListFormatter-or',
define => 'UICU_CAN_FORMAT_OR',
c => q[
#include <unicode/ulistformatter.h>
int main() {
int what = ULISTFMT_TYPE_OR;
return 0;
}
],
},
);
my $dir = File::Temp::tempdir( CLEANUP => 1 );
my $i = 0;
for my $check_hr (@checks) {
++$i;
_note("Checking: $check_hr->{'label'}");
my $path = "$dir/source-$i.cc";
open my $fh, '>', $path;
syswrite($fh, $check_hr->{'c'});
close $fh;
my $obj_file = eval {
$builder->compile(
source => $path,
);
};
my $supported;
if ($obj_file) {
my $lib_file = eval {
$builder->link(
objects => $obj_file,
extra_linker_flags => $lflags,
);
};
if ($lib_file) {
$supported = 1;
push @defines, $check_hr->{'define'};
}
}
my $result = ($supported ? q<> : 'NOT ') . 'supported';
_note("\t$check_hr->{'label'}: $result");
}
return map { "-D$_" } @defines;
}
sub _note {
print "===== @_$/";
}