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
|
use vars qw(%param %param_xs $ostype);
init_param();
add_ccflags('-Werror');
#add_ccflags('-DNDEBUG'); # uncomment for release,
#include_test();
do_mediate();
use ExtUtils::MakeMaker;
WriteMakefile(%param,%param_xs);
sub include_test
{
$param_xs{'CCFLAGS'} .= '-g -DTEST=1';
$param_xs{'OBJECT'} .= ' test.o';
}
#
# mediate.h/mediate.cpp ���
sub do_mediate
{
# check @ARGV
my @arg;
@ARGV = grep{ !(@arg-push(@arg,/^(PurePerl|NoXS)(=(0|1|yes|no|y|n))?$/i)) } @ARGV;
if( @arg )
{
my $v = $arg[1] ? $arg[2] : '1';
if( $v eq '1' || $v eq 'y' || $v eq 'yes' )
{
print "install with PurePerl mode\n";
disable_xs();
return;
}
}
$ostype = `uname -s` || '';
if( $ostype =~ /(Linux)/ )
{
$ostype = $1;
}elsif( $ostype =~ /(BSD)/ )
{
$ostype = $1;
$hdr = "#include <fcntl.h>\n\n";
}elsif( $ostype =~ /(SunOS)/ )
{
$ostype = $1;
$hdr = "#include <fcntl.h>\n\n";
}elsif( !$ostype )
{
print "Here environment cannot use XS.\n";
disable_xs();
return;
}
if( $] < 5.006 )
{
/`/;
$hdr .= <<'EOF';
#define aTHX_
#define pTHX_
#define dTHX_
#define get_av(var_name,create_flag) perl_get_av(var_name,create_flag);
#ifndef newSVpvn
#define newSVpvn(str,len) newSVpv(str,len)
#endif
EOF
if( $] < 5.005 )
{
# PL_na���äƤ⤤�����ɤष���Ȥ�ʤ�������.
$hdr .= <<'EOF';
#ifndef PL_sv_undef
#define PL_sv_undef sv_undef
#endif
EOF
} # if( $] < 5.005 )
/`/;
} # if( $] < 5.006 )
use FileHandle;
my $fh_hdr = new FileHandle('>mediate.h');
my $fh_cpp = new FileHandle('>mediate.cpp');
if( !$fh_hdr || !$fh_cpp )
{
die 'cannot open mediate.h or .cpp for output';
}
$hdr = "/* nothing is needed. */\n" unless( $hdr );
$cpp = "/* nothing is needed. */\n" unless( $cpp );
print $fh_cpp <<EOF;
#include "Japanese.h"
$cpp
EOF
print $fh_hdr <<EOF;
#ifndef MEDIATE_H__
#define MEDIATE_H__
$hdr
#endif
EOF
# compile check.
my $cmd = "$param_xs{CC} -shared -c xs_test.c";
print "Checking XS Compiling... : $cmd\n";
my $rc = 0xffff & system($cmd);
if( $rc )
{
if( $rc == 0xffff )
{
print "Here environment cannot use XS.\n";
print "Because : command failed : $!\n";
disable_xs();
return;
}elsif( $rc > 0x80 )
{
print "Here environment cannot use XS.\n";
print "Because : ran with non-zero exit status $rc\n";
disable_xs();
return;
}elsif( $rc & 0x80 )
{
$rc &= ~0x80;
print "Compile failed..\n";
print "Because : ran with coredump from signal $rc\n";
exit 1;
}else
{
print "Compile failed..\n";
print "Because : ran with signal $rc\n";
exit 1;
}
}
unlink('xs_test.o');
}
sub disable_xs
{
use ExtUtils::Manifest;
$ExtUtils::Manifest::MANIFEST = 'MANIFEST.noxs';
%param_xs = ('linkext'=>{'LINKTYPE'=>''});
#rename('Japanese','Japanese-notused');
}
sub init_param
{
my $cc = 'g++';
my $ld = $cc;
@ARGV = grep{ /^CC=(.*)/ ? !($cc=$1) : 1 } @ARGV;
my $object = join(' ',qw( Japanese.o memmap.o conv.o ucs2_utf8.o
getcode.o getcode_map.o sjis.o eucjp.o jis.o
sjis_imode.o sjis_jsky.o sjis_doti.o
mediate.o
) );
%param = (
'NAME' => 'Unicode::Japanese',
'VERSION_FROM' => 'Japanese.pm', # finds $VERSION
'PREREQ_PM' => {}, # e.g., Module::Name => 1.1
'LIBS' => [''], # e.g., '-lm'
'DEFINE' => '', # e.g., '-DHAVE_SOMETHING'
'INC' => '', # e.g., '-I/usr/include/other'
);
%param_xs = (
'EXE_FILES' => ['Japanese/u2s-s2u.dat','Japanese/emoji.dat'],
'INSTALLSCRIPT' => '$(INST_LIBDIR)',
'CC' => $cc,
'CCFLAGS' => '-Wall',
'LD' => $ld,
'OBJECT' => $object,
'XS' => {'Japanese.xs','Japanese.c',},
'XSOPT'=>'-C++',
'XSPROTOARG'=>'-prototypes',
'clean' => { FILES => 'mediate.{cpp,h}' },
);
}
sub add_ccflags
{
$param_xs{'CCFLAGS'} = join(' ',$param_xs{'CC_FLAGS'},@_);
}
|