Doc: Added nested index structure

This patch adjusts the structure of documentation, making it
easier to organise and navigate.

* Modifies index.rst.in decoupled from cmake index.rst.
* Creates respective indexes in the documentation sub-directories
  and links them to the master index
* External component documentation is preserved
* CMAKE build system is updated to automate the document listing
  in the design_documents index instead of the master index.

Change-Id: I697b68e19dc57ecf7f36bc6dd8248fe345bdad61
Signed-off-by: Galanakis, Minos <minos.galanakis@arm.com>
diff --git a/cmake/Common/BuildSphinxDoc.cmake b/cmake/Common/BuildSphinxDoc.cmake
index 74ead01..3aea00f 100644
--- a/cmake/Common/BuildSphinxDoc.cmake
+++ b/cmake/Common/BuildSphinxDoc.cmake
@@ -76,9 +76,10 @@
 	set(SPHINXCFG_TEMPLATE_FILE "${TFM_ROOT_DIR}/docs/conf.py.in")
 	set(SPHINXCFG_CONFIGURED_FILE "${SPHINXCFG_OUTPUT_PATH}/conf.py")
 
-	set(SPHINX_TEMPLATE_INDEX_FILE "${TFM_ROOT_DIR}/docs/index.rst.in")
-	set(SPHINX_CONFIGURED_INDEX_FILE "${SPHINX_TMP_DOC_DIR}/index.rst")
 	set(SPHINX_DESIGN_DOC_ROOT "${TFM_ROOT_DIR}/docs/design_documents")
+	set(SPHINX_TEMPLATE_INDEX_FILE "${SPHINX_DESIGN_DOC_ROOT}/index.rst.in")
+	set(SPHINX_CONFIGURED_INDEX_FILE "${SPHINX_TMP_DOC_DIR}/docs/design_documents/index.rst")
+	set(SPHINX_MAIN_INDEX_FILE "docs/index.rst")
 
 	#Version ID of TF-M.
 	#TODO: this shall not be hard-coded here. We need a process to define the
@@ -111,6 +112,7 @@
 		COMMAND "${CMAKE_COMMAND}" -D TFM_ROOT_DIR=${TFM_ROOT_DIR}
 				-D DST_DIR=${SPHINX_TMP_DOC_DIR}
 				-D BINARY_DIR=${CMAKE_BINARY_DIR}
+				-D MASTER_IDX=${SPHINX_MAIN_INDEX_FILE}
 				-P "${TFM_ROOT_DIR}/cmake/SphinxCopyDoc.cmake"
 		WORKING_DIRECTORY "${TFM_ROOT_DIR}"
 		DEPENDS run-allways
diff --git a/cmake/SphinxCopyDoc.cmake b/cmake/SphinxCopyDoc.cmake
index e95757c..6bf2f07 100644
--- a/cmake/SphinxCopyDoc.cmake
+++ b/cmake/SphinxCopyDoc.cmake
@@ -26,10 +26,11 @@
 #
 #Usage:
 #   cmake -DDST_DIR=<path to destination> -DTFM_ROOT_DIR=<path to tf-m root> \
-#          -DBINARY_DIR=${CMAKE_BINARY_DIR} -P SphinxCopyDoc.cmake
+#          -DBINARY_DIR=${CMAKE_BINARY_DIR}
+#          -DMASTER_IDX=<path to master index.rst> -P SphinxCopyDoc.cmake
 
 #Check input parameters
-foreach(_PARAM IN ITEMS TFM_ROOT_DIR DST_DIR BINARY_DIR)
+foreach(_PARAM IN ITEMS TFM_ROOT_DIR DST_DIR BINARY_DIR MASTER_IDX)
 	if (NOT DEFINED ${_PARAM})
 		message(FATAL_ERROR "Variable ${_PARAM} is undefined. Please add -D${_PARAM}=<...> when calling this script.")
 	endif()
@@ -56,5 +57,9 @@
 #Copy files with directory tree.
 foreach(_FILE ${_COPY_FILES})
 	get_filename_component(_DIR ${_FILE} DIRECTORY)
-	file(COPY ${_FILE} DESTINATION "${DST_DIR}/${_DIR}")
+	if (_FILE STREQUAL MASTER_IDX)
+		file(COPY ${_FILE} DESTINATION "${DST_DIR}")
+	else()
+		file(COPY ${_FILE} DESTINATION "${DST_DIR}/${_DIR}")
+	endif()
 endforeach()
diff --git a/cmake/SphinxDesignDocStatus.cmake b/cmake/SphinxDesignDocStatus.cmake
index e76c448..88438d3 100644
--- a/cmake/SphinxDesignDocStatus.cmake
+++ b/cmake/SphinxDesignDocStatus.cmake
@@ -20,7 +20,7 @@
 Include(CMakeParseArguments)
 
 #This function will search for .rst files in a given directory, read them and
-#check if the “:Status:” field is defined in them. Then will add each file to a
+#check if the ":Status:" field is defined in them. Then will add each file to a
 #list with a name matching the status value.
 #See the definition of _STATE_VALUES below for a list of valid state values.
 #Files with missing or invalid state value will be placed on the "unknown" list.
@@ -174,15 +174,16 @@
 
 		#Loop over files on the list of this status
 		foreach(_FILE IN LISTS _DD_${_STATUS})
-			#Get the path of the file relative to the document root
-			file(RELATIVE_PATH _REL_FILE ${_MY_PARAMS_DOC_ROOT} ${_FILE})
+
+			# Strip path from the filesince index is placed in same location
+			get_filename_component(_FILE ${_FILE} NAME)
 			#Detailed and Draft files go to the same section
 			if (_STATUS STREQUAL "DETAILED")
 				set(_STATUS "DRAFT")
 			endif()
 
 			#Append the file to the output string
-			string(APPEND ${_STATUS}_DD_LIST "\n    ${_REL_FILE}")
+			string(APPEND ${_STATUS}_DD_LIST "\n    ${_FILE}")
 		endforeach()
 	endforeach()