test: Move test_data_file() to test.h
[dpkg.git] / scripts / Build.PL.in
blob76fb04e542c5019b532bb2ccaf071ba7020a8ddb
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 eval {
7 require Module::Build;
8 } or do {
9 die "error: Missing Module::Build module, cannot proceed.\n";
12 if (-e 'Build.PL.in') {
13 die "error: This is an in-tree build, not a proper perl distribution.\n" .
14 "To create one please configure normally and then run 'make dist'.\n";
17 my $class = Module::Build->subclass(
18 class => 'Module::Build::Dpkg',
19 code => q{
20 require Config;
21 require IPC::Cmd;
23 sub find_command {
24 my (@alts) = @_;
26 foreach my $cmd (@alts) {
27 my $pathname = IPC::Cmd::can_run($cmd);
28 return $pathname if defined $pathname;
30 die "error: cannot find any of @alts\n";
33 sub subst {
34 my ($self, $file) = @_;
35 my $path = $self->install_path();
36 my $version = $self->dist_version();
38 my $progmake = find_command(qw(gmake make));
39 my $progpatch = find_command(qw(gpatch patch));
40 my $progtar = find_command(qw(gtar tar));
42 unlink "blib/$file"
43 or die "error: cannot remove blib/$file: $!\n";
44 open my $fhin, '<', $file
45 or die "error: cannot open $file: $!\n";
46 open my $fhout, '>', "blib/$file"
47 or die "error: cannot create blib/$file: $!\n";
48 while (<$fhin>) {
49 s{our \$PROGVERSION = .*;}{our \$PROGVERSION = '$version';};
50 s{our \$PROGMAKE = .*;}{our \$PROGMAKE = '$progmake';};
51 s{our \$PROGPATCH = .*;}{our \$PROGPATCH = '$progpatch';};
52 s{our \$PROGTAR = .*;}{our \$PROGTAR = '$progtar';};
53 s{our \$CONFDIR = .*;}{our \$CONFDIR = '$path->{conf}';};
54 s{our \$DATADIR = .*;}{our \$DATADIR = '$path->{data}';};
55 s{our \$ADMINDIR = .*;}{our \$ADMINDIR = '$path->{admin}';};
56 s{our \$LIBDIR = .*;}{our \$LIBDIR = '$path->{libexec}';};
57 print { $fhout } $_;
59 close $fhout or die "error: cannot write blib/$file: $!\n";
60 close $fhin;
63 sub ACTION_build {
64 my $self = shift;
66 $self->SUPER::ACTION_build;
67 $self->subst('lib/Dpkg.pm');
69 sub ACTION_test {
70 my $self = shift;
72 local $ENV{LC_ALL} = 'C';
73 local $ENV{PERL} = $Config::Config{perlpath} || $^X || 'perl';
74 local $ENV{DPKG_TEST_MODE} = 'cpan';
75 local $ENV{DPKG_DATADIR} = 'data';
76 local $ENV{DPKG_ORIGINS_DIR} = 't/origins';
77 # To avoid requiring dpkg(1).
78 local $ENV{DEB_BUILD_ARCH} = 'amd64';
79 $self->SUPER::ACTION_test;
84 my $build = $class->new(
85 dist_name => '@PACKAGE_CPAN_NAME@',
86 dist_abstract => 'Debian Package Manager Perl modules',
87 dist_version => '@PACKAGE_VERSION@',
88 dist_author => '@PACKAGE_COPYRIGHT_HOLDER@ <@PACKAGE_BUGREPORT@>',
89 license => 'GPL_2',
91 release_status => @PACKAGE_DIST_IS_RELEASE@ ? 'stable' : 'testing',
93 # Set only to avoid warnings.
94 module_name => '@PACKAGE_CPAN_NAME@',
96 meta_merge => {
97 'meta-spec' => {
98 version => 2,
100 prereqs => {
101 configure => {
102 recommends => {
103 'Module::Signature' => 0,
106 test => {
107 recommends => {
108 'Test::Pod' => 0,
109 'Test::Strict' => 0,
112 develop => {
113 recommends => {
114 'Test::MinimumVersion' => 0,
115 'Test::Perl::Critic' => 0,
116 'Test::Pod::Coverage' => 0,
117 'Test::Spelling' => 0,
118 'Test::Synopsis' => 0,
122 resources => {
123 homepage => '@PACKAGE_URL@',
124 repository => {
125 type => '@PACKAGE_VCS_TYPE@',
126 url => '@PACKAGE_VCS_URL@',
127 web => '@PACKAGE_VCS_WEB@',
129 bugtracker => {
130 web => '@PACKAGE_BUG_WEB@',
133 keywords => [ qw(dpkg debian perl) ],
136 sign => @PACKAGE_DIST_IS_RELEASE@,
137 dynamic_config => 0,
139 configure_requires => {
140 'Module::Build' => '0.4004',
142 test_requires => {
143 'TAP::Harness' => 0,
144 'Test::More' => 0,
146 recommends => {
147 'Algorithm::Merge' => 0,
148 'File::FcntlLock' => 0,
149 'Locale::gettext' => 0,
152 requires => {
153 'perl' => '@PERL_MIN_VERSION@',
156 data_files => {
157 map { $_ => $_ } glob 'data/*'
159 install_path => {
160 conf => '/etc/dpkg',
161 data => '/usr/share/dpkg',
162 admin => '/var/lib/dpkg',
163 libexec => '/usr/lib/dpkg',
167 $build->add_build_element('data');
168 $build->create_build_script();