1#!/usr/bin/env bash
2#
3#  Copyright (C) 2020 Alexandros Theodotou <alex at zrythm dot org>
4#
5#  This file is part of Zrythm
6#
7#  Zrythm is free software: you can redistribute it and/or modify
8#  it under the terms of the GNU Affero General Public License as published by
9#  the Free Software Foundation, either version 3 of the License, or
10#  (at your option) any later version.
11#
12#  Zrythm is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#  GNU Affero General Public License for more details.
16#
17#  You should have received a copy of the GNU Affero General Public License
18#  along with Zrythm.  If not, see <https://www.gnu.org/licenses/>.
19#
20# This file generates .texi documentation from a
21#   given C source file with defined SCM_* macros.
22
23set -e
24
25GUILE_SNARF_DOCS_BIN=$1
26GUILE_PKGCONF_NAME=$2
27INPUT_FILE=$3 # c file
28OUTPUT_FILE=$4 # texi file
29PRIVATE_DIR=$5 # for intermediate files
30GUILD_BIN=$6
31OTHER_INCLUDES=$7
32
33input_file_base=$(basename $INPUT_FILE)
34input_file_base_noext=$(echo "$input_file_base" | cut -f 1 -d '.')
35
36# change to abs paths
37output_file="`pwd`/$OUTPUT_FILE"
38private_dir="`pwd`/$PRIVATE_DIR"
39
40pushd $(dirname $GUILE_SNARF_DOCS_BIN)
41mkdir -p "$private_dir"
42# snarf docs out of the C file into a doc file
43echo "Snarfing docs out of <$INPUT_FILE> to <$private_dir/$input_file_base_noext.doc>"
44$GUILE_SNARF_DOCS_BIN -o \
45  "$private_dir/$input_file_base_noext.doc" \
46  $INPUT_FILE -- \
47  "$OTHER_INCLUDES" \
48  $(pkg-config --cflags-only-I $GUILE_PKGCONF_NAME)
49# convert to texi
50echo "Converting <$private_dir/$input_file_base_noext.doc> to <$output_file>"
51cat "$private_dir/$input_file_base_noext.doc" | \
52  $GUILD_BIN snarf-check-and-output-texi > \
53  "$output_file"
54popd
55