our
@ISA
=
qw/Mpp::CommandParser/
;
*factory
= \
&Mpp::Subs::p_swig
;
sub
new {
my
$self
=
&Mpp::CommandParser::new
;
$self
->{SCANNER} = new Mpp::Scanner::Swig(
$self
->rule,
$self
->dir);
$self
;
}
my
(
$cplusplus
,
$idash
,
$importall
,
$includeall
);
my
%opt
=
(
'c++'
=> \
$cplusplus
,
'I-'
=> \
$idash
,
importall
=> \
$importall
,
includeall
=> \
$includeall
);
$opt
{
$_
} = 1
for
qw(allegrocl chicken csharp guile java modula3 mzscheme ocaml
perl perl5 php php4 pike python ruby sexp tcl xml)
;
$opt
{
$_
} = 2
for
qw(MD MF MMD co dllimport dlname feature features generateconst
generaterename generatetypemap globals identifier-converter
interface module namespace outdir package prefix typemaplang
w withc withcxx withincs withlibs xmllang)
;
my
%info_string
= (
user
=>
'SWIG_INCLUDES'
,
sys
=>
'SWIG_SYSTEM_INCLUDES'
);
my
$swig_library_path
;
sub
xparse_command {
my
(
$self
,
$command
,
$setenv
) =
@_
;
my
@input_files
;
my
$output_file
;
my
@swig_libs
;
my
$swig_language
=
'tcl'
;
my
@includes
;
my
@defines
;
my
@files
;
$cplusplus
=
$idash
=
$importall
=
$includeall
= 0;
my
(
$swig_binary
,
@words
) =
@$command
;
local
$_
;
while
(
defined
(
$_
=
shift
@words
)) {
if
( !s/^-// ) {
push
@files
,
$_
;
}
elsif
(
$opt
{
$_
} ) {
if
(
ref
$opt
{
$_
} ) {
${
$opt
{
$_
}} = 1;
}
elsif
(
$opt
{
$_
} == 1 ) {
$swig_language
=
$_
;
}
else
{
shift
@words
;
}
}
elsif
( s/^l// ) {
push
@swig_libs
,
$_
;
}
elsif
( /^(?:oh?|xml(?:out)?)$/ ) {
$self
->add_target(
shift
@words
);
}
elsif
( s/^D// ) {
push
@defines
,
$_
;
}
elsif
( s/^I// ) {
push
@includes
,
$_
;
}
}
my
$scanner
=
$self
->{SCANNER};
$scanner
->{LANGUAGE} =
$swig_language
;
$scanner
->should_find(
"user"
);
$scanner
->info_string( \
%info_string
);
foreach
my
$def
(
@defines
) {
if
(
$def
=~ /^(\w+)=(.*)/) {
$scanner
->set_var($1, $2);
}
else
{
$scanner
->set_var(
$def
, 1);
}
}
$importall
and
$scanner
->{IMPORTALL} = 1;
$includeall
and
$scanner
->{INCLUDEALL} = 1;
my
$rule
=
$self
->rule;
$rule
->set_signature_class(
"c_compilation_md5"
);
$scanner
->set_var(
SWIG
=> 1);
$scanner
->set_var(
"SWIG"
.
uc
(
$swig_language
), 1);
$scanner
->set_var(
__STDC__
=> 1 );
$scanner
->set_var(
__cplusplus
=> 1)
if
$cplusplus
;
$swig_library_path
= Mpp::Subs::f_shell
"$swig_binary -swiglib"
,
$rule
->makefile,
$rule
->source
if
!
defined
$swig_library_path
;
$scanner
->add_include_dir(
"user"
,
undef
)
unless
$idash
;
foreach
my
$include
(
@includes
,
"."
,
"$swig_library_path"
) {
$scanner
->add_include_dir(
"user"
,
$include
);
$scanner
->add_include_dir(
"sys"
,
$include
);
my
$inc_swig_language
=
"$include/$swig_language"
;
if
( is_or_will_be_dir file_info
$inc_swig_language
) {
$scanner
->add_include_dir(
"user"
,
$inc_swig_language
);
$scanner
->add_include_dir(
"sys"
,
$inc_swig_language
);
}
}
my
$context
=
$scanner
->get_context;
foreach
my
$swig_lib
(
@swig_libs
) {
$scanner
->scan_file(
$self
,
"c"
,
"$swig_lib.i"
) or
return
undef
;
}
$scanner
->
reset
(
$context
);
foreach
my
$file
(
@files
) {
$scanner
->
reset
(
$context
);
$scanner
->scan_file(
$self
,
"c"
,
$file
) or
return
undef
;
}
return
1;
}
1;