Skip to content

Instantly share code, notes, and snippets.

@TakesxiSximada
Created June 16, 2016 04:39
Show Gist options
  • Save TakesxiSximada/2383ffddc7db85fb5bb77cfe3b3568ea to your computer and use it in GitHub Desktop.
Save TakesxiSximada/2383ffddc7db85fb5bb77cfe3b3568ea to your computer and use it in GitHub Desktop.
MakefileのUsageを表示するためのperl スクリプト
#! /usr/bin/env perl
#
# Display Makefile Usage Script
#
# Examle Makefile)::
#
# .all:
# @## version=VERSION
# @# comment1
# @# comment2
# @# comment3
# echo "OK"
use strict;
use warnings;
open (FILE, "./Makefile") or die "$!";
my $buf = do { local $/; <FILE> };
close FILE;
while ($buf =~ /^([^._][a-zA-Z0-9_\-]*):(.*)\n(^\t\@\##.*\n)?((^\t\@\#.*\n)*)/gm ) {
my $cmd = $1;
my $synopsis = $3 || "";
my $msg = $4 || "";
$synopsis =~ s/@##//g;
$synopsis =~ s/\A\s*(.*?)\s*\z/$1/;
$msg =~ s/\t\@\#/ /g;
printf("* %-20s\n%s\n", $cmd . " " . $synopsis, $msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment