]> git.vpit.fr Git - perl/modules/re-engine-Hooks.git/blob - Makefile.PL
Add BUILD_REQUIRES to WriteMakefile()
[perl/modules/re-engine-Hooks.git] / Makefile.PL
1 use 5.010001;
2
3 use strict;
4 use warnings;
5 use ExtUtils::MakeMaker;
6
7 my $dist = 're-engine-Hooks';
8
9 (my $name = $dist) =~ s{-}{::}g;
10
11 (my $file = $dist) =~ s{-}{/}g;
12 $file = "lib/$file.pm";
13
14 my %PREREQ_PM = (
15  'Carp'       => 0,
16  'DynaLoader' => 0,
17 );
18
19 my %BUILD_REQUIRES = (
20  'ExtUtils::Depends'   => 0,
21  'ExtUtils::MakeMaker' => 0,
22  'File::Spec'          => 0,
23  'POSIX'               => 0,
24  'Test::More'          => 0,
25  'blib'                => 0,
26  %PREREQ_PM,
27 );
28
29 my %META = (
30  configure_requires => {
31   'ExtUtils::Depends'   => 0,
32   'ExtUtils::MakeMaker' => 0,
33   'File::Spec'          => 0,
34  },
35  build_requires => {
36   %BUILD_REQUIRES,
37  },
38  dynamic_config => 1,
39  resources => {
40   bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist",
41   homepage   => "http://search.cpan.org/dist/$dist/",
42   license    => 'http://dev.perl.org/licenses/',
43   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
44  },
45 );
46
47 sub versioned_file {
48  my ($file) = @_;
49
50  my $version = "$]";
51  $version    =~ s/\.//g;
52  my $len     = length $version;
53  if ($len > 7) {
54   die "Invalid perl version";
55  } else {
56   $version .= '0' x (7 - $len);
57  }
58
59  require File::Spec;
60  my $versioned_file = File::Spec->catfile('src', $version, $file);
61
62  return -e $versioned_file ? [ $file => $versioned_file ] : undef;
63 }
64
65 unless (defined versioned_file('regcomp.c')) {
66  print STDERR <<EOF;
67      This version of perl ($]) is not supported by this version of
68      re::engine::Hooks. If your perl has been recently released,
69      make sure there isn't a newer version of the module available
70      on the CPAN.
71 EOF
72  exit 0;
73 }
74
75 my @DEFINES = qw<-DPERL_EXT_RE_BUILD -DPERL_EXT>;
76 @DEFINES    = (DEFINE => join ' ', @DEFINES) if @DEFINES;
77
78 use ExtUtils::Depends;
79
80 my $ed = ExtUtils::Depends->new($name);
81 $ed->add_c('regcomp.c');
82 $ed->add_c('regexec.c');
83 $ed->add_xs('Hooks.xs');
84 $ed->add_pm($file => do { local $_ = $file; s/^lib/\$(INST_LIB)/; $_ });
85 $ed->install('re_engine_hooks.h');
86 $ed->save_config('Files.pm');
87
88 my %ed_vars = $ed->get_makefile_vars;
89 $ed_vars{clean}->{FILES} .= ' ' . join ' ', (
90  "$dist-*",
91  'Files.pm',
92  qw<*.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt>,
93  qw<regcomp.c regexec.c dquote_static.c inline_invlist.c>,
94 );
95
96 WriteMakefile(
97  NAME             => $name,
98  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
99  LICENSE          => 'perl',
100  VERSION_FROM     => $file,
101  ABSTRACT_FROM    => $file,
102  PL_FILES         => {},
103  BUILD_REQUIRES   => \%BUILD_REQUIRES,
104  PREREQ_PM        => \%PREREQ_PM,
105  MIN_PERL_VERSION => '5.010001',
106  META_MERGE       => \%META,
107  dist             => {
108   PREOP    => "pod2text $file > \$(DISTVNAME)/README",
109   COMPRESS => 'gzip -9f', SUFFIX => 'gz'
110  },
111  XSPROTOARG       => '-noprototypes',
112  @DEFINES,
113  FUNCLIST         => [ qw<
114   boot_re__engine__Hooks
115   reh_register
116  > ],
117  %ed_vars,
118 );
119
120 {
121  my $args_dat = './args.dat';
122
123  open my $fh, '>', $args_dat or die "open(>$args_dat): $!";
124  for (@ARGV) {
125   my $arg = $_;
126   $arg =~ s{\s*(['"])\s*(.*)\s*\1\s*$}{$2}s;
127   $arg =~ s{([^=/.a-zA-Z0-9-])}{sprintf "[%d]", ord $1}ge;
128   print $fh "$arg\n";
129  }
130 }
131
132 package MY;
133
134 sub postamble {
135  my $regcomp_c        = main::versioned_file('regcomp.c');
136  my $regexec_c        = main::versioned_file('regexec.c');
137  my $dquote_static_c  = main::versioned_file('dquote_static.c');
138  my $inline_invlist_c = main::versioned_file('inline_invlist.c');
139
140  my @all_c          = ($regcomp_c, $regexec_c);
141  my @regcomp_c_deps = ('regcomp.c');
142  my @regexec_c_deps = ('regexec.c');
143
144  for my $extra_c ($dquote_static_c, $inline_invlist_c) {
145   next unless defined $extra_c;
146   push @all_c,           $extra_c;
147   push @regcomp_c_deps, $extra_c->[0];
148  }
149
150  my $rules;
151
152  for my $file_c (@all_c) {
153   my ($target_file, $versioned_file) = @$file_c;
154   $rules .= <<"RULE";
155 $target_file : $versioned_file
156         - \$(RM_F) $target_file
157         \$(CP) $versioned_file $target_file
158
159 RULE
160  }
161
162  $rules .= <<"RULE";
163 regcomp\$(OBJ_EXT) : @regcomp_c_deps
164
165 regexec\$(OBJ_EXT) : @regexec_c_deps
166
167 RULE
168
169  $rules .= <<'EOF';
170 configure_test.pl: args.dat
171
172 t/re-engine-Hooks-TestDist/Makefile: configure_test.pl
173         $(FULLPERLRUN) configure_test.pl
174
175 all clean:: t/re-engine-Hooks-TestDist/Makefile
176         cd t/re-engine-Hooks-TestDist && $(MAKE) $@
177
178 clean::
179         $(RM_RF) args.dat
180
181 EOF
182
183  return $rules;
184 }