[mm-common] skeletonmm: Update for builddir != sourcedir



commit 4f4178be623c804ca68139e8111406be393c7be2
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sat Feb 2 12:03:29 2019 +0100

    skeletonmm: Update for builddir != sourcedir
    
    * skeletonmm/codegen/generate_defs_and_docs.sh: Read the environment
    variables $GMMPROC_GEN_SOURCE_DIR and $GMMPROC_GEN_BUILD_DIR.

 skeletonmm/codegen/generate_defs_and_docs.sh | 96 +++++++++++++++++++++-------
 1 file changed, 73 insertions(+), 23 deletions(-)
---
diff --git a/skeletonmm/codegen/generate_defs_and_docs.sh b/skeletonmm/codegen/generate_defs_and_docs.sh
index 724b356..7deb248 100755
--- a/skeletonmm/codegen/generate_defs_and_docs.sh
+++ b/skeletonmm/codegen/generate_defs_and_docs.sh
@@ -2,15 +2,17 @@
 
 # skeletonmm/codegen/generate_defs_and_docs.sh
 
-# This script must be executed from directory skeletonmm/codegen.
-
-# Assumed directory structure:
-#   glibmm/tools/defs_gen/docextract_to_xml.py
-#   glibmm/tools/defs_gen/h2def.py
-#   glibmm/tools/enum.pl
-#   skeleton/src/*.h
-#   skeleton/src/*.c
-#   skeletonmm/codegen/extradefs/generate_extra_defs
+# Global environment variables:
+# GMMPROC_GEN_SOURCE_DIR  Top directory where source files are searched for.
+#                         Default value: $(dirname "$0")/../..
+#                         i.e. 2 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.
 
 # Generated files:
 #   skeletonmm/skeleton/src/skeleton_docs.xml
@@ -18,22 +20,70 @@
 #   skeletonmm/skeleton/src/skeleton_method.defs
 #   skeletonmm/skeleton/src/skeleton_signal.defs
 
-GLIBMM_TOOLS_DIR=../../glibmm/tools
-SKELETON_DIR=../../skeleton
-SKELETONMM_SKELETON_SRC_DIR=../skeleton/src
+# Root directory of skeletonmm 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 the executable that generates extra defs (signals and properties).
+extra_defs_gen_dir="$GMMPROC_GEN_BUILD_DIR/skeletonmm/codegen/extradefs"
+### If skeletonmm is built with meson:
+if [ "$GMMPROC_GEN_SOURCE_DIR" == "$GMMPROC_GEN_BUILD_DIR" ]; then
+  # skeletonmm is built with meson, which requires non-source-dir builds.
+  # This is what jhbuild does, if neccesary, to force non-source-dir builds.
+  extra_defs_gen_dir="$GMMPROC_GEN_BUILD_DIR/skeletonmm/build/codegen/extradefs"
+fi
+### If skeletonmm is built with autotools:
+# skeletonmm is built with autotools.
+# autotools support, but don't require, non-source-dir builds.
+
+source_prefix="$GMMPROC_GEN_SOURCE_DIR/skeleton"
+build_prefix="$GMMPROC_GEN_BUILD_DIR/skeleton"
+### If skeleton is built with meson:
+if [ "$source_prefix" == "$build_prefix" ]; then
+  # skeleton is built with meson, which requires non-source-dir builds.
+  # This is what jhbuild does, if neccesary, to force non-source-dir builds.
+  build_prefix="$build_prefix/build"
+fi
+### If skeleton is built with autotools:
+# skeleton is built with autotools, which support, but don't require, non-source-dir builds.
+
+out_dir="$root_dir/skeleton/src"
+
+# Documentation
+echo === skeleton_docs.xml ===
+params="--with-properties --no-recursion"
+for dir in "$source_prefix/skeleton" "$build_prefix/skeleton"; do
+  if [ -d "$dir" ]; then
+    params="$params -s $dir"
+  fi
+done
+"$gen_docs" $params > "$out_dir/skeleton_docs.xml"
 
-$GLIBMM_TOOLS_DIR/defs_gen/docextract_to_xml.py \
-  -s $SKELETON_DIR/src \
-  >$SKELETONMM_SKELETON_SRC_DIR/skeleton_docs.xml
+shopt -s nullglob # Skip a filename pattern that matches no file
 
-$GLIBMM_TOOLS_DIR/enum.pl \
-  $SKELETON_DIR/src/*.h \
-  >$SKELETONMM_SKELETON_SRC_DIR/skeleton_enum.defs
+# Enums
+echo === skeleton_enum.defs ===
+"$gen_enums" "$source_prefix"/skeleton/*.h "$build_prefix"/skeleton/*.h  > "$out_dir/skeleton_enum.defs"
 
-$GLIBMM_TOOLS_DIR/defs_gen/h2def.py \
-  $SKELETON_DIR/src/*.h \
-  >$SKELETONMM_SKELETON_SRC_DIR/skeleton_method.defs
+# Functions and methods
+echo === skeleton_method.defs ===
+"$gen_methods" "$source_prefix"/skeleton/*.h "$build_prefix"/skeleton/*.h  > "$out_dir/skeleton_method.defs"
 
-extradefs/generate_extra_defs \
-  >$SKELETONMM_SKELETON_SRC_DIR/skeleton_signal.defs
+# Properties and signals
+echo === skeleton_signal.defs ===
+"$extra_defs_gen_dir"/generate_extra_defs > "$out_dir/skeleton_signal.defs"
 


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