My last PerlMonks posting was a CUFP that related very specifically to Microsoft Windows (but had the saving grace that it related to Free/Open-Source software insofar as I had written it in order to use Cygwin, that is, GNU-on-Windows, more effectively). So to be balanced and all, this submission for the perusal of the monkly Sis/Breth-ren relates to the very GNU-oriented developer's tool Autoconf and specifically to the use of macros in the authorship of those darned complex-icated configure files that are used to prepare the directed compilation of so many Open Source packages.

My CUFP this time is another very, very simple tool (because that's what I like most: the simple tools) that just does one thing. Before I explain what it does I'll just show the code:

#! /usr/bin/env perl =for gpg -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 =cut # update_acsite -- Place all m4 autoconf macros found in DIR into the +file named # "acsite.m4" under ${PREFIX}/share/autoconf. use warnings; use strict; use File::Glob qw{:glob}; use File::Spec::Functions qw{rel2abs splitpath file_name_is_absolute catfile canonpath}; use vars qw{@MacrDa}; my $MyDir = $ARGV[0] || q|/usr/local/share/repository_ac_macros|; my $OutFN = $ARGV[1] || q|/usr/local/share/autoconf/acsite.m4|; my $OutDN = (splitpath($OutFN))[1]; # my $MyGlb = catfile($MyDir , "*.m4"); $MyDir = rel2abs( canonpath($MyDir) => '' ) if not file_name_is_absolute($MyDir); die "This process cannot write to the dest directory: $!" if not ( -w $OutFN || (-d $OutDN && -w _) ); die "This indicated directory does not exist!: $!" if not chdir( $MyDir ); my @repos_macs = bsd_glob( '*.m4' , GLOB_ERROR | GLOB_MARK | GLOB_NOCASE | GLOB_TILDE | GLOB_NOSORT ); if (@repos_macs) { foreach my $macfile_data (@repos_macs) { my $fsz = -s $macfile_data; (my $fln = <<"!ROBUSTO!" ) =~s/^\s*//mg; dnl ------------------------------------------------------------ +- dnl The next file added $fsz bytes to this collection. dnl file: $macfile_data dnl ------------------------------------------------------------ +- !ROBUSTO! open IFH,$macfile_data or die "Failed to open() \"$macfile_data\" "; read(IFH, my $data, $fsz); $data or die "Could not read any data from \"$macfile_data\""; close IFH; push @MacrDa , qq{\n\n}, $fln , $data; } open OFH,">$OutFN" or die "Cannot open() the outfile \"$OutFN\" -- $ +!"; print OFH @MacrDa; } else { my $me = (splitpath($0))[3]; print STDERR <<"!CLEMENTINE!"; $me terminated because there were no macro *.m4 files found in the ind +icated or default directory location. Please check your arguments and try aga +in. !CLEMENTINE! } __END__ =begin gpg -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE/FWU8BXOj2U4kTqYRArKyAJwKJ/9gmyof0MZJ+Ao2TQ+rcPEwYQCdEmdC 5/oKZKbs5XfVaHlvV1r3h+0= =TX52 -----END PGP SIGNATURE----- =end gpg This Program is Free Software, (C)2003 Soren Andersen <somian -AT- pobox -DOT- com> it may be used under the same terms as Perl itself.

Now what's going on there is this. Being the kind of laid-back mellow dude that I am, I recently surfed over into the two AC Autoconf Macro archive sites (who are:

...) and I did what comes most naturally to me, just started downloading whatever looked useful. So I ended up with a newly-created directory populated with files ending in .m4 and wondered how to use them.

Autoconf (versions going back how far?) will add any macros found in a file named acsite.m4 located in the top Autoconf "lib" (conceptually) directory. In the case of my own recent site-local (manually installed) Autoconf that is in

/usr/local/share/autoconf
, macros in such a file will be known to Autoconf (when it is looking for definitions while building the configure file from configure.ac).

Autoconf m4 macros are conceptually very much like Perl modules. They extend the functionality of Autoconf in an analogous fashion and embody the primary Virtue of code reuse. My simple Perl tool just slurps in all the .m4 files it finds in the given dir and writes them all out to the single properly named file (the user is responsible for telling the program where the file should be be properly placed). There's not much Perl there but there was a gap in the convenience of the AC Archive concept that I thought Perl should be the one to fill. And yes, the Archive(s) offer all the macros bundled into downloadable archive files, and that would be perhaps another shortcut. I felt that I didn't want ALL the macros but just the ones that seemed useful or interesting to me, and I can always go back and add more later. Perl will take care of adding them to my working Autoconf system: I can re-run update_acsite anytime I want and it will just Do The Right Thing. IMHO, this comprises a CUFP.


PS: Q: OK, what's up with the signed code?
A: See perlsign. Another CUFP, IMHO ;-)