Here is a dmake makefile indenter, I wrote it to make perl/win32/makefile.mk more readable, it indents .IF/.END blocks.
#!/usr/bin/perl -- # # Usage: # perl indentmk.pl < crud.mk > indented-crud.mk # perl indentmk.pl crud.mk crud.mk > indented-crud.mk # # use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Main { local *ARGV; ## uncomment to edit files and make backups instead of printing to STD +OUT #~ local $^I = ".orig"; local @ARGV = @_; my $dent = 0; my $oldent = 0; my $space = "\t"; LINE: while (defined($_ = <ARGV>)) { next if /^#/; my $w = /^\s*\.(\S+)/ ? $1 : ''; if( $w ) { $oldent = $dent; if( $w =~ /^END/i ){ $dent--; s/^/ $space x ( $dent )/e ; } else { $dent++ if $w =~ /^IF/i; s/^/ $space x ( $dent - 1 )/e ; } } else { s/^/ $space x ( $dent )/e; } } continue { die "-p destination: $!\n" unless print $_; } } __END__

Example usage

$ perl indentmk.pl crud.mk > indented-crud.mk $ cat crud.mk CC *= gcc CCTYPE *= GCC .IF "$(CCTYPE)" == "GCC" GCC_MAJOR_VERSION *= 12 .IF "$(GCC_MAJOR_VERSION)" == "4" CFLAGS += -static-libgcc LIBC += -static-libgcc .ELSE GCC_MAJOR_VERSION *= 42 .ENDIF .ENDIF .IF "$(CCTYPE)" == "GCC" $(XCOPY) $(CCHOME)\bin\*dll ..\t\$(NULL) .ENDIF $ cat indented-crud.mk CC *= gcc CCTYPE *= GCC .IF "$(CCTYPE)" == "GCC" GCC_MAJOR_VERSION *= 12 .IF "$(GCC_MAJOR_VERSION)" == "4" CFLAGS += -static-libgcc LIBC += -static-libgcc .ELSE GCC_MAJOR_VERSION *= 42 .ENDIF .ENDIF .IF "$(CCTYPE)" == "GCC" $(XCOPY) $(CCHOME)\bin\*dll ..\t\$(NULL) .ENDIF
I've tested with cc786a4f9707dccd5f9dd092b2f3926dfa4bb510, seems to work (nothing broke:)

In reply to indentmk - dmake makefile indenter by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.