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:)