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