|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Generate documentation from the CMake project specific modules where needed. |
| 6 | + * |
| 7 | + * SYNOPSIS: |
| 8 | + * ./bin/make-docs.php |
| 9 | + */ |
| 10 | + |
| 11 | +$docs = __DIR__ . '/../docs/cmake-modules'; |
| 12 | +if (!file_exists($docs)) { |
| 13 | + mkdir($docs, 0777, true); |
| 14 | +} |
| 15 | + |
| 16 | +$docFiles = glob($docs . '/*{/*,*}', GLOB_BRACE); |
| 17 | +foreach ($docFiles as $file) { |
| 18 | + if (is_file($file)) { |
| 19 | + unlink($file); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +$modulesDirectory = realpath(__DIR__ . '/../cmake/cmake/modules'); |
| 24 | +$files = glob($modulesDirectory . '/*{/*,*}.cmake', GLOB_BRACE); |
| 25 | + |
| 26 | +foreach ($files as $file) { |
| 27 | + $relativeFilename = trim(str_replace($modulesDirectory, '', $file), '/'); |
| 28 | + echo "Processing " . $relativeFilename . "\n"; |
| 29 | + |
| 30 | + $content = file_get_contents($file); |
| 31 | + preg_match('/#\[===+\[\s*(.*?)\s*#\]===+\]/s', $content, $matches); |
| 32 | + |
| 33 | + if (isset($matches[1])) { |
| 34 | + $moduleName = basename($file, '.cmake'); |
| 35 | + $namespace = trim(str_replace($modulesDirectory, '', dirname($file)), '/'); |
| 36 | + $namespace = ($namespace == '') ? '' : $namespace . '/'; |
| 37 | + |
| 38 | + $content = ''; |
| 39 | + $content .= "# $namespace" . "$moduleName\n\n"; |
| 40 | + $content .= $matches[1]; |
| 41 | + $content .= "\n"; |
| 42 | + |
| 43 | + if (!file_exists($docs . '/' . $namespace)) { |
| 44 | + mkdir($docs . '/' . $namespace, 0777, true); |
| 45 | + } |
| 46 | + |
| 47 | + file_put_contents($docs . '/' . $namespace . $moduleName . '.md', $content); |
| 48 | + } |
| 49 | +} |
0 commit comments