]> git.saurik.com Git - apt.git/commitdiff
CMake: Add initial support for documentation building
authorJulian Andres Klode <jak@debian.org>
Sat, 6 Aug 2016 19:18:39 +0000 (21:18 +0200)
committerJulian Andres Klode <jak@debian.org>
Sat, 6 Aug 2016 20:36:02 +0000 (22:36 +0200)
Build HTML docbook guides (untranslated) and manual pages
(including translations). Also install the examples in the
example subdirectory.

Translation of docbook guides has not been implemented yet,
but should be easy to do. The code also needs some cleanup
to automatically detect the available translations.

CMake/Documentation.cmake [new file with mode: 0644]
CMakeLists.txt
README.cmake
doc/CMakeLists.txt [new file with mode: 0644]
doc/examples/CMakeLists.txt [new file with mode: 0644]

diff --git a/CMake/Documentation.cmake b/CMake/Documentation.cmake
new file mode 100644 (file)
index 0000000..98e0717
--- /dev/null
@@ -0,0 +1,134 @@
+# Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+function(add_docbook target sourcefiles installdest)
+    foreach(file ${sourcefiles})
+        get_filename_component(relfile ${file} NAME)
+        string(REPLACE ".dbk" "" manual ${relfile})
+        get_filename_component(absolute ${file} ABSOLUTE)
+
+        add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html/
+            COMMAND xsltproc --nonet --novalid --xinclude
+                             --stringparam base.dir ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html/
+                             --path ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/${CURRENT_VENDOR}/
+                             --path ${CMAKE_CURRENT_SOURCE_DIR}/
+                             ${CMAKE_CURRENT_SOURCE_DIR}/docbook-html-style.xsl
+                             ${absolute}
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+            DEPENDS ${file}
+        )
+        set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html)
+        if (NOT ${installdest} EQUAL "" )
+        install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html
+            DESTINATION ${installdest})
+        endif()
+    endforeach(file ${sourcefiles})
+
+    add_custom_target(${target} ALL DEPENDS ${commands})
+endfunction()
+
+
+function(add_po4a type master po target deps)
+    add_custom_command(OUTPUT ${target}
+        COMMAND po4a-translate --keep 0 -f ${type} -m ${master}
+                               -p ${po} -l ${target}
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        DEPENDS ${deps} ${master} ${po})
+endfunction()
+
+
+# Macro for XML man pages.
+function(add_xml_manpages target manpages translations entities)
+    foreach(manpage ${manpages})
+        string(LENGTH ${manpage} manpage_length)
+        math(EXPR manpage_length ${manpage_length}-1)
+        string(SUBSTRING ${manpage} ${manpage_length} 1 section)
+
+        add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
+                COMMAND xsltproc --path ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/${CURRENT_VENDOR}/
+                                 --path ${CMAKE_CURRENT_SOURCE_DIR}/
+                                 ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl
+                                 ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl
+        )
+
+
+        set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manpage})
+
+        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
+                DESTINATION ${CMAKE_INSTALL_MANDIR}/man${section})
+
+        # Add the translations for the manpage.
+        foreach(translation ${translations})
+            set(entities)
+            # transdir = shortcut to the output directory for translations.
+            set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
+
+            add_po4a(docbook ${manpage}.xml po/${translation}.po
+                             ${transdir}/${manpage}.xml "${ent_cmds}")
+
+
+            add_custom_command(OUTPUT ${transdir}/${manpage}
+                COMMAND xsltproc --path ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/${CURRENT_VENDOR}/
+                                 --path ${CMAKE_CURRENT_SOURCE_DIR}/
+                                 --stringparam l10n.gentext.default.language ${translation}
+                                 ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl
+                                 ${transdir}/${manpage}.xml
+                WORKING_DIRECTORY ${transdir}
+                DEPENDS ${transdir}/${manpage}.xml
+                DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl)
+
+            set(nls-cmd ${nls-cmd} ${transdir}/${manpage})
+            install(FILES ${transdir}/${manpage}
+                    DESTINATION ${CMAKE_INSTALL_MANDIR}/${translation}/man${section})
+
+        endforeach(translation ${translations})
+    endforeach(manpage ${manpages})
+
+    add_custom_target(${target} ALL DEPENDS ${commands})
+    # Sort the list of the translations.
+    list(SORT nls-cmd)
+    add_custom_target(nls-${target} ALL DEPENDS ${nls-cmd})
+endfunction()
+
+
+function(add_manpages target manpages translations)
+    foreach(man ${manpages})
+        string(LENGTH ${man} manpage_length)
+        math(EXPR manpage_length ${manpage_length}-1)
+        string(SUBSTRING ${man} ${manpage_length} 1 section)
+        install(FILES ${man} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${section})
+
+        if (USE_NLS)
+            foreach(translation ${translations})
+                set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
+                add_po4a(man ${man} po/${translation}.po ${transdir}/${man} "")
+                install(FILES ${transdir}/${man}
+                        DESTINATION ${CMAKE_INSTALL_MANDIR}/${translation}/man${section})
+                set(files ${files} ${transdir}/${man})
+            endforeach(translation ${translations})
+        endif()
+    endforeach(man ${manpages})
+    add_custom_target(${target} ALL DEPENDS ${files})
+endfunction()
index cba89322706faeb4e09bb9a2fbcab83ceec38fc0..defb4f1112c20b755f99b222786ef4b625c4806a 100644 (file)
@@ -128,6 +128,7 @@ add_subdirectory(apt-pkg)
 add_subdirectory(apt-private)
 add_subdirectory(apt-inst)
 add_subdirectory(cmdline)
+add_subdirectory(doc)
 add_subdirectory(dselect)
 add_subdirectory(ftparchive)
 add_subdirectory(methods)
index d94a46f12e4f5ff772ef9e6e5eb93689655ef480..a993b25890a3fe5a25304bc6ca7c2df04801d7c0 100644 (file)
@@ -31,7 +31,6 @@ TODO
 
 The following features have not been implemented yet:
 
- - documentation
  - Translated docbook guides
  - dselect translations
  - unit tests
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..bbf5fb0
--- /dev/null
@@ -0,0 +1,21 @@
+include(Documentation)
+
+file(GLOB_RECURSE debiandoc-apt guide*.dbk offline*.dbk)
+file(GLOB_RECURSE debiandoc-libapt cache*.dbk design*.dbk dpkg-tech*.dbk
+                                   files*.dbk method*.dbk)
+
+
+set(manpages apt.8 apt-cache.8 apt-get.8 apt-cdrom.8 apt.conf.5 sources.list.5
+             apt-config.8 apt_preferences.5 apt-sortpkgs.1 apt-ftparchive.1
+             apt-extracttemplates.1 apt-key.8 apt-secure.8 apt-mark.8)
+
+if (WITH_DOC)
+add_docbook(debiandoc-apt "${debiandoc-apt}" share/doc/apt-doc)
+add_docbook(debiandoc-libapt "${debiandoc-libapt}" share/doc/libapt-pkg-doc)
+endif()
+
+# Build the manpages, and add translations (ja only for now, others broken)
+add_xml_manpages(doc-man "${manpages}" "de;es;fr;it;ja;nl;pl;pt_BR;pt" "apt.ent;apt-verbatim.ent")
+
+
+add_subdirectory(examples)
diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1998867
--- /dev/null
@@ -0,0 +1,4 @@
+install(FILES apt.conf apt-https-method-example.conf configure-index preferences
+        DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples)
+install(FILES apt-ftparchive.conf ftp-archive.conf
+        DESTINATION ${CMAKE_INSTALL_DOCDIR}/../apt-utils/examples)