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
|
use 5.008;
use strict;
package MY;
use ExtUtils::MakeMaker;
use Config;
my $csubdir = 'sombok';
my $sombok_atleast_version = '2.3.2';
my $sombok_max_version = '2.99.99';
my $pkg_config = $ENV{'PKG_CONFIG'} || 'pkg-config';
my $enable_libthai = 1;
my $libthai_inc = '';
my $libthai_libs = '';
my $bundled_sombok = 0;
my $unicode;
my $unicode_num;
my $copy_unidata = 0;
my $sombok;
my $libthai;
sub clean {
my $inherited = shift->SUPER::clean(@_);
$inherited =~ s{(\n*)\z}
{\n\t\$(RM_F) $csubdir\$(DIRFILESEP)Makefile.PL $csubdir\$(DIRFILESEP)include\$(DIRFILESEP)sombok.h $csubdir\$(DIRFILESEP)lib\$(DIRFILESEP)*\$(OBJ_EXT)$1};
$inherited;
}
sub test {
my $inherited = shift->SUPER::test(@_);
# Get UNIDATA before testing.
$inherited =~ s/^(test\s*:+\s*)/${1}copy_unidata /m
if $copy_unidata;
$inherited;
}
sub distdir {
my $inherited = shift->SUPER::distdir(@_);
if ($copy_unidata) {
open my $mani, '<', 'MANIFEST' or die "$!";
$inherited =~ s/^(distdir\s*:+\s*)/${1}copy_unidata /m
if scalar grep m{^test-data/LineBreakTest.txt}, <$mani>;
close $mani;
}
$inherited;
}
sub postamble {
my $self = shift;
my $cd_make = $self->cd($csubdir, '$(MAKE) all');
my $make_json = $self->cd(q{$(DISTVNAME)},
q{$(FULLPERL) -MCPAN::Meta -MCPAN::Meta::Converter -e 'CPAN::Meta->new(CPAN::Meta::Converter->new(CPAN::Meta->load_file("META.yml"))->convert(version=>"2"))->save("META.json")'}
);
my $make_rpm_spec = $self->cd(q{$(DISTVNAME)},
q{$(FULLPERL) -i -pe 's/^(%define version\s+).*/$${1}$(VERSION)/; s/^(%define sombok_version\s+).*/$${1}}
. $sombok_atleast_version . q{/' perl-Unicode-LineBreak.spec});
return <<EOF;
\$(MYEXTLIB): $csubdir\$(DIRFILESEP)Makefile
\t$cd_make
copy_unidata :
\tcd test-data; \\
\t[ -f LineBreakTest.txt ] || \\
\twget -q -N -O LineBreakTest.txt \\
\tftp://unicode.org/Public/$unicode_num/ucd/auxiliary/LineBreakTest*.txt \\
\t|| \$(NOOP)
\tcd test-data; \\
\t[ -f GraphemeBreakTest.txt ] || \\
\twget -q -N -O GraphemeBreakTest.txt \\
\tftp://unicode.org/Public/$unicode_num/ucd/auxiliary/GraphemeBreakTest*.txt \\
\t|| \$(NOOP)
preop :
\t$make_json
\t$make_rpm_spec
EOF
}
if (open my $fp, '<', "$csubdir/UNICODE") {
$unicode = <$fp>;
$unicode =~ s/\s+$//;
close $fp;
}
foreach my $arg (@ARGV) {
if ($arg eq '--disable-libthai') {
$enable_libthai = 0;
} elsif ($arg eq '--with-bundled-sombok') {
$bundled_sombok = 1;
} elsif ($arg =~ /^--with-unicode-version=(\S+)$/) {
$unicode = $1;
}
}
$unicode_num = $unicode;
$unicode_num =~ s/[^.\d].*//;
my %opts = ('LIBS' => '', 'INC' => '');
$enable_libthai = 0 if system("$pkg_config --exists libthai") >> 8;
if ($enable_libthai) {
$libthai = `$pkg_config --modversion libthai`;
chomp $libthai;
my $ver;
if ($libthai and $libthai =~ m{^(\d+)\.(\d+)(?:\.(\d+))?}) {
$ver = $1 + $2 * 0.001 + ($3 || 0) * 0.000001;
}
unless ($ver and 0.001009 <= $ver) {
printf
"Version of your libthai is %s. 0.1.9 or later is required. Update it or specify --disable-libthai option.\n",
($libthai || $ver);
exit 1;
}
print "Use libthai $libthai\n";
$libthai_libs = `$pkg_config --libs libthai`;
chomp $libthai_libs;
$libthai_inc = `$pkg_config --cflags libthai`;
chomp $libthai_inc;
}
if (system("$pkg_config --atleast-version=$sombok_atleast_version sombok")
>> 8 or
system("$pkg_config --max-version=$sombok_max_version sombok") >> 8) {
$bundled_sombok = 1;
}
if ($bundled_sombok) {
if (open my $fp, '<', "$csubdir/VERSION") {
$sombok = <$fp>;
close $fp;
$sombok =~ s/\s+$//;
$sombok ||= 'bundled';
}
print "Use bundled sombok $sombok with Unicode $unicode\n";
# create sombok/Makefile.PL
unlink "$csubdir/Makefile" if -e "$csubdir/Makefile";
open my $fp, '<', 'Makefile.PL.sombok' or die $!;
my $h = join '', <$fp>;
close $fp;
$h =~ s/\@LIBTHAI_INC\@/$libthai_inc/g;
$h =~ s/\@UNICODE_VERSION\@/$unicode/g;
open my $ofp, '>', "$csubdir/Makefile.PL" or die $!;
print $ofp $h;
close $ofp;
# create sombok/include/sombok.h
open my $fp, '<', "$csubdir/include/sombok.h.in" or die $!;
my $h = join '', <$fp>;
close $fp;
$h =~ s/#ifdef HAVE_CONFIG_H/#if 1/;
if ($enable_libthai) {
$h =~ s{\"config.h\"}
{\"EXTERN.h\"\n#include \"perl.h\"\n#include \"XSUB.h\"\n#define USE_LIBTHAI \"libthai/$libthai\"};
} else {
$h =~ s{\"config.h\"}
{\"EXTERN.h\"\n#include \"perl.h\"\n#include \"XSUB.h\"\n#undef USE_LIBTHAI};
}
$h =~ s/\@SOMBOK_UNICHAR_T\@/U32/;
$h =~ s/\@PACKAGE_VERSION\@/$sombok/;
$h =~ s/\@SOMBOK_UNICHAR_T_IS_WCHAR_T\@//;
$h =~ s/\@SOMBOK_UNICHAR_T_IS_UNSIGNED_INT\@//;
$h =~ s/\@SOMBOK_UNICHAR_T_IS_UNSIGNED_LONG\@//;
open my $ofp, '>', "$csubdir/include/sombok.h" or die $!;
print $ofp $h;
close $ofp;
#XXXmy $define = ($^O eq 'MSWin32') ? '-DMSDOS' : '';
my $myextlib;
if ($^O eq 'MSWin32') {
$myextlib = 'sombok\\libsombok$(LIB_EXT)';
} elsif ($^O eq 'darwin' && $Config{'ldflags'} =~ /-arch ppc64/) {
$myextlib = '-all_load sombok/libsombok$(LIB_EXT)';
} else {
$myextlib = 'sombok/libsombok$(LIB_EXT)';
}
$opts{'MYEXTLIB'} = $myextlib;
$opts{'INC'} .= " -I$csubdir\$(DIRFILESEP)include";
$opts{'depend'} = {'$(OBJECT)' => '$(MYEXTLIB)'};
} else {
$sombok = `$pkg_config --modversion sombok`;
chomp $sombok;
print "Use sombok $sombok\n";
$opts{'LIBS'} .= ' ' . `$pkg_config --libs sombok`;
$opts{'INC'} .= ' ' . `$pkg_config --cflags sombok`;
}
if ($enable_libthai) {
$opts{'LIBS'} .= ' ' . $libthai_libs;
$opts{'INC'} .= ' ' . $libthai_inc;
}
$opts{'LIBS'} =~ s/\s+/ /g;
$opts{'INC'} =~ s/\s+/ /g;
$copy_unidata = (!-e "test-data/LineBreakTest.txt" ||
!-e "test-data/GraphemeBreakTest.txt");
WriteMakefile(
'NAME' => 'Unicode::LineBreak',
'ABSTRACT_FROM' => 'lib/Unicode/LineBreak.pod',
'VERSION_FROM' => 'lib/Unicode/LineBreak.pm',
'AUTHOR' => q{Hatuka*nezumi - IKEDA Soji <hatuka@nezumi.nu>},
'LICENSE' => 'perl',
'MIN_PERL_VERSION' => 5.008,
'CONFIGURE_REQUIRES' => {'ExtUtils::MakeMaker' => '6.26',},
'BUILD_REQUIRES' => {
'ExtUtils::MakeMaker' => '6.26',
'Test::More' => '0.45',
},
'PREREQ_PM' => {
'Encode' => 1.98,
'MIME::Charset' => '1.006.2',
},
'META_MERGE' => {
'resources' => {
'license' => 'http://dev.perl.org/licenses/',
'repository' => 'https://github.com/hatukanezumi/Unicode-LineBreak/',
},
},
%opts,
'dist' => {'PREOP' => "\$(MAKE) preop",},
);
|