3 A simple tool for converting a Makefile to reStructuredText.
5 Basically it strips all comments starting at column 0 that don't start with
6 ``##`` and converts all the rest to literal blocks. The first comment line
7 defines the number of spaces after the comment sign to be ignored (this allows
8 ``# text...`` which is more readable than ``#text...``).
12 from __future__
import generators
17 """Generate lines of reST from makefile lines."""
18 in_literal_block
= False # state
19 comment_spaces
= None # stripped from all lines
20 leading_spaces
= 0 # this/last line's indentation
24 # Empty line accepted in both states.
25 if not in_literal_block
:
29 if line
[0] == '#' and not line
[:2] == '##':
33 in_literal_block
= False
35 line
= line
.expandtabs()[1:]
36 leading_spaces
= len(line
) - len(line
.lstrip(' '))
37 if comment_spaces
is None:
38 comment_spaces
= leading_spaces
40 line
= line
[min(leading_spaces
, comment_spaces
):]
45 if not in_literal_block
:
49 in_literal_block
= True
54 sys
.stdout
.writelines(convert(fileinput
.input(args
)))
56 if __name__
== '__main__':