aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/generate-doc.sh
blob: 45ae81803126c7402d3150f967a03660116a54a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh

help()
{
	echo "Generate and add eclipse help from yocto's documentation"
	echo -e "Usage: $0 BRANCH_NAME | TAG_NAME PLUGIN_FOLDER\n"
	echo "Options:"
	echo "-h - display this help and exit"
	echo "TAG_NAME - tag to build the documentation upon"
	echo "BRANCH_NAME - branch to build the documentation upon"
	echo "PLUGIN_FOLDER - root folder of the eclipse-poky project"
	exit 1
}

fail ()
{
  local retval=$1
  shift $1
  echo "[Fail $retval]: $*"
  echo "BUILD_TOP=${BUILD_TOP}"
  cd ${TOP}
  exit ${retval}
}

safe_sed()
{
  if [ "$1" ] && [ "$2" ]; then
     sed -e "$1" $2 > $2.tmp && mv $2.tmp $2 || fail $? "safe_sed $1 $2"
  else
     fail 1 "usage: safe_sed \"s/from/to/\" /path/to/file"
  fi
}

CHECKOUT_TAG=0
while getopts ":h" opt; do
	case $opt in
		h)
			help
			;;
	esac
done
shift $(($OPTIND - 1))

if [ $# -ne 2 ]; then
	help
fi

PLUGIN_FOLDER=`readlink -f $2`

TOP=`pwd`

DOC_DIR=${PLUGIN_FOLDER}/docs
rm -rf ${DOC_DIR}
DOC_PLUGIN_DIR=${PLUGIN_FOLDER}/plugins/org.yocto.doc.user
DOC_HTML_DIR=${DOC_PLUGIN_DIR}/html/

# git clone
DOC_GIT=http://git.yoctoproject.org/git/yocto-docs
git clone ${DOC_GIT} ${DOC_DIR} || fail $? "git clone ${DOC_GIT}"
cd ${DOC_DIR}

git checkout $1 || fail $? "git checkout $1"
COMMIT_ID=`git rev-parse HEAD`

# check yocto-docs branch/tag and build sdk-manual or adt-manual accordingly
# [YOCTO #9622]
if [ "$1" = "master" ] || [ "$1" = "krogoth" ] || [ "$1" = "yocto-2.1" ]; then
  DOCS="yocto-project-qs sdk-manual kernel-dev \
        bsp-guide ref-manual dev-manual profile-manual"
else
  DOCS="yocto-project-qs adt-manual kernel-dev \
        bsp-guide ref-manual dev-manual profile-manual"
  safe_sed "s/sdk-manual/adt-manual/" ${DOC_PLUGIN_DIR}/plugin.xml
  safe_sed "s/sdk-manual/adt-manual/" ${DOC_PLUGIN_DIR}/about.html.in
  safe_sed "s/Software Development Kit (SDK)/Application/" ${DOC_PLUGIN_DIR}/about.html.in
  safe_sed "s/(SDK)/(ADT)/" ${DOC_PLUGIN_DIR}/about.html.in
  safe_sed "s/sdk-manual/adt-manual/" ${DOC_PLUGIN_DIR}/toc.xml
  safe_sed "s/Software Development Kit (SDK)/Application/" ${DOC_PLUGIN_DIR}/toc.xml
fi

# build and copy
cd documentation
for DOC in ${DOCS}; do
	make DOC=${DOC} eclipse || fail $? "make DOC=${DOC} eclipse"
	cp -rf ${DOC}/eclipse/html/* ${DOC_HTML_DIR}
	cp -f ${DOC}/eclipse/${DOC}-toc.xml ${DOC_HTML_DIR}
done

sed -e "s/@.*@/${COMMIT_ID}/" < ${DOC_PLUGIN_DIR}/about.html.in > ${DOC_PLUGIN_DIR}/about.html

cd ${TOP}