[gtkmm] tools/gen_scripts: Update for non-source-dir builds



commit 7af92476e55cda7c15c2bd43ad9b3882eeefebea
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Dec 28 19:14:22 2018 +0100

    tools/gen_scripts: Update for non-source-dir builds
    
    Most modules (e.g. gtk+) can be built in a directory separated from the
    source directory. Update the scripts that generate .defs and doc.xml files
    to handle that. See !11.
    The environment variable JHBUILD_SOURCES is not used any more.
    Instead the environment variables GMMPROC_GEN_SOURCE_DIR and
    GMMPROC_GEN_BUILD_DIR are read. See comments in init_generate.sh.

 tools/gen_scripts/gdk_generate_docs.sh       | 25 +++++---------
 tools/gen_scripts/gdk_generate_enums.sh      | 23 +++++--------
 tools/gen_scripts/gdk_generate_extra_defs.sh |  8 ++---
 tools/gen_scripts/gdk_generate_methods.sh    | 33 +++++++-----------
 tools/gen_scripts/generate_docs_and_defs.sh  |  2 ++
 tools/gen_scripts/gtk_generate_docs.sh       | 25 +++++---------
 tools/gen_scripts/gtk_generate_enums.sh      | 19 ++++-------
 tools/gen_scripts/gtk_generate_extra_defs.sh | 18 +++++-----
 tools/gen_scripts/gtk_generate_methods.sh    | 19 ++++-------
 tools/gen_scripts/init_generate.sh           | 51 ++++++++++++++++++++++++++++
 10 files changed, 117 insertions(+), 106 deletions(-)
---
diff --git a/tools/gen_scripts/gdk_generate_docs.sh b/tools/gen_scripts/gdk_generate_docs.sh
index b4778e24..1ccb7400 100755
--- a/tools/gen_scripts/gdk_generate_docs.sh
+++ b/tools/gen_scripts/gdk_generate_docs.sh
@@ -1,25 +1,18 @@
 #!/bin/bash
 
-# Note that JHBUILD_SOURCES should be defined to contain the path to the root
-# of the jhbuild sources. The script assumes that it resides in the
-# tools/gen_scripts/ directory and the XML file will be placed in gdk/src.
+# The script assumes that it resides in the tools/gen_scripts/ directory and
+# the XML file will be placed in gdk/src.
 
-if [ -z "$JHBUILD_SOURCES" ]; then
-  echo -e "JHBUILD_SOURCES must contain the path to the jhbuild sources."
-  exit 1;
-fi
+source "$(dirname "$0")/init_generate.sh"
 
-PREFIX="$JHBUILD_SOURCES"
-ROOT_DIR="$(dirname "$0")/../.."
-OUT_DIR="$ROOT_DIR/gdk/src"
+out_dir="$root_dir/gdk/src"
 
-PARAMS="--with-properties --no-recursion"
-for dir in "$PREFIX"/gtk+/{gdk,gdk/deprecated} "$PREFIX"/gtk+/build/gdk \
-           "$PREFIX"/gdk-pixbuf/gdk-pixbuf "$PREFIX"/gdk-pixbuf/build/gdk-pixbuf; do
+params="--with-properties --no-recursion"
+for dir in "$gtk_source_prefix"/{gdk,gdk/deprecated} "$gtk_build_prefix"/gdk \
+           "$pixbuf_source_prefix"/gdk-pixbuf "$pixbuf_build_prefix"/gdk-pixbuf; do
   if [ -d "$dir" ]; then
-    PARAMS="$PARAMS -s $dir"
+    params="$params -s $dir"
   fi
 done
 
-DOCEXTRACT_TO_XML_PY="$JHBUILD_SOURCES/glibmm/tools/defs_gen/docextract_to_xml.py"
-$DOCEXTRACT_TO_XML_PY $PARAMS > "$OUT_DIR"/gdk_docs.xml
+"$gen_docs" $params > "$out_dir/gdk_docs.xml"
diff --git a/tools/gen_scripts/gdk_generate_enums.sh b/tools/gen_scripts/gdk_generate_enums.sh
index 748dbe0c..88db534b 100755
--- a/tools/gen_scripts/gdk_generate_enums.sh
+++ b/tools/gen_scripts/gdk_generate_enums.sh
@@ -1,24 +1,17 @@
 #!/bin/bash
 
