summaryrefslogtreecommitdiff
path: root/scripts/auxiliar/cg-section.sh
blob: aaee5812689cd4f9abdc614867db1f122b541789 (about) (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh

#  Build html versions of sections of lilypond Contributors' Guide
#
#  Usage:  ./cg-section.sh SECTION
#
#    where SECTION is the section to be built.
#
#  For example, CG 4 would be built by
#       ./cg-section.sh doc-work
#
#  At the end of the run, the user is prompted whether or not to
#  remove the generated files.
#
#  Paths are calculated from environment variables in exactly the
#  same way as they are for doc-section.sh - see the documentation
#  for that.
#
#  Known limitations:
#
#     * Doesn't use website css files
#     * Bitmap images aren't loaded properly
#

usage () {
    cat <<EOF >&2
Usage: $0 SECTION

e.g. $0 doc-work
EOF
    exit "$1"
}

if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
    usage 0
fi

[ $# = 1 ] || usage 1

if [ -n "$LILYPOND_GIT" ]; then
    echo "Using source tree from value of \$LILYPOND_GIT: $LILYPOND_GIT"
else
    cd "`dirname $0`"
    cd ../..
    LILYPOND_GIT="`pwd`"
    echo "\$LILYPOND_GIT was not set; auto-detected source tree at $LILYPOND_GIT"
fi

if test ! -e "$LILYPOND_GIT/DEDICATION"; then
    echo "Error: $LILYPOND_GIT did not look like a LilyPond source tree; aborting." >&2
    exit 1
fi

: "${LILYPOND_BUILD_DIR:=$LILYPOND_GIT/build}"
DOC_DIR="${LILYPOND_TEMPDOCS:-$LILYPOND_BUILD_DIR/tempdocs}"
LILYPOND_BOOK="$LILYPOND_BUILD_DIR/out/bin/lilypond-book"
TEXI2HTML="texi2html"
REFCHECK="$LILYPOND_GIT/scripts/auxiliar/ref_check.py"

SECTION="$1"
DOCDIR="$HOME/lilypond/tempdocs"
OUTPUT_DIR="$DOC_DIR/contributor"
SECTION_PATH="$LILYPOND_GIT/Documentation/contributor/$SECTION.itexi"

if test ! -e "$SECTION_PATH"; then
    echo "$SECTION_PATH did not exist; is $SECTION a valid section in the Contributor's Guide?" >&2
    exit 1
fi

if test ! -d "$OUTPUT_DIR"; then
    mkdir "$OUTPUT_DIR"
fi
if test ! -d "$OUTPUT_DIR/out"; then
    mkdir "$OUTPUT_DIR/out"
fi

cp "$LILYPOND_GIT/Documentation/common-macros.itexi" "$OUTPUT_DIR/common-macros.itexi"
cp "$LILYPOND_GIT/Documentation/macros.itexi" "$DOC_DIR/macros.itexi"
cp "$LILYPOND_BUILD_DIR/Documentation/out/version.itexi" "$OUTPUT_DIR"

if test -e "$OUTPUT_DIR/$SECTION.html"; then
    rm "$OUTPUT_DIR/$SECTION.html"
fi

if test -e "$OUTPUT_DIR/out/$SECTION.texi"; then
    rm "$OUTPUT_DIR/out/$SECTION.texi"
fi

echo "Running RefCheck"
python "$REFCHECK"

cd "$DOC_DIR"
echo "Running $TEXI2HTML"
cat "$DOC_DIR/macros.itexi" "$SECTION_PATH" > "$OUTPUT_DIR/$SECTION.texi"

"$TEXI2HTML" \
    --no-validate \
    --output="$OUTPUT_DIR/out/$SECTION.html" \
    --I="$LILYPOND_GIT/Documentation" \
    --I="$OUTPUT_DIR/out" \
    "$OUTPUT_DIR/$SECTION.texi"

cat <<EOF

The $SECTION section of the Contributor's Guide should now be viewable at

  $OUTPUT_DIR/out/$SECTION.html

If you want to keep the generated docs around for a while, answer
'n' to the next question.  If you only needed them to quickly check
something, view them now and then answer 'y' when you're done.

EOF

read -p "rm -rf $OUTPUT_DIR ? (y/n): "
if [ "$REPLY" = "y" ]; then
    echo "deleting files"
    rm -rf "$OUTPUT_DIR"
fi