1#!/bin/sh
2# SPDX-License-Identifier: LGPL-2.1-or-later
3set -e
4
5if [ -z "$1" ]; then
6    echo "Use: $0 page-name (with no section suffix)"
7    exit 1
8fi
9
10# make sure the rules have been regenerated (in case update-man-rules was just run)
11ninja -C "@BUILD_ROOT@" version.h
12
13target="man/$1.html"
14ninja -C "@BUILD_ROOT@" "$target"
15
16fullname="@BUILD_ROOT@/$target"
17redirect="$(test -f "$fullname" && readlink "$fullname" || :)"
18if [ -n "$redirect" ]; then
19    ninja -C "@BUILD_ROOT@" "man/$redirect"
20
21    fullname="@BUILD_ROOT@/man/$redirect"
22fi
23
24set -x
25exec xdg-open "$fullname"
26