develooper Front page | perl.macperl.porters | Postings from November 2002

MM->perl_oneliner() for portable Makefile oneliners

Thread Next
From:
Michael G Schwern
Date:
November 15, 2002 23:58
Subject:
MM->perl_oneliner() for portable Makefile oneliners
Message ID:
20021116005709.GL25839@ool-18b93024.dyn.optonline.net
Trying to come up with a way to write cross-platform, shell safe perl
one-liners was causing me to lose sleep.  So I've given up one trying to
write One Unified One Liner and instead took a page from the perl core test
suite's t/test.pl run_perl().

There is now a perl_oneliner() method which given some perl code and
switches will generate a safe one liner.  Overrides have been put in
MM_Win32, MM_Unix and MM_VMS to do the escapes and quoting appropriate for
that platform.  After playing with it some, I added suport for newline
escaping (which could probably be improved to use multiple -e's) and
stripping of leading/trailing newlines.

It doesn't do everything, just enough to handle the code I've thrown at it
so far.

If the VMS and Win32 folks could examine their versions of perl_oneliner()
to make sure I got it right.

Also, we need one for MacOS Classic.

The end result?  Instead of this:

  return <<'MAKE_FRAG';
  dist : $(DEFAULT)
        $(NOECHO) $(PERL) -le "print 'Warning: Makefile possibly out of date with $(VERSION_FROM)' if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(MAKEFILE)';"
MAKE_FRAG

you can do this:

    my $date_check = $self->perl_oneliner(<<'CODE', ['-l']);
print 'Warning: Makefile possibly out of date with $(VERSION_FROM)'
  if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(MAKEFILE)';
CODE

  return sprintf <<'MAKE_FRAG', $date_check;
  dist : $(DEFAULT)
        $(NOECHO) %s
MAKE_FRAG

so the code formatting is natural and you don't have to worry about quoting.


The end result in the Makefile is icky:

dist : $(DIST_DEFAULT)
        $(NOECHO) $(PERLRUN) -l -e 'print '\''Warning: Makefile possibly out of 
date with $(VERSION_FROM)'\''\
  if -e '\''$(VERSION_FROM)'\'' and \
     -M '\''$(VERSION_FROM)'\'' < -M '\''$(MAKEFILE)'\'';'

but its more important that the MakeMaker code is easy to maintain than the
resulting Makefile.


The real win is that with the ability to generate portable one-liners, a
whole slew of duplicate method overrides in MM_VMS and MM_Win32 that are
just there to change quoting from ' to " go away.


So, if anyone has a little free time you can start running through the
MM_Unix code and replacing ad-hoc one-liners with perl_oneliner() generated
code.


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <perl-qa@perl.org>         Kwalitee Is Job One
"Please hold while reality is adjusted to match my ideal world."
	-- njt

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About