#!/usr/bin/perl # makefile menu; # Last updated: 2010-11-17 $version = '1.4'; $copyyear = '2010'; =head1 Roqet Makefile Menu v1.4 Roqet Makefile Menu is a utility that parses a makefile and creates a menu from and launches commands found within it. =head2 An Example Makefile # this is a makefile to build roqet web pages # a useful tag to remember are the "exit" tag at the top (this isn't # essential but it helps to have a quick exit option on your menu). # IF you don't like this, comment-out the line in makefile_menu.pl # after the line: "# disable if you don't like to use 0 as an exit" exit: echo bye! all: roqdocbuild_help makefile_menu_help echo roqet build complete roqdocbuild_help: pod2text roqdocbuild.pl makefile_menu_help: pod2text makefile_menu.pl help: echo read makefile, and type "make xxx" or "make all" =head1 ChangeLog 2006-09-25 :: 1.0 :: initial release 2006-09-27 :: 1.1 :: modified pod 2007-06-12 :: 1.2 :: added ability to run makefiles by another name 2009-10-02 :: 1.3 :: now allows : in parameters 2010-11-17 :: 1.4 :: now can run multiple selections (delimited by commas) =head1 Author roqet =head1 Copyright Roqet Makefile Menu Perl script copyright 2009,2010 roqet . Roqet Makefile Menu et al can be distributed and modified under the terms of the GNU General Public License: http://www.gnu.org/copyleft/gpl.html This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details. Updates and other scripts and software available at: http://www.roqet.org/software.html ~~~ 'l' - =cut print "Roqet Makefile Menu v$version copyright $copyyear\n"; if ($ARGV[0] eq '') {die "Makefile name not entered!\n";} $makefile = $ARGV[0]; if ($ARGV[1] eq '') {die "Title not entered (enter nil if you don't want a title)!\n";} $title = $ARGV[1]; $extra = $ARGV[2]; open MAKEFILEIN, "$makefile" or die "error opening makefile $makefile" . ": $!\n"; @makefile = ; undef @commands; foreach $line (@makefile) { chomp($line); if (substr($line,0,1) eq '#') {next;} if ($line =~ "\t"){next;} elsif ($line =~ ":"){ if ($line =~ "=") { next; } else { ($makecommand,$rest) = split(':',$line,2); push (@commands,$makecommand); } } } undef @makefile; close MAKEFILEIN; $inpdiv = $#commands / 2; $divresult = sprintf("%.1f", $inpdiv); $colconv = "$divresult"; ($colcount,$remainder) = split(/\./,$colconv,2); if ($remainder ne '') { $colcount++; } # build column text @col1 = undef; @col2 = undef; $menulines = ''; $num = 0; foreach $i (@commands) { if ($colcount > 1) { push(@col1, $num . " $i"); } else { if ($i ne '') { push(@col2, $num . " $i\n"); } } $colcount--; $num++; } # # Menu # # 1 2 3 4 5 6 7 8 #012345678901234567890123456789012345678901234567890123456789012345678901234567890 format STDOUT= | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | $item1, $item2 . $input = ''; $command = ''; print "\n\n"; while ($input ne 'exit') { print "+-----------------------------------------------------------------------------+\n"; print "| Roqet Makefile Menu($version) for makefile: $makefile\n"; if ($title ne 'nil') { print "| $title\n"; } print "+--------------------------------------+--------------------------------------+\n"; $q = 1; foreach $c (@col1) { $item1 = $c; $item2 = @col2[$q]; write; $q++; } print "| | |\n"; print "+--------------------------------------+--------------------------------------+\n"; print " Enter Selection (comma delimit for multiple, \"exit\" to exit): "; $input = ; chomp($input); # disable if you don't like to use 0 as an exit if ($input eq '0') {last;} if ($input eq 'exit') {last;} if ($input =~ ",") { undef @multiple; @multiple = split(',',$input); foreach $comm (@multiple) { runmake($comm); } } else { runmake($input); } } undef @commands; print "\n\nRoqet Makefile Menu Exit.\n"; sub runmake { local($makecommand) = @_; #print "test: make ". @commands[$makecommand] ."\n"; if ($makecommand > ($#commands - 1)) { print "\nInvalid number; please enter 0 - " . ($#commands - 1) . "\n\n"; } else { system ("make $extra -f $makefile " . @commands[$makecommand]); } }