Salvador "Fandiño <***@yahoo.com> writes:
>Hi,
>
>Now that 5.8.2 has been released, Michael G Schwern has accepted to
>consider my patch to add support for C++ modules for inclusion on
>MakeMaker but he has requested me to get it reviewed by somebody on
>here first so...
>
>A new version of the patch is available from here:
> http://www.nondoc.org/perl/cxx-0.10.patch.gz
>
>C++ modules are expected to contain a .xss file instead of the usual
>.xs one. That file is preprocessed by xsubpp to a .cpp file and then
>compiled by the C++ compiler.
Good patch in general - a few questions/comments:
xsubpp has a -C++ option - is the some reason that you don't use
that when processing a .xss file ?
(I forget what it does in detail but I have found it useful in the past.)
+ # Use some heuristics to find the C++ compiler and linker:
+
+ if ( $Config{ccname} =~ /gcc/i) {
+ my($vol, $dir, $file) = File::Spec->splitpath($self->{CC});
+ $self->{CXX} ||= $dir eq '' ? 'c++' : File::Spec->join($vol, $dir, 'c++');
+ $self->{CXXLD} ||= $self->{CXX};
+ } else {
+ $self->{CXX} ||= $self->{CC};
+ $self->{CXXLD} ||= $self->{LD};
+ }
+
If $Config{cc} is 'gcc' you should probaly try/use 'g++' - there may be
a system c++ which does not match the gcc.
+This target is stubbed out. Not sure why.
+
+=cut
+
+sub xss_o {
+ return ''
+}
+
I think because you get less re-re-builds if the rules stack.
i.e. one rule
.xss -> .cpp
and then one
.cpp -> .o
and let make figure out to chain the two rules.
If you do a direct .xss -> .o rule as well make can get confused as
to which one to use, it may depend if an old .cpp is about from
an prior run and the guts of rules must match.
+=item CXXLD
+
+Program to be used to link C++ libraries for dynamic loading.
+
+Defaults to $Config{ld}.
I think it should default to being the compiler you found i.e. CXXCMD.
>
>Two new variables can be used on Makefile.PL: CXX to set the C++
>compiler and CXXLD to set the linker to be used for C++ modules. As
>there isn't any information available from Config.pm about the C++
>compiler, linker, libs, etc., I had to use some heuristics to find
>default values for those variables from the C config. Also, new hints
>should be added for compilers others than gcc and MSVC and support
>for other vars (CXXFLAGS, CXXLIBS?) could be needed.
>
>The user can also set CXX and CXXLD himself when running Makefile.PL
>from the command line (or even set them on CPAN.pm config).
>
>Deducting C++ compiler config from info on Config.pm is not bullet
>proof but the only alternative would be to run some kind of
>auto-config process, that doesn't seem easy to implement... any
>volunteer?
It isn't too hard to have/write a tiny C++ file and "try" the c++ command
you find.
open(my $fh,">test.cpp") || die;
print $fh <<'END';
#include <iostream>
int main(int argc,char *argv[])
{
std::cout << "It works\n";
return 0;
}
END
close($fh);
if (system($cpp_to_try,"test.cpp") == 0)
{
# that will do
}