xdg-specs-build (2166B)
1 #!/bin/bash 2 3 set -eu -o pipefail 4 shopt -s inherit_errexit 5 test "${DEBUG:-}" && set -x 6 7 declare -r SRC_DIR=~/src/freedesktop.org/xdg-specs 8 declare -r INSTALL_DIR=~/apps/xdg-specs 9 declare -r TEXI_DIR="${INSTALL_DIR}"/texi 10 declare -r INFO_DIR="${INSTALL_DIR}"/share/info 11 12 find-specs () 13 { 14 # Ain't nobody got time for parsing spec-index.toml. 15 find "${SRC_DIR}" -name '*-spec.xml' 16 } 17 18 spec-title () 19 { 20 local -r docbook=$1 21 # Ain't nobody got time for querying XML. See also: 22 # https://github.com/jgm/pandoc/issues/1950 23 # https://pandoc.org/lua-filters.html#replacing-placeholders-with-their-metadata-value 24 sed -nr s,'^ *<title>(.*)</title>$','\1',p "${docbook}" | head -n1 25 } 26 27 spec-id () 28 { 29 local -r docbook=$1 30 echo xdg-$(basename "${docbook}" -spec.xml) 31 } 32 33 texi-dir-prologue () 34 { 35 local -r docbook=$1 36 local -r texi_title=$(spec-title "${docbook}") 37 local -r texi_id=$(spec-id "${docbook}") 38 39 cat <<EOF 40 @dircategory Software development 41 @direntry 42 * ${texi_title}: (${texi_id}). 43 @end direntry 44 EOF 45 } 46 47 build-spec () 48 { 49 shift # mapfile callback: $1 = index. 50 local -r docbook=$1 51 local -r name=$(spec-id "${docbook}") 52 local -r texi=${TEXI_DIR}/${name}.texi 53 local -r info=${INFO_DIR}/${name}.info 54 55 pandoc -s -H <(texi-dir-prologue "${docbook}") \ 56 -f docbook "${docbook}" -o "${texi}" 57 58 } 59 60 mkdir -p "${TEXI_DIR}" "${INFO_DIR}" 61 # Create a /bin directory to coax 62 # * my apps 'activate' script into adding it to PATH, 63 # * info into finding the .info files, by virtue of inspecting PATH 64 # entries for share/info siblings. 65 mkdir "${INSTALL_DIR}"/bin 66 67 # I dream of a bash built-in like 68 # map FUNC [ARGS… --] GLOB… 69 # but afaict that doesn't exist? So here I am inflicting 'mapfile' & 70 # 'xargs' violence. 71 72 find-specs | mapfile -tc1 -Cbuild-spec 73 74 # pandoc turns menu-spec.xml's 75 # <xref linkend="term-desktop-file-id"/> 76 # into 77 # @ref{#term-desktop-file-id,,glossentry_title} 78 # but makeinfo does not like those. Quelch with --no-validate. 79 makeinfo --no-validate "${TEXI_DIR}"/*.texi -o "${INFO_DIR}" 80 81 find "${INFO_DIR}" -name '*.info' | 82 xargs -d'\n' -I'{}' install-info '{}' "${INFO_DIR}"/dir