summaryrefslogtreecommitdiff
path: root/util/util_readme/util_readme.sh
blob: 41ee4087fe8d3685272cab1f329cdeb8e150b6e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash

# Creates `./util/README.md` and `./Documentation/Util.md` of description files
# in `./util` subdirectories
#
# Execute from root of project.  Example:
# `util/util_readme/util_readme.sh`

UTIL_README_DIR="$(cd "$(dirname "$0")" || exit; pwd -P)"
UTIL_DIR=$(dirname "$UTIL_README_DIR")
COREBOOT_ROOT_DIR=$(dirname "$UTIL_DIR")
DOCMENTATION_DIR="$COREBOOT_ROOT_DIR/Documentation"
SUMMARY='
## List of utils

_Scripts and programs found in the coreboot `./util` directory_
'
APPEND_TO_UTIL_MD="${UTIL_README_DIR}/post_util.md"

DESCRIPTION_FILES=$(find "$UTIL_DIR" -name "description.md" | sort)

echo -n "" > "$UTIL_DIR/README.md"
{
  echo "<!-- DO NOT EDIT - AUTOGENERATED FILE -->";
  echo "<!-- RUN 'util/util_readme/util_readme.sh' to regenerate -->";
  echo;
  echo "# Utilities";
  echo "${SUMMARY}"
} > "${DOCMENTATION_DIR}/util.md"

for DESC_FILE in $DESCRIPTION_FILES; do
  UTIL_NAME=$(echo "$DESC_FILE" | rev | cut -d '/' -f2 | rev)
  DESC=$(cat "$DESC_FILE")

  if [[ $DESC == "__"${UTIL_NAME}* || $DESC == "__["${UTIL_NAME}* ]]; then
    DESC="* $DESC"
  else
    DESC="* __${UTIL_NAME}__ - $DESC"
  fi

  # format description to under 72 characters per line and only
  # breaking on whitespace
  DESC=$(echo "$DESC" \
      | tr '\r\n' ' '  \
      | sed 's/  [*]\+/\n\t\*/g' \
      | sed 's/  \+/ /g' \
      | fold -s -w72 \
      | sed 's/\s*$//')

  echo "$DESC" >> "$UTIL_DIR/README.md"
  echo "$DESC" >> "$DOCMENTATION_DIR/util.md"
done

cat "${APPEND_TO_UTIL_MD}" >> "${DOCMENTATION_DIR}/util.md"