… | |
… | |
64 | |
64 | |
65 | package ExtUtils::CXX; |
65 | package ExtUtils::CXX; |
66 | |
66 | |
67 | use common::sense; |
67 | use common::sense; |
68 | |
68 | |
69 | our $VERSION = 0.02; |
69 | our $VERSION = '1.0'; |
70 | |
70 | |
71 | use parent Exporter::; |
71 | use Exporter 'import'; |
72 | |
72 | |
73 | our @EXPORT = qw(extutils_cxx); |
73 | our @EXPORT = qw(extutils_cxx); |
|
|
74 | |
|
|
75 | use ExtUtils::MakeMaker::Config (); |
74 | |
76 | |
75 | =item extutils_cxx BLOCK; |
77 | =item extutils_cxx BLOCK; |
76 | |
78 | |
77 | This function temporarily does hideous things so you can call |
79 | This function temporarily does hideous things so you can call |
78 | C<WriteMakefile> or similar functions in the BLOCK normally. See the |
80 | C<WriteMakefile> or similar functions in the BLOCK normally. See the |
… | |
… | |
88 | xlc => "xlC", |
90 | xlc => "xlC", |
89 | cc => "g++", |
91 | cc => "g++", |
90 | c89 => "g++", |
92 | c89 => "g++", |
91 | ); |
93 | ); |
92 | |
94 | |
|
|
95 | our $PREFIX = qr{(?:\S+[\/\\])? (?:ccache|distcc)}x; |
|
|
96 | |
93 | sub _ccrepl { |
97 | sub _ccrepl { |
94 | my ($cfgvar, $env) = @_; |
98 | my ($cfgvar, $env) = @_; |
95 | |
99 | |
96 | my $tie = tied %Config; |
100 | my $tie = tied %Config; |
97 | |
101 | |
… | |
… | |
102 | if ($env) { |
106 | if ($env) { |
103 | $val =~ s/^\S+/$env/; |
107 | $val =~ s/^\S+/$env/; |
104 | } else { |
108 | } else { |
105 | keys %cc; |
109 | keys %cc; |
106 | while (my ($k, $v) = each %cc) { |
110 | while (my ($k, $v) = each %cc) { |
107 | $val =~ s/^ (\S*[\/\\])? $k (-|\s|\d|$) /$1$v$2/x |
111 | $val =~ s/^ ((?:$PREFIX\s+)? \S*[\/\\])? $k (-|\s|\d|$) /$1$v$2/x |
108 | and goto done; |
112 | and goto done; |
109 | } |
113 | } |
110 | |
114 | |
111 | $val =~ s/^\S+/g++/; |
115 | $val =~ s/^($PREFIX\s+)? \S+/$1g++/x; |
112 | |
116 | |
113 | done: ; |
117 | done: ; |
114 | } |
118 | } |
115 | |
119 | |
116 | $tie->{$cfgvar} = $val; |
120 | $tie->{$cfgvar} = $val; |
… | |
… | |
124 | |
128 | |
125 | my $tie = tied %Config; |
129 | my $tie = tied %Config; |
126 | |
130 | |
127 | # now dive into internals of Config and temporarily patch those values |
131 | # now dive into internals of Config and temporarily patch those values |
128 | |
132 | |
129 | $tie->{ld} = "/uasr/bin/gcc-4.6 -O"; |
|
|
130 | local $tie->{cc} = $Config{cc}; _ccrepl cc => "CXX"; |
133 | local $tie->{cc} = $Config{cc}; _ccrepl cc => "CXX"; |
131 | local $tie->{ld} = $Config{ld}; _ccrepl ld => ($ENV{PERL_CXXLD} ? "CXXLD" : "CXX"); |
134 | local $tie->{ld} = $Config{ld}; _ccrepl ld => ($ENV{PERL_CXXLD} ? "CXXLD" : "CXX"); |
|
|
135 | |
|
|
136 | local $ExtUtils::MakeMaker::Config::Config{cc} = $tie->{cc}; |
|
|
137 | local $ExtUtils::MakeMaker::Config::Config{ld} = $tie->{ld}; |
132 | |
138 | |
133 | eval { |
139 | eval { |
134 | $cb->(); |
140 | $cb->(); |
135 | }; |
141 | }; |
136 | die if $@; |
142 | die if $@; |