[gtkmm-documentation] Update the meson.build files and the auxiliary scripts



commit 4c303e6cc7bf19ffbb21cbe90ee201b36937bfcb
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Apr 30 15:50:22 2019 +0200

    Update the meson.build files and the auxiliary scripts
    
    meson+ninja can now validate XML files and build a PDF file.

 README                                 | 13 ++++--
 docs/tutorial/meson.build              | 50 ++++++++++++++++++-----
 examples/book/meson.build              | 24 +++++++----
 examples/meson.build                   | 28 +++++++++++--
 meson.build                            | 73 +++++++++++++++++++++-------------
 meson_options.txt                      | 15 +++++--
 tools/meson_aux/extra-dist-cmd.sh      | 32 +++++++++++----
 tools/meson_aux/tutorial-custom-cmd.sh | 38 ++++++++++++++----
 8 files changed, 203 insertions(+), 70 deletions(-)
---
diff --git a/README b/README
index 7d8698f..6e835de 100644
--- a/README
+++ b/README
@@ -3,13 +3,13 @@ See http://www.gtkmm.org/
 
 Building with meson
 -------------------
-This is experimental and incomplete.
-Use autotools for production builds.
+This is experimental, but it's believed to work correctly.
+You're encouraged to test it.
 
 Create a build directory:
   $ cd gtkmm-documentation
   $ meson <build-dir>
-Do not call the build-dir gtkmm-documenation/build. There is already such a
+Do not call the build-dir gtkmm-documentation/build. There is already such a
 directory, used when building with autotools.
 
 Create the html files of the tutorial:
@@ -28,8 +28,15 @@ Print a list of configuration options:
 Example of changing options:
   $ meson configure --prefix=/opt/gnome -Dwarnings=fatal
 
+Create a PDF file
+  $ meson -Dbuild-pdf=true
+  $ ninja
+This requires that you have the xmllint and docbook2pdf commands installed.
+
 Make a tarball:
   $ ninja dist
+
 This tarball is not identical to one made with "make dist" or "make distcheck".
 There is e.g. no "configure" file. If you want to use a tarball made with
 "ninja dist" for building with autotools, you have to start with ./autogen.sh.
+"make dist" and "make distcheck" don't distribute the meson.build files.
diff --git a/docs/tutorial/meson.build b/docs/tutorial/meson.build
index 8fc8a27..7e664fd 100644
--- a/docs/tutorial/meson.build
+++ b/docs/tutorial/meson.build
@@ -1,15 +1,23 @@
 # docs/tutorial
 
 # input: gtkmm_datadir, gtkmm_pcname, tutorial_custom_cmd_sh
-# output: tutorial_languages
+# output: can_parse_and_validate, build_translations_by_default, can_build_translations,
+#         build_pdf_by_default, can_build_pdf, tutorial_languages
 
 xsltproc = find_program('xsltproc', required: true)
 perl = find_program('perl', required: true)
 xmllint = find_program('xmllint', required: false)
 
+can_parse_and_validate = xmllint.found()
+
 can_build_translations = find_program('msgfmt', required: false).found() and \
                          find_program('itstool', required: false).found()
 build_translations_by_default = get_option('build-translations')
+validate = get_option('validation') ? 'true' : 'false'
+
+can_build_pdf = find_program('docbook2pdf', required: false).found() and \
+                xmllint.found()
+build_pdf_by_default = get_option('build-pdf')
 
 tutorial_languages = ['cs', 'de', 'el', 'es', 'fr', 'pt_BR', 'sl', 'zh_CN']
 
@@ -141,6 +149,7 @@ xslt_params = [
   '--stringparam', 'use.id.as.filename', '1',
 ]
 
