r7rs-small-texinfo

R7RS-small Scheme converted to Texinfo.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

build.sh (3156B)


      1 #!/bin/sh
      2 #
      3 # Copyright © 2024 Wolfgang Corcoran-Mathe
      4 #
      5 # Permission is hereby granted, free of charge, to any person obtaining
      6 # a copy of this software and associated documentation files (the
      7 # "Software"), to deal in the Software without restriction, including
      8 # without limitation the rights to use, copy, modify, merge, publish,
      9 # distribute, sublicense, and/or sell copies of the Software, and to
     10 # permit persons to whom the Software is furnished to do so, subject
     11 # to the following conditions:
     12 #
     13 # The above copyright notice and this permission notice shall be
     14 # included in all copies or substantial portions of the Software.
     15 #
     16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
     17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
     18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
     20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     21 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
     22 # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     23 # THE SOFTWARE.
     24 
     25 usage () {
     26         printf 'Usage: %s [OPTION]... [TARGET]\n' "$(basename $0)" 1>&2
     27         echo 1>&2
     28         cat 1>&2 <<EOF
     29 Helper script for building R7RS-small from Texinfo.
     30 
     31 Options:
     32   -s         Split output files.
     33   -m METHOD  Use METHOD for HTML math output (default: mathjax)
     34              METHODs include 'mathjax', 't4h', and 'l2h'. See
     35              the texinfo manual for more information. Pass 'none'
     36              to disable special rendering.
     37   -h         Show this text.
     38 
     39 TARGETs are 'info', 'html', and 'pdf'. The default is 'html'.
     40 
     41 The command contained in the MAKEINFO environment variable
     42 (or 'makeinfo' if it is empty) will be used. Additional options
     43 in MAKEINFOFLAGS will be passed to this command.
     44 EOF
     45         exit 1
     46 }
     47 
     48 input_file="r7rs-small.texinfo"
     49 split=""
     50 makeinfo_cmd="${MAKEINFO:-makeinfo}"
     51 makeinfo_flags="$MAKEINFOFLAGS"
     52 html_math="mathjax"
     53 
     54 while getopts hm:s opt
     55 do
     56         case "$opt" in
     57         m) html_math="$OPTARG"
     58            shift 2
     59            ;;
     60         s) split=yes
     61            shift
     62            ;;
     63         *) usage ;;
     64         esac
     65 done
     66 
     67 # Append HTML_MATH setting.
     68 case "$html_math" in
     69 none)
     70 	set_var="--set-customization-variable HTML_MATH=undef"
     71 	;;
     72 *)
     73 	set_var="--set-customization-variable HTML_MATH=${html_math}"
     74 	;;
     75 esac
     76 
     77 makeinfo_flags="$makeinfo_flags $set_var"
     78 
     79 if test "$split" != "yes"
     80 then
     81         makeinfo_flags="$makeinfo_flags --no-split"
     82 fi
     83 
     84 target_flag=""
     85 case "${1:-html}" in  # target
     86 epub)
     87         target_flag="--epub"
     88         ;;
     89 html)
     90         target_flag="--html"
     91         ;;
     92 info)
     93         target_flag="--info"
     94         ;;
     95 pdf)
     96         target_flag="--pdf"
     97         ;;
     98 *)
     99         printf "Error: target '%s' not yet supported.\n" "$1"
    100         exit 1
    101         ;;
    102 esac
    103 
    104 if ! test -f $input_file -a -r $input_file
    105 then
    106         printf "Error: %s is not a readable regular file.\n"\
    107                $input_file 1>&2
    108         exit 1
    109 fi
    110 
    111 printf "%s %s %s %s\n" "$makeinfo_cmd" "$makeinfo_flags"\
    112        "$target_flag" "$input_file" 1>&2
    113 
    114 $makeinfo_cmd $makeinfo_flags $target_flag $input_file