Brian Silverman | 5962333 | 2018-08-04 23:36:56 -0700 | [diff] [blame^] | 1 | # Copyright David Abrahams 2004. Use, modification and distribution is |
| 2 | # subject to the Boost Software License, Version 1.0. (See accompanying |
| 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 4 | |
| 5 | # This script accepts a list of .rst files to be processed and |
| 6 | # generates Makefile dependencies for .html and .rst files to stdout. |
| 7 | import os,sys |
| 8 | import re |
| 9 | |
| 10 | include = re.compile(r' *\.\. +(include|image):: +(.*)', re.MULTILINE) |
| 11 | |
| 12 | def deps(path, found): |
| 13 | dir = os.path.split(path)[0] |
| 14 | for m in re.findall(include, open(path).read()): |
| 15 | |
| 16 | dependency = os.path.normpath(os.path.join(dir,m[1])) |
| 17 | if dependency not in found: |
| 18 | found[dependency] = 1 |
| 19 | |
| 20 | if m[0] == 'include': |
| 21 | deps(dependency, found) |
| 22 | |
| 23 | return found |
| 24 | |
| 25 | for file in sys.argv[1:]: |
| 26 | found = deps(file, {}) |
| 27 | if found: |
| 28 | base = os.path.splitext(os.path.basename(file))[0] |
| 29 | print '%s.tex %s.html: %s' % (base, base, ' '.join(found.keys())) |