+# Create a DocBook C locale XML file with the examples' source code included.
 index_docbook = custom_target('index.docbook',
   input: join_paths('C', 'index-in.docbook'),
   output: 'index.docbook',
@@ -154,6 +163,7 @@ index_docbook = custom_target('index.docbook',
   build_by_default: true
 )
 
+# Create an html version of the C locale's version of the DocBook.
 custom_target('html_index.html',
   input: index_docbook,
   output: 'html',
@@ -171,13 +181,14 @@ custom_target('html_index.html',
   install_dir: tutorialdir
 )
 
-if xmllint.found()
+if can_parse_and_validate
+  # Parse and possibly validate the C locale's version of the DocBook.
   custom_target('C-xmllint',
     input: index_docbook,
     output: 'C_xmllint.stamp',
     command: [
-      tutorial_custom_cmd_sh,
-      'xmllint',
+      tutorial_custom_cmd_sh, 'xmllint',
+      validate,
       '@INPUT@',
       '@OUTPUT@'
     ],
@@ -186,13 +197,14 @@ if xmllint.found()
 endif
 
 if can_build_translations
+  # Create XML files with translations.
   foreach lang : tutorial_languages
+    # Create .mo files.
     po2mo = custom_target(lang + '-po2mo',
       input: join_paths(lang, lang + '.po'),
       output: lang + '_mo.stamp',
       command: [
-        tutorial_custom_cmd_sh,
-        'po2mo',
+        tutorial_custom_cmd_sh, 'po2mo',
         lang,
         meson.current_build_dir(),
         '@INPUT@',
@@ -202,12 +214,12 @@ if can_build_translations
       build_by_default: build_translations_by_default,
     )
 
+  # Create XML files.
     lang_index_docbook = custom_target(lang + '-index.docbook',
       input: [po2mo, index_docbook],
       output: lang + '_docbook.stamp',
       command: [
-        tutorial_custom_cmd_sh,
-        'docbook',
+        tutorial_custom_cmd_sh, 'docbook',
         join_paths(meson.current_build_dir(), lang, lang + '.mo'),
         '@INPUT1@',
         join_paths(meson.current_build_dir(), lang),
@@ -216,13 +228,14 @@ if can_build_translations
       build_by_default: build_translations_by_default,
     )
 
-    if xmllint.found()
+    if can_parse_and_validate
+      # Parse and possibly validate the translated version of the DocBook.
       custom_target(lang + '-xmllint',
         input: lang_index_docbook,
         output: lang + '_xmllint.stamp',
         command: [
-          tutorial_custom_cmd_sh,
-          'xmllint',
+          tutorial_custom_cmd_sh, 'xmllint',
+          validate,
           join_paths(meson.current_build_dir(), lang, 'index.docbook'),
           '@OUTPUT@'
         ],
@@ -232,6 +245,21 @@ if can_build_translations
   endforeach # lang
 endif # can_build_translations
 
+if can_build_pdf
+  # Create a PDF file of the C locale's version of the DocBook.
+  custom_target('C-pdf',
+    input: index_docbook,
+    output: 'programming-with-gtkmm.pdf',
+    command: [
+      tutorial_custom_cmd_sh, 'pdf',
+      '@INPUT@',
+      join_paths(meson.current_source_dir(), 'C', 'figures'),
+      '@OUTPUT@'
+    ],
+    build_by_default: build_pdf_by_default,
+  )
+endif
+
 install_data('style.css', install_dir: tutorial_htmldir)
 install_data(tutorial_figures, install_dir: tutorial_figuresdir)
 install_data(tutorial_icons, install_dir: tutorial_iconsdir)
diff --git a/examples/book/meson.build b/examples/book/meson.build
index 91cf473..45b9dcd 100644
--- a/examples/book/meson.build
+++ b/examples/book/meson.build
@@ -117,15 +117,23 @@ foreach ex : examples_book
     endif
   endforeach
 
-  # multi-threaded programs need thread support
-  deps = (ex[0][0] == 'multithread') ? [gtkmm_dep, thread_dep] : gtkmm_dep
+  if ex[0][0] == 'input'
+    # input/main.cc includes build/config.h.
+    exe_file = executable(ex_name, ex_sources, resources,
+      dependencies: gtkmm_dep,
+      include_directories: config_include_dir,
+      build_by_default: build_examples_by_default
+    )
+  else
+    # multi-threaded programs need thread support
+    deps = (ex[0][0] == 'multithread') ? [gtkmm_dep, thread_dep] : gtkmm_dep
 
-  exe_file = executable(ex_name, ex_sources, resources,
-    dependencies: deps,
-    gui_app: true,
-    include_directories: config_include_dir, # only input/example needs this
-    build_by_default: build_examples_by_default
-  )
+    exe_file = executable(ex_name, ex_sources, resources,
+      dependencies: deps,
+      gui_app: true,
+      build_by_default: build_examples_by_default
+    )
+  endif
 
   stamp_file_name = ex_name + '_copy.stamp'
   custom_target(stamp_file_name,
diff --git a/examples/meson.build b/examples/meson.build
index 7e6f830..6342979 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -1,9 +1,31 @@
 # examples
 
-# input: gnome, gtkmm_dep, giomm_dep, compile_schemas_sh, copy_to_subdir_sh,
-#        config_include_dir
+# input: gnome, gtkmm_dep, giomm_dep, compile_schemas_sh, copy_to_subdir_sh, is_dist
+# output: build_examples_by_default
 
-build_examples_by_default = get_option('build-examples')
+# examples/book/input/main.cc includes build/config.h.
+has_mkfifo = cpp_compiler.has_function('mkfifo')
+conf_data = configuration_data()
+conf_data.set('HAVE_MKFIFO', has_mkfifo)
+conf_file = configure_file(
+  output: 'config.h',
+  configuration: conf_data
+)
+custom_target('build_config',
+  input: conf_file,
+  output: 'config.stamp',
+  command: [
+    copy_to_subdir_sh,
+    '@INPUT@',
+    'build',
+    'config.h',
+    '@OUTPUT@',
+  ],
+  build_by_default: true
+)
+config_include_dir = include_directories('.')
+
+build_examples_by_default = get_option(is_dist ? 'build-dist-examples' : 'build-examples')
 examples_targets = []
 
 subdir('book')
diff --git a/meson.build b/meson.build
index 7ef7b88..e95b047 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,4 @@
-# Building gtkmm-documentation with meson is experimental.
-# Use autotools for production builds.
+# This file is part of gtkmm-documentation.
 
 project('gtkmm-documentation', 'c', 'cpp',
   version: '3.89.0',
@@ -24,7 +23,12 @@ tutorial_custom_cmd_sh = files(join_paths('tools', 'meson_aux', 'tutorial-custom
 
 cpp_compiler = meson.get_compiler('cpp')
 
-warning_level = get_option('warnings')
+# Is this configuration done during creation of a tarball (ninja dist)?
+# The "real" source directory contains a .git subdirectory. The temporary
+# source directory created by "ninja dist" does not.
+is_dist = run_command('test', '-d', join_paths(meson.current_source_dir(), '.git')).returncode() != 0
+
+warning_level = get_option(is_dist ? 'dist-warnings' : 'warnings')
 warning_flags = []
 if warning_level == 'min'
   warning_flags = [ '-Wall' ]
@@ -42,36 +46,51 @@ endif
 warning_flags = cpp_compiler.get_supported_arguments(warning_flags)
 add_project_arguments(warning_flags, language: 'cpp')
 
-# This fix is necessary to make examples/book/input/example compile.
-# TODO: Improve it.
-has_mkfifo = cpp_compiler.has_function('mkfifo')
-conf_data = configuration_data()
-conf_data.set('HAVE_MKFIFO', has_mkfifo)
-conf_file = configure_file(
-  output: 'config.h',
-  configuration: conf_data
-)
-custom_target('build_config',
-  input: conf_file,
-  output: 'config.stamp',
-  command: [
-    copy_to_subdir_sh,
-    '@INPUT@',
-    'build',
-    'config.h',
-    '@OUTPUT@',
-  ],
-  build_by_default: true
-)
-config_include_dir = include_directories('.')
-# end of examples/book/input/example fix
-
 subdir('docs/tutorial')
 subdir('examples')
 
+# Modify the contents of the distribution directory.
 meson.add_dist_script(
   join_paths('tools', 'meson_aux', 'extra-dist-cmd.sh'),
+  meson.current_source_dir(),
   meson.current_build_dir(),
   join_paths('meson-dist', meson.project_name() + '-' + meson.project_version()),
   ' '.join(tutorial_languages)
 )
+
+# Print a summary.
+validate = get_option('validation') and can_parse_and_validate
+explain_val = ''
+if get_option('validation') and not validate
+  explain_val = ' (requires xmllint)'
+endif
+
+build_translations = build_translations_by_default and can_build_translations
+explain_trans = ''
+if build_translations_by_default and not build_translations
+  explain_trans = ' (requires msgfmt and itstool)'
+endif
+
+build_pdf = build_pdf_by_default and can_build_pdf
+explain_pdf = ''
+if build_pdf_by_default and not build_pdf
+  explain_pdf = ' (requires xmllint and docbook2pdf)'
+endif
+
+summary = [
+  '',
+  '------',
+  meson.project_name() + ' ' + meson.project_version(),
+  '',
+  '    Build examples: @0@'.format(build_examples_by_default),
+  ' Compiler warnings: @0@'.format(warning_level),
+  '    XML validation: @0@@1@'.format(validate, explain_val),
+  'Build translations: @0@@1@'.format(build_translations, explain_trans),
+  '         Build PDF: @0@@1@'.format(build_pdf, explain_pdf),
+  'Directories:',
+  '            prefix: @0@'.format(gtkmm_prefix),
+  '           datadir: @0@'.format(gtkmm_datadir),
+  '------'
+]
+
+message('\n'.join(summary))
diff --git a/meson_options.txt b/meson_options.txt
index 26d4486..6643355 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,7 +1,14 @@
 option('warnings', type: 'combo', choices : ['no', 'min', 'max', 'fatal'], value : 'min',
-  description : 'Set compiler pedantry level')
+  description : 'Compiler warning level')
+option('dist-warnings', type: 'combo', choices : ['no', 'min', 'max', 'fatal'], value : 'fatal',
+  description : 'Compiler warning level when creating distribution tarball')
 option('build-examples', type: 'boolean', value: false,
-  description : 'Build all example programs by default')
+  description : 'Build all example programs')
+option('build-dist-examples', type: 'boolean', value: true,
+  description : 'Build all example programs when creating distribution tarball')
+option('validation', type: 'boolean', value: true,
+  description : 'Validate generated XML files')
 option('build-translations', type: 'boolean', value: true,
-  description : 'Build translated tutorials by default')
-
+  description : 'Build translated tutorials')
+option('build-pdf', type: 'boolean', value: false,
+  description : 'Build tutorial PDF file')
diff --git a/tools/meson_aux/extra-dist-cmd.sh b/tools/meson_aux/extra-dist-cmd.sh
index d734051..1cb4307 100755
--- a/tools/meson_aux/extra-dist-cmd.sh
+++ b/tools/meson_aux/extra-dist-cmd.sh
@@ -2,16 +2,34 @@
 
 # External command, intended to be called with add_dist_script() in meson.build
 
-# extra-dist-cmd.sh <root_build_dir> <relative_dist_dir> <tutorial_languages>
+# extra-dist-cmd.sh <root_source_dir> <root_build_dir> <relative_dist_dir> <tutorial_languages>
 
 # relative_dist_dir is the distribution directory path relative to root_build_dir.
+# Meson does not preserve timestamps on distributed files. Neither does this script.
+
+# Make a ChangeLog file for distribution.
+git --git-dir="$1/.git" --work-tree="$1" log --no-merges --date=short --max-count=200 \
+    --pretty='tformat:%cd  %an  <%ae>%n%n  %s%n%w(0,0,2)%+b' > "$2/$3/ChangeLog"
 
 # Distribute some built files in addition to the files in the local git clone.
-cd "$1"
-# English index.docbook and html files
-cp "docs/tutorial/index.docbook" "$2/docs/tutorial/C/"
-cp --recursive "docs/tutorial/html/" "$2/docs/tutorial/"
+cd "$2"
+dist_docs_tutorial="$3/docs/tutorial"
+
+# English index.docbook and html files.
+cp "docs/tutorial/index.docbook" "$dist_docs_tutorial/C/"
+cp --recursive "docs/tutorial/html/" "$dist_docs_tutorial/"
+
 # .mo files with translations and translated index.docbook files.
-for lang in $3; do
-  cp "docs/tutorial/$lang/$lang.mo" "docs/tutorial/$lang/index.docbook" "$2/docs/tutorial/$lang/"
+for lang in $4; do
+  cp "docs/tutorial/$lang/$lang.mo" "docs/tutorial/$lang/index.docbook" "$dist_docs_tutorial/$lang/"
 done
+
+# If there is an updated PDF file, include it in the tarball.
+pdf_file="docs/tutorial/programming-with-gtkmm.pdf"
+if [ -f "$pdf_file" -a "$pdf_file" -nt "docs/tutorial/index.docbook" ]; then
+  cp "$pdf_file" "$dist_docs_tutorial/C/"
+fi
+
+# Remove all .gitignore files and an empty $3/build directory.
+find "$3" -name ".gitignore" -exec rm '{}' \;
+rmdir --ignore-fail-on-non-empty "$3/build"
diff --git a/tools/meson_aux/tutorial-custom-cmd.sh b/tools/meson_aux/tutorial-custom-cmd.sh
index 765b552..878b9df 100755
--- a/tools/meson_aux/tutorial-custom-cmd.sh
+++ b/tools/meson_aux/tutorial-custom-cmd.sh
@@ -2,18 +2,42 @@
 
 # External command, intended to be called with custom_target() in meson.build
 
-if [ "x$1" = "xpo2mo" ]; then
+case $1 in
+po2mo)
   # tutorial-custom-cmd.sh po2mo <relative_dir_name> <build_dir> <input_po_file> <output_mo_file> 
<stamp_file_path>
   ( cd "$3"; mkdir --parents "$2" )
   msgfmt -o "$5" "$4"
   touch "$6"
-elif [ "x$1" = "xdocbook" ]; then
+  ;;
+docbook)
   # tutorial-custom-cmd.sh docbook <input_mo_file> <input_xml_file> <output_xml_dir> <stamp_file_path>
+  # Create XML file with translation.
   itstool -m "$2" -o "$4" "$3"
   touch "$5"
-elif [ "x$1" = "xxmllint" ]; then
-  # tutorial-custom-cmd.sh xmllint <input_xml_file> <stamp_file_path>
-  xmllint --nonet --noout --noent --path "$(dirname "$2")" --xinclude "$2"
-  touch "$3"
-fi
+  ;;
+xmllint)
+  # tutorial-custom-cmd.sh xmllint <validate> <input_xml_file> <stamp_file_path>
+  validate=""
+  if [ "x$2" = "xtrue" ]; then
+    validate="--postvalid"
+  fi
+  xmllint --noout --noent --xinclude $validate "$3"
+  touch "$4"
+  ;;
+pdf)
+  # tutorial-custom-cmd.sh pdf <input_xml_file> <figures_dir> <output_pdf_file>
+  output_dir="$(dirname "$4")"
+  output_basename="$(basename -s .pdf "$4")"
+  xml_file="$output_dir/$output_basename.xml"
+
+  # We need to produce a full examples XML with all of the XIncludes done.
+       xmllint --xinclude --postvalid --output "$xml_file" "$2"
+
+       # We also need to copy the figures from the source directory, so they
+       # can be found from the XML files.
+       cp --preserve --recursive "$3" "$output_dir/$(basename "$3")"
+
+       docbook2pdf --output "$output_dir" "$xml_file"
+       ;;
+esac
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]