-# Note that JHBUILD_SOURCES should be defined to contain the path to the root
-# of the jhbuild sources. The script assumes that it resides in the
-# tools/gen_scripts/ directory and the defs file will be placed in gdk/src.
+# The script assumes that it resides in the tools/gen_scripts/ directory and
+# the defs file will be placed in gdk/src.
 
-if [ -z "$JHBUILD_SOURCES" ]; then
-  echo -e "JHBUILD_SOURCES must contain the path to the jhbuild sources."
-  exit 1;
-fi
+source "$(dirname "$0")/init_generate.sh"
 
-PREFIX="$JHBUILD_SOURCES"
-ROOT_DIR="$(dirname "$0")/../.."
-OUT_DIR="$ROOT_DIR/gdk/src"
+out_dir="$root_dir/gdk/src"
 
 shopt -s extglob # Enable extended pattern matching
 shopt -s nullglob # Skip a filename pattern that matches no file
-ENUM_PL="$JHBUILD_SOURCES/glibmm/tools/enum.pl"
 # Process files whose names end with .h, but not with private.h.
 # Exclude gtk+/gdk/gdkinternals.h.
-$ENUM_PL "$PREFIX"/gtk+/gdk/!(*private|gdkinternals).h "$PREFIX"/gtk+/gdk/deprecated/!(*private).h \
-         "$PREFIX"/gtk+/build/gdk/*.h > "$OUT_DIR"/gdk_enums.defs
-$ENUM_PL "$PREFIX"/gdk-pixbuf/gdk-pixbuf/gdk!(*private).h \
-         "$PREFIX"/gdk-pixbuf/build/gdk-pixbuf/*.h > "$OUT_DIR"/gdk_pixbuf_enums.defs
+"$gen_enums" "$gtk_source_prefix"/gdk/!(*private|gdkinternals).h 
"$gtk_source_prefix"/gdk/deprecated/!(*private).h \
+             "$gtk_build_prefix"/gdk/*.h > "$out_dir"/gdk_enums.defs
+"$gen_enums" "$pixbuf_source_prefix"/gdk-pixbuf/gdk!(*private).h \
+             "$pixbuf_build_prefix"/gdk-pixbuf/*.h > "$out_dir"/gdk_pixbuf_enums.defs
diff --git a/tools/gen_scripts/gdk_generate_extra_defs.sh b/tools/gen_scripts/gdk_generate_extra_defs.sh
index d726fdf7..83c0a1d8 100755
--- a/tools/gen_scripts/gdk_generate_extra_defs.sh
+++ b/tools/gen_scripts/gdk_generate_extra_defs.sh
@@ -3,10 +3,10 @@
 # The script assumes that it resides in the tools/gen_scripts directory
 # and the defs file will be placed in gdk/src.
 
-ROOT_DIR="$(dirname "$0")/../.."
-GEN_DIR="$ROOT_DIR/tools/extra_defs_gen"
-OUT_DIR="$ROOT_DIR/gdk/src"
+source "$(dirname "$0")/init_generate.sh"
+
+out_dir="$root_dir/gdk/src"
 
 # Without LC_ALL=C documentation (docs "xxx") may be translated in the .defs file.
-LC_ALL=C "$GEN_DIR"/generate_defs_gdk > "$OUT_DIR"/gdk_signals.defs
+LC_ALL=C "$extra_defs_gen_dir"/generate_defs_gdk > "$out_dir"/gdk_signals.defs
 
diff --git a/tools/gen_scripts/gdk_generate_methods.sh b/tools/gen_scripts/gdk_generate_methods.sh
index fceb2ced..8160fd51 100755
--- a/tools/gen_scripts/gdk_generate_methods.sh
+++ b/tools/gen_scripts/gdk_generate_methods.sh
@@ -1,8 +1,7 @@
 #!/bin/bash
 
-# Note that JHBUILD_SOURCES should be defined to contain the path to the root
-# of the jhbuild sources. The script assumes that it resides in the
-# tools/gen_scripts/ directory and the defs file will be placed in gdk/src.
+# The script assumes that it resides in the tools/gen_scripts/ directory and
+# the defs file will be placed in gdk/src.
 
 # To update the gdk_methods.defs file:
 # 1. ./gdk_generate_methods.sh
@@ -17,34 +16,28 @@
 # 3. ./gdk_generate_methods.sh --make-patch
 # 4. Like step 2 when updating only the gdk_methods.defs files.
 
-if [ -z "$JHBUILD_SOURCES" ]; then
-  echo -e "JHBUILD_SOURCES must contain the path to the jhbuild sources."
-  exit 1;
-fi
+source "$(dirname "$0")/init_generate.sh"
 
-PREFIX="$JHBUILD_SOURCES"
-ROOT_DIR="$(dirname "$0")/../.."
-OUT_DIR="$ROOT_DIR/gdk/src"
+out_dir="$root_dir/gdk/src"
 
 shopt -s extglob # Enable extended pattern matching
 shopt -s nullglob # Skip a filename pattern that matches no file
 if [ $# -eq 0 ]
 then
-  H2DEF_PY="$JHBUILD_SOURCES/glibmm/tools/defs_gen/h2def.py"
   # Process files whose names end with .h, but not with private.h.
   # Exclude gtk+/gdk/gdkinternals.h.
-  $H2DEF_PY "$PREFIX"/gtk+/gdk/!(*private|gdkinternals).h "$PREFIX"/gtk+/gdk/deprecated/!(*private).h \
-            "$PREFIX"/gtk+/build/gdk/*.h > "$OUT_DIR"/gdk_methods.defs
-  $H2DEF_PY "$PREFIX"/gdk-pixbuf/gdk-pixbuf/gdk!(*private).h \
-            "$PREFIX"/gdk-pixbuf/build/gdk-pixbuf/*.h > "$OUT_DIR"/gdk_pixbuf_methods.defs
+  "$gen_methods" "$gtk_source_prefix"/gdk/!(*private|gdkinternals).h 
"$gtk_source_prefix"/gdk/deprecated/!(*private).h \
+                 "$gtk_build_prefix"/gdk/*.h > "$out_dir"/gdk_methods.defs
+  "$gen_methods" "$pixbuf_source_prefix"/gdk-pixbuf/gdk!(*private).h \
+                 "$pixbuf_build_prefix"/gdk-pixbuf/*.h > "$out_dir"/gdk_pixbuf_methods.defs
   # patch version 2.7.5 does not like directory names.
-  cd "$OUT_DIR"
-  PATCH_OPTIONS="--backup --version-control=simple --suffix=.orig"
-  patch $PATCH_OPTIONS gdk_methods.defs gdk_methods.defs.patch
+  cd "$out_dir"
+  patch_options="--backup --version-control=simple --suffix=.orig"
+  patch $patch_options gdk_methods.defs gdk_methods.defs.patch
 elif [ "$1" = "--make-patch" ]
 then
-  OUT_DIR_FILE="$OUT_DIR"/gdk_methods.defs
-  diff --unified=5 "$OUT_DIR_FILE".orig "$OUT_DIR_FILE" > "$OUT_DIR_FILE".patch
+  out_dir_file="$out_dir"/gdk_methods.defs
+  diff --unified=5 "$out_dir_file".orig "$out_dir_file" > "$out_dir_file".patch
 else
   echo "Usage: $0 [--make-patch]"
   exit 1
diff --git a/tools/gen_scripts/generate_docs_and_defs.sh b/tools/gen_scripts/generate_docs_and_defs.sh
index 3294ce74..e15dcfd6 100755
--- a/tools/gen_scripts/generate_docs_and_defs.sh
+++ b/tools/gen_scripts/generate_docs_and_defs.sh
@@ -3,6 +3,8 @@
 # Generate all docs.xml and .defs files, either for gdk or gtk or (default) both.
 # This script shall be executed from the tools/gen_scripts directory.
 
+cd "$(dirname "$0")"
+
 if [ $# -eq 0 ]
 then
   GENERATE_GDK_FILES="yes"
diff --git a/tools/gen_scripts/gtk_generate_docs.sh b/tools/gen_scripts/gtk_generate_docs.sh
index 44689def..fb34bca1 100755
--- a/tools/gen_scripts/gtk_generate_docs.sh
+++ b/tools/gen_scripts/gtk_generate_docs.sh
@@ -1,28 +1,21 @@
 #!/bin/bash
 
-# Note that JHBUILD_SOURCES should be defined to contain the path to the root
-# of the jhbuild sources. The script assumes that it resides in the
-# tools/gen_scripts/ directory and the XML file will be placed in gtk/src.
+# The script assumes that it resides in the tools/gen_scripts/ directory and
+# the XML file will be placed in gtk/src.
 
-if [ -z "$JHBUILD_SOURCES" ]; then
-  echo -e "JHBUILD_SOURCES must contain the path to the jhbuild sources."
-  exit 1;
-fi
+source "$(dirname "$0")/init_generate.sh"
 
-PREFIX="$JHBUILD_SOURCES"
-ROOT_DIR="$(dirname "$0")/../.."
-OUT_DIR="$ROOT_DIR/gtk/src"
+out_dir="$root_dir/gtk/src"
 
-PARAMS="--with-properties --no-recursion"
-for dir in "$PREFIX"/gtk+/{gtk,gtk/deprecated} "$PREFIX"/gtk+/build/gtk; do
+params="--with-properties --no-recursion"
+for dir in "$gtk_source_prefix"/{gtk,gtk/deprecated} "$gtk_build_prefix"/gtk; do
   if [ -d "$dir" ]; then
-    PARAMS="$PARAMS -s $dir"
+    params="$params -s $dir"
   fi
 done
 
 # Exclude gtkdnd-quartz.c. Function descriptions in gtkdnd-quartz.c can
 # replace better descriptions in gtkdnd.c, if gtkdnd-quartz.c is processed.
-PARAMS="$PARAMS -x $PREFIX/gtk+/gtk/gtkdnd-quartz.c"
+params="$params -x $gtk_source_prefix/gtk/gtkdnd-quartz.c"
 
-DOCEXTRACT_TO_XML_PY="$JHBUILD_SOURCES/glibmm/tools/defs_gen/docextract_to_xml.py"
-$DOCEXTRACT_TO_XML_PY $PARAMS > "$OUT_DIR/gtk_docs.xml"
+"$gen_docs" $params > "$out_dir/gtk_docs.xml"
diff --git a/tools/gen_scripts/gtk_generate_enums.sh b/tools/gen_scripts/gtk_generate_enums.sh
index 152fe076..ea894eb8 100755
--- a/tools/gen_scripts/gtk_generate_enums.sh
+++ b/tools/gen_scripts/gtk_generate_enums.sh
@@ -1,21 +1,14 @@
 #!/bin/bash
 
-# Note that JHBUILD_SOURCES should be defined to contain the path to the root
-# of the jhbuild sources. The script assumes that it resides in the
-# tools/gen_scripts/ directory and the defs file will be placed in gtk/src.
+# The script assumes that it resides in the tools/gen_scripts/ directory and
+# the defs file will be placed in gtk/src.
 
-if [ -z "$JHBUILD_SOURCES" ]; then
-  echo -e "JHBUILD_SOURCES must contain the path to the jhbuild sources."
-  exit 1;
-fi
+source "$(dirname "$0")/init_generate.sh"
 
-PREFIX="$JHBUILD_SOURCES/gtk+"
-ROOT_DIR="$(dirname "$0")/../.."
-OUT_DIR="$ROOT_DIR/gtk/src"
+out_dir="$root_dir/gtk/src"
 
 shopt -s extglob # Enable extended pattern matching
 shopt -s nullglob # Skip a filename pattern that matches no file
-ENUM_PL="$JHBUILD_SOURCES/glibmm/tools/enum.pl"
 # Process files whose names end with .h, but not with private.h.
-$ENUM_PL "$PREFIX"/gtk/!(*private).h "$PREFIX"/gtk/deprecated/!(*private).h \
-         "$PREFIX"/build/gtk/*.h > "$OUT_DIR"/gtk_enums.defs
+"$gen_enums" "$gtk_source_prefix"/gtk/!(*private).h "$gtk_source_prefix"/gtk/deprecated/!(*private).h \
+             "$gtk_build_prefix"/gtk/*.h > "$out_dir"/gtk_enums.defs
diff --git a/tools/gen_scripts/gtk_generate_extra_defs.sh b/tools/gen_scripts/gtk_generate_extra_defs.sh
index 89a5dba5..63daf91a 100755
--- a/tools/gen_scripts/gtk_generate_extra_defs.sh
+++ b/tools/gen_scripts/gtk_generate_extra_defs.sh
@@ -17,22 +17,22 @@
 # 3. ./gtk_generate_extra_defs.sh --make-patch
 # 4. Like step 2 when updating only the gtk_signals.defs file.
 
-ROOT_DIR="$(dirname "$0")/../.."
-GEN_DIR="$ROOT_DIR/tools/extra_defs_gen"
-OUT_DIR="$ROOT_DIR/gtk/src"
-OUT_DEFS_FILE="$OUT_DIR"/gtk_signals.defs
+source "$(dirname "$0")/init_generate.sh"
+
+out_dir="$root_dir/gtk/src"
+out_defs_file="$out_dir"/gtk_signals.defs
 
 if [ $# -eq 0 ]
 then
   # Without LC_ALL=C documentation (docs "xxx") may be translated in the .defs file.
-  LC_ALL=C "$GEN_DIR"/generate_defs_gtk > "$OUT_DEFS_FILE"
+  LC_ALL=C "$extra_defs_gen_dir"/generate_defs_gtk > "$out_defs_file"
   # patch version 2.7.5 does not like directory names.
-  cd "$(dirname "$OUT_DEFS_FILE")"
-  PATCH_OPTIONS="--backup --version-control=simple --suffix=.orig"
-  patch $PATCH_OPTIONS "$(basename "$OUT_DEFS_FILE")" "$(basename "$OUT_DEFS_FILE").patch"
+  cd "$(dirname "$out_defs_file")"
+  patch_options="--backup --version-control=simple --suffix=.orig"
+  patch $patch_options "$(basename "$out_defs_file")" "$(basename "$out_defs_file").patch"
 elif [ "$1" = "--make-patch" ]
 then
-  diff --unified=5 "$OUT_DEFS_FILE".orig "$OUT_DEFS_FILE" > "$OUT_DEFS_FILE".patch
+  diff --unified=5 "$out_defs_file".orig "$out_defs_file" > "$out_defs_file".patch
 else
   echo "Usage: $0 [--make-patch]"
   exit 1
diff --git a/tools/gen_scripts/gtk_generate_methods.sh b/tools/gen_scripts/gtk_generate_methods.sh
index 6dbde9dd..15cac678 100755
--- a/tools/gen_scripts/gtk_generate_methods.sh
+++ b/tools/gen_scripts/gtk_generate_methods.sh
@@ -1,21 +1,14 @@
 #!/bin/bash
 
-# Note that JHBUILD_SOURCES should be defined to contain the path to the root
-# of the jhbuild sources. The script assumes that it resides in the
-# tools/gen_scripts/ directory and the defs file will be placed in gtk/src.
+# The script assumes that it resides in the tools/gen_scripts/ directory and
+# the defs file will be placed in gtk/src.
 
-if [ -z "$JHBUILD_SOURCES" ]; then
-  echo -e "JHBUILD_SOURCES must contain the path to the jhbuild sources."
-  exit 1;
-fi
+source "$(dirname "$0")/init_generate.sh"
 
-PREFIX="$JHBUILD_SOURCES/gtk+"
-ROOT_DIR="$(dirname "$0")/../.."
-OUT_DIR="$ROOT_DIR/gtk/src"
+out_dir="$root_dir/gtk/src"
 
 shopt -s extglob # Enable extended pattern matching
 shopt -s nullglob # Skip a filename pattern that matches no file
-H2DEF_PY="$JHBUILD_SOURCES/glibmm/tools/defs_gen/h2def.py"
 # Process files whose names end with .h, but not with private.h.
-$H2DEF_PY "$PREFIX"/gtk/!(*private).h "$PREFIX"/gtk/deprecated/!(*private).h \
-          "$PREFIX"/build/gtk/*.h > "$OUT_DIR"/gtk_methods.defs
+"$gen_methods" "$gtk_source_prefix"/gtk/!(*private).h "$gtk_source_prefix"/gtk/deprecated/!(*private).h \
+               "$gtk_build_prefix"/gtk/*.h > "$out_dir"/gtk_methods.defs
diff --git a/tools/gen_scripts/init_generate.sh b/tools/gen_scripts/init_generate.sh
new file mode 100755
index 00000000..ba31a29f
--- /dev/null
+++ b/tools/gen_scripts/init_generate.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# This file is part of gtkmm.
+# Initializes some variables for the scripts that generate docs and defs files.
+# Not intented to be called directly from the command line.
+
+# Global environment variables:
+# GMMPROC_GEN_SOURCE_DIR  Top directory where source files are searched for.
+#                         Default value: $(dirname "$0")/../../..
+#                         i.e. 3 levels above this file.
+# GMMPROC_GEN_BUILD_DIR   Top directory where built files are searched for.
+#                         Default value: $GMMPROC_GEN_SOURCE_DIR
+#
+# If you use jhbuild, you can set these environment variables equal to jhbuild's
+# configuration variables checkoutroot and buildroot, respectively.
+# Usually you can leave GMMPROC_GEN_SOURCE_DIR undefined.
+# If you have set buildroot=None, GMMPROC_GEN_BUILD_DIR can also be undefined.
+
+# Root directory of gtkmm source files.
+root_dir="$(dirname "$0")/../.."
+
+# Where to search for source files.
+if [ -z "$GMMPROC_GEN_SOURCE_DIR" ]; then
+  GMMPROC_GEN_SOURCE_DIR="$root_dir/.."
+fi
+
+# Where to search for built files.
+if [ -z "$GMMPROC_GEN_BUILD_DIR" ]; then
+  GMMPROC_GEN_BUILD_DIR="$GMMPROC_GEN_SOURCE_DIR"
+fi
+
+# Scripts in glibmm. These are source files.
+gen_docs="$GMMPROC_GEN_SOURCE_DIR/glibmm/tools/defs_gen/docextract_to_xml.py"
+gen_methods="$GMMPROC_GEN_SOURCE_DIR/glibmm/tools/defs_gen/h2def.py"
+gen_enums="$GMMPROC_GEN_SOURCE_DIR/glibmm/tools/enum.pl"
+
+# Where to find executables that generate extra defs (signals and properties).
+# gtkmm is built with autotools.
+# autotools support, but don't require, non-source-dir builds.
+extra_defs_gen_dir="$GMMPROC_GEN_BUILD_DIR/gtkmm/tools/extra_defs_gen"
+
+gtk_source_prefix="$GMMPROC_GEN_SOURCE_DIR/gtk+"
+gtk_build_prefix="$GMMPROC_GEN_BUILD_DIR/gtk+"
+pixbuf_source_prefix="$GMMPROC_GEN_SOURCE_DIR/gdk-pixbuf"
+pixbuf_build_prefix="$GMMPROC_GEN_BUILD_DIR/gdk-pixbuf"
+if [ "$GMMPROC_GEN_SOURCE_DIR" == "$GMMPROC_GEN_BUILD_DIR" ]; then
+  # gtk+ and gdk-pixbuf are built with meson, which requires non-source-dir builds.
+  # This is what jhbuild does, if neccesary, to force non-source-dir builds.
+  gtk_build_prefix="$gtk_build_prefix/build"
+  pixbuf_build_prefix="$pixbuf_build_prefix/build"
+fi


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