#!/usr/bin/perl -w
our
$VERSION
=
'@VERSION@'
;
our
$datadir
;
BEGIN {
$datadir
= $0;
unless
(
$datadir
=~ s@/[^/]+$@@ ) {
foreach
(
split
( /:/,
$ENV
{
'PATH'
} ),
'.'
) {
if
( -d
"$_/Mpp"
) {
$datadir
=
$_
;
last
;
}
}
}
$datadir
or
die
"makepp: can't find library files\n"
;
$datadir
=
eval
"use Cwd; cwd . '/$datadir'"
if
$datadir
=~ /^\./;
unshift
@INC
,
$datadir
;
}
$Mpp::Subs::rule
->{MAKEFILE}{PACKAGE} =
''
;
sub
eval_or_die($) {
if
(
wantarray
) {
my
@result
=
eval
$_
[0];
&maybe_die
;
@result
;
}
else
{
my
$result
=
eval
$_
[0];
&maybe_die
;
$result
;
}
}
{
no
warnings
'redefine'
;
*Mpp::Cmds::eval_or_die
= \
&eval_or_die
}
sub
metahelp {
print
STDERR
"usage: $0"
,
<<'EOF' }
[metaoption ...] command [option ...] [argument ...]
Options depend on the command, while metaoptions are these:
-I or --include=dir
dir to load module from
-M or --module=module[=arg,...]
module with your functions
Look at @htmldir@/makeppbuiltin.html for wrapper details,
or type "man makeppbuiltin".
EOF
sub
helpfoot {
die
<<'EOF' }
Look at @htmldir@/makepp_builtins.html for command details,
or type "man makepp_builtins".
EOF
sub
getopts_help(@) {
my
@opts
=
@_
;
print
STDERR
"$0 options:"
;
shift
@opts
if
'HASH'
eq
ref
$opts
[0];
my
%short
;
for
(
@opts
) {
my
$long
= Mpp::Text::_getopts_long(
$_
);
my
$short
=
$_
->[0];
$_
= ((
$short
&& !
$short
{
$short
}) ?
"$_->[0], --$long"
:
$long
) .
(
$_
->[3] ?
'=arg'
:
''
);
$short
{
$short
} ||= 1
if
$short
;
}
for
(
sort
{
lc
(
substr
$a
, 0, 1 ) cmp
lc
(
substr
$b
, 0, 1 ) ||
substr
(
$b
, 0, 1 ) cmp
substr
(
$a
, 0, 1 ) ||
$a
cmp
$b
}
@opts
) {
s/^/-/;
s/^(-.[^,])/ -$1/;
print
STDERR
"\n $_"
;
}
&helpfoot
;
}
my
$re
=
join
'|'
,
grep
{
exists
&{
"Mpp::Cmds::$_"
} && s/^c_// }
keys
%Mpp::Cmds::
;
sub
doit {
my
$cmd
= $0;
if
( $0 =~ /(
$re
)[^\/]*$/ ) {
$0 = $1;
$cmd
=
"Mpp::Cmds::c_$0"
;
}
else
{
my
$tmp
;
Mpp::Text::getopts 1,
[
'I'
,
qr/include(?:[-_]?dir)?/
, \
$tmp
, 1,
sub
{
unshift
@INC
,
$tmp
}],
[
qw(M module)
, \
$tmp
, 1,
sub
{
$tmp
=~ s/=(.*)/
qw($1)
/ and
$tmp
=~
tr
/,/ /; eval_or_die
"use $tmp"
}],
[
qr/[h?]/
,
'help'
,
undef
, 0,
sub
{
&metahelp
;
&helpfoot
}],
[0,
'version'
,
undef
, 0, \
&Mpp::File::version
];
&metahelp
,
&helpfoot
if
!
@ARGV
;
$tmp
= $0;
$0 =
shift
@ARGV
;
if
( !
exists
&{
$cmd
=
"c_$0"
} ) {
$cmd
=
"Mpp::Cmds::c_$0"
;
die
"$tmp: $0 is not a makepp builtin command.\n"
if
!
exists
&$cmd
;
}
}
if
(
@ARGV
and
$ARGV
[0] eq
'-?'
||
$ARGV
[0] eq
'--help'
) {
no
warnings;
*Mpp::Text::getopts
= \
&getopts_help
;
}
if
( !
$ENV
{INSTALL_LOG} &&
$cmd
=~ /install$/ ) {
Mpp::Makefile::find_root_makefile_upwards(
$Mpp::File::CWD_INFO
);
}
elsif
(
$cmd
=~ /preprocess$/ ) {
}
&$cmd
(
@ARGV
);
}
doit;