Alien-Base-ModuleBuild
view release on metacpan or search on metacpan
lib/Alien/Base/ModuleBuild/FAQ.pod view on Meta::CPAN
# Build.PL
use Alien::Base::ModuleBuild;
use Config;
Alien::Base::ModuleBuild->new(
...
alien_bin_requires => {
'Alien::CMake' => 0.07,
},
alien_build_commands => [
# acutal required arguments may vary
"cmake -G 'Unix Makefiles' -DCMAKE_MAKE_PROGRAM=$Config{make} -DCMAKE_INSTALL_PREFIX:PATH=%s",
"$Config{make}",
],
alien_install_commands => [
"$Config{make} install",
],
...
)->create_build_script;
=head3 vanilla Makefiles?
If you want to use the same C<make> as Perl, you can use L<Config>:
# Build.PL
use Alien::Base::ModuleBuild;
use Config;
Alien::Base::ModuleBuild->new(
...
alien_build_commands => [
"$Config{make}",
],
alien_install_commands => [
"$Config{make} install",
],
...
)->create_build_script;
=head3 GNU Makefiles?
Some packages require GNU Make's unique syntax. Perl's L<Config> provides an entry for C<gmake>, but it is
frequently wrong. Do not depend on it. Instead you can use L<Alien::gmake> to provide a real GNU Make (either
from the operating system, or built from source):
# Build.PL
use Alien::Base::ModuleBuild;
Alien::Base::ModuleBuild->new(
...
alien_bin_requires => {
'Alien::gmake' => 0.11, # needed for %{gmake} helper
},
alien_build_commands => [
"%{gmake}",
],
alien_install_commands => [
"%{gmake} install",
],
...
)->create_build_script;
=head2 When debugging my package build, I get different results!
If you get results from running the commands in your shell different to what happens when your C<Alien::>
distribution attempts to build, it may be because your environment is different than the one that your
distribution is using. For example, if you use L<Alien::CMake> or L<Alien::gmake> to build with specific tools
that are provided by your operating system, L<Alien::Base::ModuleBuild> will adjust the path before executing
build and install commands.
In the alien build directory (usually C<_alien>) you will find environment files that you can source
into your shell (C<env.csh> for tcsh and C<env.sh> for bourne based shells), which should provide the
identical environment used by the build process in order to troubleshoot the build manually.
% source _alien/env.sh
=head2 Can/Should I write a tool oriented Alien module using C<Alien::Base> that provides executables instead of a library?
Certainly. The original intent was to provide libraries, but tools are also quite doable using the
C<Alien::Base> tool set. A simple minded example of this which is fairly easy to replicate is L<Alien::m4>.
In general, this means specifying a subclass in your C<Build.PL> and bundling it in your distribution C<inc> directory.
C<Build.PL>:
...
use lib 'inc';
use My::ModuleBuild;
My::ModuleBuild->new(
...
)->create_build_script;
C<inc/My/ModuleBuild.pm>:
package My::ModuleBuild;
use strict;
use warnings;
use parent 'Alien::Base::ModuleBuild';
use Capture::Tiny qw( capture );
sub alien_check_installed_version
{
# see Alien::Base::ModuleBuild#alien_check_installed_version for details
my($self) = @_;
my($stdout, $stderr) = capture { system 'mytool', '--version' };
# return empty list if the tool is unavailable on the system,
# or unacceptable.
return if $! || ...;
# parse from stdout or stderr
my $version = ...;
return $version;
}
sub alien_check_built_version
{
# see Alien::Base::ModuleBuild#alien_check_built_version for details
# return empty list if the tool version cannot be found, or if it
( run in 0.547 second using v1.01-cache-2.11-cpan-0bd6704ced7 )