Skip to content

Commit 97d7985

Browse files
authored
pptemplate improvements (#539)
1 parent 27c0139 commit 97d7985

File tree

2 files changed

+121
-15
lines changed

2 files changed

+121
-15
lines changed

lib/PDL/PP.pod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ but the modules using this method are very hard to make installable.
4242

4343
=item Write a Makefile.PL to compile in advance
4444

45-
The section L</"MAKEFILES FOR PP FILES"> gives an example how to add
46-
directives to your F<Makefile.PL> so that your C code will be compiled
47-
when you build your module.
45+
The script L<pptemplate> can create a directory structure for a module
46+
containing a .pd file, including a F<Makefile.PL>. This is
47+
recommended for new PDL::PP modules.
48+
49+
For more details about this method, the section L</"MAKEFILES FOR PP
50+
FILES"> gives an example how to add directives to your F<Makefile.PL>
51+
so that your C code will be compiled when you build your module.
4852

4953
=back
5054

script/pptemplate

Lines changed: 114 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!perl -w
1+
#!perl
22

33
use strict;
44
use warnings;
@@ -90,13 +90,13 @@ WriteMakefile(
9090
MIN_PERL_VERSION => '5.016',
9191
LICENSE=> 'perl',
9292
PREREQ_PM => {
93-
'PDL::Basic' => '2.096', # deep mode
93+
'PDL' => '2.096', # deep mode
9494
},
9595
CONFIGURE_REQUIRES => {
96-
'PDL::Basic' => '2.096',
96+
'PDL' => '2.096',
9797
},
9898
BUILD_REQUIRES => {
99-
'PDL::Basic' => '2.096',
99+
'PDL' => '2.096',
100100
},
101101
TEST_REQUIRES => {
102102
'Test::More' => '0.88', # done_testing
@@ -117,6 +117,76 @@ sub postamble { ::pdlpp_postamble(\@pd_srcs) }
117117
EOM
118118
}
119119

120+
sub pdManifest {
121+
my ($pdname) = @_;
122+
my $pd_dir = dirname $pdname;
123+
return <<"END_OF_MANIFEST";
124+
$pdname
125+
Makefile.PL
126+
MANIFEST
127+
MANIFEST.SKIP
128+
t/basic.t
129+
END_OF_MANIFEST
130+
}
131+
132+
sub pdManifest_skip {
133+
my ($pdname,$dir) = @_;
134+
my $pd_dir = dirname $pdname;
135+
my $bare_name = $pdname =~ s/\.pd$//r;
136+
return <<"SKIP_PROJECT" . <<'SKIP_GENERAL';
137+
# This project's temporary files
138+
^$bare_name(\\.(pm|xs|c)|-pp-)
139+
$pd_dir/.*\\.(bs|o)\$
140+
$dir-.*\\.tar\\.gz
141+
SKIP_PROJECT
142+
143+
# Version control
144+
^.git
145+
146+
# Avoid Makemaker generated and utility files
147+
^Makefile$
148+
\bMANIFEST\.bak
149+
\bblib/
150+
\bMakeMaker-\d
151+
\bpm_to_blib\.ts$
152+
\bpm_to_blib$
153+
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
154+
^MYMETA
155+
156+
# Avoid temp and backup files.
157+
~$
158+
\.old$
159+
\#$
160+
\b\.#
161+
\.bak$
162+
\.swp$
163+
SKIP_GENERAL
164+
}
165+
166+
sub pdGitignore {
167+
my ($pdname,$dir) = @_;
168+
my $base_name = $pdname =~ s/\.pd$//r;
169+
return <<"GIT_PROJECT" . <<'GIT_GENERAL';
170+
# This project's temporary files
171+
$base_name.pm
172+
*-pp-*.c
173+
$base_name.bs
174+
$base_name.c
175+
$base_name.o
176+
$base_name.xs
177+
$dir-*.tar.gz
178+
GIT_PROJECT
179+
180+
# ExtUtil::MakeMaker temporary files
181+
/blib
182+
/Makefile
183+
/MANIFEST.bak
184+
/Makefile.old
185+
/MYMETA.*
186+
/pm_to_blib
187+
GIT_GENERAL
188+
}
189+
120190
sub usage {
121191
require File::Basename;
122192
die "usage: @{[File::Basename::basename $0]} modulename\n";
@@ -130,6 +200,7 @@ die "$dir already exists; move out of the way if you want to proceed"
130200
mkdir $dir or die "$dir: $!";
131201
chdir $dir or die "$dir: $!";
132202
203+
print "Setting up a template for '$module' in '$dir'\n";
133204
my $pd_dir = dirname $pdname;
134205
make_path $pd_dir; die "$pd_dir not created" if !-d $pd_dir;
135206
open my $pdfl, ">", $pdname or die "$pdname: $!";
@@ -140,6 +211,18 @@ open my $mkfl, ">", 'Makefile.PL' or die "Makefile.PL: $!";
140211
print $mkfl pdMakefile($module, $pdname);
141212
close $mkfl;
142213
214+
open my $manifest, '>', 'MANIFEST' or die "MANIFEST: '$!'";
215+
print $manifest pdManifest($pdname);
216+
close $manifest;
217+
218+
open my $manifest_skip, '>', 'MANIFEST.SKIP' or die "MANIFEST.SKIP: '$!'";
219+
print $manifest_skip pdManifest_skip($pdname,$dir);
220+
close $manifest_skip;
221+
222+
open my $gitignore, '>', '.gitignore' or die ".gitignore: '$!'";
223+
print $gitignore pdGitignore($pdname,$dir);
224+
close $gitignore;
225+
143226
mkdir 't' or die "t: $!";
144227
open my $tfl, '>', 't/basic.t' or die "t/basic.t: $!";
145228
print $tfl <<EOF;
@@ -172,21 +255,40 @@ for PDL that contains PP code (see also L<PDL::PP>). The usage is simply
172255
173256
pptemplate modulename;
174257
175-
As a result pptemplate will generate a perl Makefile for the new
176-
module (F<Makefile.PL>) that contains the minimal structure to
177-
generate a module from PP code and also a skeleton file
178-
for your new module.
179-
180-
The file will be called F<mymod.pd> if you called C<pptemplate> as
258+
As a result pptemplate will generate the usual directory structure you
259+
would expect for a CPAN module: if you called C<pptemplate> as
181260
182261
pptemplate PDL::CleverAlgs::Mymod;
183262
184-
I suppose you can work out the naming rule C<;)>. If not resort to
185-
experimentation or the source code.
263+
Then you get the following files and directories:
264+
265+
PDL-CleverAlgs-Mymod
266+
|-- lib
267+
| |-- PDL
268+
| |-- CleverAlgs
269+
| |-- MyMod.pd
270+
|-- t
271+
| |-- basic.t
272+
|-- Makefile.PL
273+
| MANIFEST
274+
| MANIFEST.SKIP
275+
| .gitignore
276+
277+
Adapt F<MyMod.pd> to your needs and then you can build and test the
278+
module as usual: From the directory F<PDL-CleverAlgs-Mymod>:
279+
280+
$ perl Makefile.pl # To create a Makefile
281+
$ make # Build the module in blib
282+
$ make test # Run the tests
283+
$ prove -vb # ...or run the tests with prove
186284
187285
C<pptemplate> will stop if the directory to be created already exists,
188286
to avoid accidents. Move it out of the way if you really want to scrap it.
189287
288+
The files F<MANIFEST>, F<MANIFEST.SKIP> and F<.gitignore> are for
289+
bookkeeping: They avoid that temporary files created by building the
290+
module end up in a git repository or a CPAN distrubution.
291+
190292
As of 2.096, the "internal mode" of this script has been removed,
191293
and it creates the files using the new "deep mode". This is because
192294
the earlier practice of incorporating vast numbers of modules into

0 commit comments

Comments
 (0)