Fix: config.xml.in template usage
[apps/low-level-can-service.git] / gendocs.sh
1 #!/bin/bash
2
3 SCRIPT=$(basename $BASH_SOURCE)
4
5 function usage() {
6         cat <<EOF >&2
7 Usage: $SCRIPT [options] [pdf|serve|doxygen]
8
9 Options:
10    --debug
11       enable debug when generating pdf or html documentation
12    -d|--dry
13       dry run
14    -h|--help
15       get this help
16
17 Example:
18         $SCRIPT pdf
19
20 EOF
21         exit 1
22 }
23
24 function info() {
25         echo "$@" >&2
26 }
27
28 #default values
29 DEBUG_FLAG=""
30 DRY=""
31 DO_ACTION=""
32 OUT_DIR=./build
33
34 [[ $? != 0 ]] && usage
35 while [ $# -gt 0 ]; do
36         case "$1" in
37                 --debug) DEBUG_FLAG="--log=debug --debug";;
38                 -d|--dry) DRY=echo;;
39                 -h|--help) usage;;
40         pdf | serve | doxygen) DO_ACTION=$1;;
41                 --) break;;
42         esac
43     shift
44 done
45
46 cd $(dirname $0)
47 ROOTDIR=`pwd -P`
48
49 # Create out dir if needed
50 [ -d $OUT_DIR ] || mkdir -p $OUT_DIR
51
52 if [ "$DO_ACTION" = "pdf" -o "$DO_ACTION" = "serve" ]; then
53     GITBOOK=`which gitbook`
54     [ "$?" = "1" ] && { echo "You must install gitbook first, using: sudo npm install -g gitbook-cli"; exit 1; }
55
56     EBCONV=`which ebook-convert`
57     [ "$?" = "1" ] && { echo "You must install calibre first, using: 'sudo apt install calibre' or refer to https://calibre-ebook.com/download"; exit 1; }
58
59     if [ "$DO_ACTION" = "pdf" ]; then
60             OUTFILE=$OUT_DIR/LowLevelCanBinding_Guide.pdf
61         $DRY $GITBOOK pdf $ROOTDIR $OUTFILE $DEBUG_FLAG
62         [ "$?" = "0" ] && echo "PDF has been successfully generated in $OUTFILE"
63     else
64         $DRY $GITBOOK serve $DEBUG_FLAG
65     fi
66
67 elif [ "$DO_ACTION" = "doxygen" ]; then
68     $DRY cd $OUT_DIR && cmake .. && make doxygen $ROOTDIR/Doxyfile
69
70 else
71     echo "Unknown action !"
72     usage
73 fi