Kojun::Makescript - Perl Extension for Makefile-atic Scripting
use Kojun::Makescript qw/sys make make_rule/;
my $SRC = "./src";
my $DST = "./classes";
my $a_rules = [
make_rule
(sub { /^${DST}/(.+).class$/ },
sub { ("${SRC}/$_[0].java") },
sub {
sys qq(javac -sourcepath "${SRC}" -d "${DST}" ${SRC}/$_[0].java);
} ),
];
make($a_rules, ["${DST}/HelloWorld.class"]);
exit;
This is an Perl extension for writing a sort of Makefile in Perl. This is tested on Windows NT and ActivePerl, but it's intended to work plathome independently. Good or bad report will be appreciated.
Makescripting may not be easier than usual Makefile writing in simple cases. But it is more flexible. You can use powerful regular expressions. You can write parametric re-usable rules as a subroutine. It may be helpfull to manage large, complex, nested projects.
To construct a rule, specify three subroutines for the 'make_rule' function.
make_rule(code_T, code_D, code_C)
This returns a rule, where
code_T is subroutine which returns true iff this rule is for the target $_ ($_[0] used formerly) in scalar context, and returns subpatterns of the matching in list context.
code_D is subroutine which takes argument @_ as the above subpatterns, and returns sub-targets the target depends.
code_C is subroutine which takes argument @_ as the above subpatterns, and executed when there is an newer sub-target than the target to update the target.
To define a set of rules, construct an array (array reference) of the rules.
my $rule1 = make_rule(...); my $rule2 = make_rule(...); ... my $a_rules = [$rule1, $rule2, ...];
To run the Makescript, specify rules and targets for the 'make' function.
my $target = $ARGV[0]; make($a_rules, [$target]);
sys EXPR
Execute EXPR as a system command. Die if an error occured.
It is a sort of short alias of:
{system EXPR; die if $? != 0;}
eva EXPR (experimental beta version)
Execute EXPR as a pieces of perl script. Die if an error occured.
It is a sort of short alias of:
{eval EXPR; die if $@ ne '';}
The module is available at or near http://kojun.webalias.com/Makescript/.
The follwoing page explains how to install modules in a standard way.
http://www.cpan.org/modules/INSTALL.html
But you may prefer to put Makescript.pm manually into your project directory. And you may distribute it with your project. Your project directory will be something like...
your_project/src/ your_project/pl/Kojun/Makescript.pm your_project/Makescript.pl your_project/build.sh (or .bat)
where build.sh contains something like...
perl -I./pl ./Makescript.pl build
Kojun Ueno, k.ueno@psynet.net http://kojun.webalias.com/
Copyright (c) 2000 Kojun Ueno. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
And you may redistribute it as a part of your project archive. The .pm contains this license term, so don't worry.
File::Spec, File::Find, Shell, Cwd, ExtUtils::Command, Kojun::Makescript::Java, make