#!/bin/bash # SPDX-FileCopyrightText: 2025 eden Emulator Project # SPDX-License-Identifier: GPL-3.0-or-later MESSAGE=" ## Markdown documentation for current CMake options. Generated with tools/generate-options-doc.sh automatically. " # Output file OUTPUT_FILE="docs/build/build-options.md" # Check if script is run from the root of the project (look for docs/ folder) if [[ ! -d "docs" ]]; then echo "Warning: Not running from project root (docs/ folder not found)." echo "Markdown will not be generated." else # Start Markdown file printf "%s\n" "$MESSAGE" > "$OUTPUT_FILE" # Process each CMakeLists.txt file find . -type f -iname 'CMakeLists.txt' | while IFS= read -r file; do options="" # Capture all options using grep while IFS= read -r line; do # Trim leading spaces line_trimmed=$(echo "$line" | sed 's/^[[:space:]]*//') # Match option() and CMAKE_DEPENDENT_OPTION() if [[ "$line_trimmed" =~ [Oo][Pp][Tt][Ii][Oo][Nn][_Dd]?[Ee]?[Pp]?[Ee]?[Nn]?[Dd]?[Ee]?[Nn]?[Tt]?_?[Oo]?[Pp]?[Tt]?[Ii]?[Oo]?[Nn]?\(([[:space:]]*[^[:space:]\)]+)[[:space:]]*\"([^\"]*)\"[[:space:]]*(.*)\) ]]; then name="${BASH_REMATCH[1]}" desc="${BASH_REMATCH[2]}" def="${BASH_REMATCH[3]}" # Escape pipe characters for Markdown desc=$(echo "$desc" | sed 's/|/\\|/g') def_value="$def" options+="$name|$desc|$def_value"$'\n' fi done < <(grep -i -E "option" "$file") # Only write header if options exist if [[ -n "$options" ]]; then { echo "## Options in $file" echo "| Name | Description | Default Value |" echo "|------|-------------|---------------|" # Sort by Default Value then Name echo "$options" | sort -t'|' -k3,3 -k1,1 | while IFS='|' read -r n d v; do echo "| $n | $d | $v |" done echo } >> "$OUTPUT_FILE" fi done echo "Markdown $OUTPUT_FILE generated successfully." fi