Files
asterisk/build_tools/get_sourceable_makeopts
George Joseph 2fcd80ef38 Makefile: Allow XML documentation to exist outside source files
Moved the xmldoc build logic from the top-level Makefile into
its own script "make_xml_documentation" in the build_tools
directory.

Created a new utility script "get_sourceable_makeopts", also in
the build_tools directory, that dumps the top-level "makeopts"
file in a format that can be "sourced" from shell sscripts.
This allows scripts to easily get the values of common make
build variables such as the location of the GREP, SED, AWK, etc.
utilities as well as the AST* and library *_LIB and *_INCLUDE
variables.

Besides moving logic out of the Makefile, some optimizations
were done like removing "third-party" from the list of
subdirectories to be searched for documentation and changing some
assignments from "=" to ":=" so they're only evaluated once.
The speed increase is noticeable.

The makeopts.in file was updated to include the paths to
REALPATH and DIRNAME.  The ./conifgure script was setting them
but makeopts.in wasn't including them.

So...

With this change, you can now place documentation in any"c"
source file AND you can now place it in a separate XML file
altogether.  The following are examples of valid locations:

res/res_pjsip.c
    Using the existing /*** DOCUMENTATION ***/ fragment.

res/res_pjsip/pjsip_configuration.c
    Using the existing /*** DOCUMENTATION ***/ fragment.

res/res_pjsip/pjsip_doc.xml
    A fully-formed XML file.  The "configInfo", "manager",
    "managerEvent", etc. elements that would be in the "c"
    file DOCUMENTATION fragment should be wrapped in proper
    XML.  Example for "somemodule.xml":

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE docs SYSTEM "appdocsxml.dtd">
    <docs>
        <configInfo>
        ...
        </configInfo>
    </docs>

It's the "appdocsxml.dtd" that tells make_xml_documentation
that this is a documentation XML file and not some other XML file.
It also allows many XML-capable editors to do formatting and
validation.

Other than the ".xml" suffix, the name of the file is not
significant.

As a start... This change also moves the documentation that was
in res_pjsip.c to 2 new XML files in res/res_pjsip:
pjsip_config.xml and pjsip_manager.xml.  This cut the number of
lines in res_pjsip.c in half. :)

Change-Id: I486c16c0b5a44d7a8870008e10c941fb19b71ade
2022-02-28 08:47:00 -06:00

55 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
PROGNAME="${0##*/}"
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
cat <<-EOF
Usage: ${PROGNAME}: [ <input_file> ] [ <output_file> ]
This script takes an Asterisk makeopts file, or any file containing
"make" style variable assignments, and converts it into a format
that can be directly 'sourced' by shell scripts.
* Any spaces around the equals sign are removed.
* The variable value is quoted.
* The "make" "or" command is evaluated.
Both input and output files are optional and will default to
stdin and stdout respectively.
NOTE: This script relies on NO external commands and only POSIX
constructs. It should be runnable by any shell.
EOF
exit 1
fi
input_file="/dev/stdin"
if [ "$1" != "" ] ; then
input_file="$1"
fi
output_file="/dev/stdout"
if [ "$2" != "" ] ; then
output_file="$2"
fi
# orfunc is a code fragment to be added to the outp[ut file.
# We don't WANT the variables evaluated.
# shellcheck disable=SC2016
orfunc='or (){ before="${1%,*}" ; after="${1#*,}" ; if [ "$before" = "" ] ; then echo "${after}" ; else echo "${before}" ; fi ; }'
echo "${orfunc}" >"${output_file}"
while read -r LINE ; do
var="${LINE%%=*}"
if [ "${var}" != "" ] ; then
val="${LINE#*=}"
if [ "${val}" != "${var}" ] ; then
if [ "${val%% *}" = "" ] ; then
echo "${var% *}=\"${val#* }\""
else
echo "${var% *}=\"${val}\""
fi
fi
fi
done <"${input_file}" >>"${output_file}"