Use bash script to generate doc instead of cmake
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Mon, 20 Mar 2017 14:34:01 +0000 (15:34 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Mon, 20 Mar 2017 14:34:01 +0000 (15:34 +0100)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
CMakeLists.txt
README.md
gendocs.sh [new file with mode: 0755]

index 05fbd5f..233ee69 100644 (file)
 cmake_minimum_required(VERSION 3.3)
 project(low-can-binding)
 add_subdirectory(src)
-
-add_custom_command(
-       OUTPUT ${PROJECT_NAME}.pdf
-       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-       COMMAND gitbook install
-       COMMAND gitbook pdf docs ${PROJECT_NAME}.pdf
-)
-add_custom_target(pdf
-       DEPENDS ${PROJECT_NAME}.pdf)
-
-add_custom_command(
-       OUTPUT _book
-       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-       COMMAND gitbook install
-       COMMAND gitbook serve
-)
-add_custom_target(serve
-       DEPENDS _book)
-
-add_custom_command(
-       OUTPUT docs_doxygen
-       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-       COMMAND doxygen CAN_signaling.doxygen
-)
-add_custom_target(doxygen
-       DEPENDS docs_doxygen)
\ No newline at end of file
index bcf9981..55fc453 100644 (file)
--- a/README.md
+++ b/README.md
@@ -33,17 +33,21 @@ cmake ..
 Generate a PDF version :
 
 ```bash
-make pdf
+gendocs.sh pdf
 ```
 
 Serve an HTML version, this will run a web server that will serve you locally documentation :
 
 ```bash
-make serve
+gendocs.sh serve
 ```
 
 Generate doxygen documentation:
 
 ```bash
-make doxygen
+gendocs.sh doxygen
+```
+or
+```bash
+cd build && make doxygen
 ```
\ No newline at end of file
diff --git a/gendocs.sh b/gendocs.sh
new file mode 100755 (executable)
index 0000000..9d9b74a
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+SCRIPT=$(basename $BASH_SOURCE)
+
+function usage() {
+       cat <<EOF >&2
+Usage: $SCRIPT [options] [pdf|serve|doxygen]
+
+Options:
+   --debug
+      enable debug when generating pdf or html documentation
+   -d|--dry
+      dry run
+   -h|--help
+      get this help
+
+Example:
+       $SCRIPT pdf
+
+EOF
+       exit 1
+}
+
+function info() {
+       echo "$@" >&2
+}
+
+#default values
+DEBUG_FLAG=""
+DRY=""
+DO_ACTION=""
+OUT_DIR=./build
+
+[[ $? != 0 ]] && usage
+while [ $# -gt 0 ]; do
+       case "$1" in
+               --debug) DEBUG_FLAG="--log=debug --debug";;
+               -d|--dry) DRY=echo;;
+               -h|--help) usage;;
+        pdf | serve | doxygen) DO_ACTION=$1;;
+               --) break;;
+       esac
+    shift
+done
+
+cd $(dirname $0)
+ROOTDIR=`pwd -P`
+
+# Create out dir if needed
+[ -d $OUT_DIR ] || mkdir -p $OUT_DIR
+
+if [ "$DO_ACTION" = "pdf" -o "$DO_ACTION" = "serve" ]; then
+    GITBOOK=`which gitbook`
+    [ "$?" = "1" ] && { echo "You must install gitbook first, using: sudo npm install -g gitbook-cli"; exit 1; }
+
+    EBCONV=`which ebook-convert`
+    [ "$?" = "1" ] && { echo "You must install calibre first, using: 'sudo apt install calibre' or refer to https://calibre-ebook.com/download"; exit 1; }
+
+    if [ "$DO_ACTION" = "pdf" ]; then
+        $DRY $GITBOOK pdf $ROOTDIR $OUT_DIR/LowLevelCanBinder_Guide.pdf $DEBUG_FLAG
+    else
+        $DRY $GITBOOK serve $DEBUG_FLAG
+    fi
+
+elif [ "$DO_ACTION" = "doxygen" ]; then
+    $DRY cd $OUT_DIR && cmake .. && make doxygen $ROOTDIR/Doxyfile
+
+else
+    echo "Unknown action !"
+    usage
+fi