[gimp] Issue #8145: meson: generation of '*-enums.c' files.



commit 106f2a061d000029e2b18c76924a826d3d8100ac
Author: Jehan <jehan girinstud io>
Date:   Mon Aug 1 19:08:35 2022 +0200

    Issue #8145: meson: generation of '*-enums.c' files.
    
    Our meson build system was not properly building the enums.c file,
    because they are versionned.
    
    I did a similar trick as what I did for the pdbgen, which is that I used
    a wrapper script around the existing perl script, which sets proper
    options and generate a stamp file in the end (which is considered by
    meson as the actual custom target, not the C file since it is generated
    in the source dir).
    
    The most important part is that the stamp file is a generated header
    source (not just a random text file) which is **included** by the
    generated C file. This is what will force meson to regenerate the C file
    if the header is updated, **then** build using this new version, not use
    an outdated versionned version (which would make for hard to diagnose
    bugs), through the indirection of the intermediate stamp header.
    
    See #4201.
    See also: https://github.com/mesonbuild/meson/issues/10196#issuecomment-1080742592

 app/config/meson.build     | 32 +++++++++++++----------
 app/core/meson.build       | 34 +++++++++++++-----------
 app/display/meson.build    | 33 +++++++++++++----------
 app/gegl/meson.build       | 34 +++++++++++++-----------
 app/meson.build            | 18 -------------
 app/operations/meson.build | 33 ++++++++++++-----------
 app/paint/meson.build      | 33 ++++++++++++-----------
 app/plug-in/meson.build    | 33 ++++++++++++-----------
 app/text/meson.build       | 32 +++++++++++++----------
 app/tools/meson.build      | 33 ++++++++++++-----------
 app/widgets/meson.build    | 33 ++++++++++++-----------
 libgimp/meson.build        | 31 ++++++++++++++++++++--
 libgimpbase/meson.build    | 65 +++++++++++++++++++++++++++-------------------
 libgimpconfig/meson.build  | 32 +++++++++++++----------
 libgimpthumb/meson.build   |  7 +++--
 libgimpwidgets/meson.build | 33 +++++++++++++----------
 meson.build                | 65 ++++++++++++++--------------------------------
 tools/meson-mkenums.sh     | 53 +++++++++++++++++++++++++++++++++++++
 18 files changed, 365 insertions(+), 269 deletions(-)
---
diff --git a/app/config/meson.build b/app/config/meson.build
index fcdc097832..b1b98edb33 100644
--- a/app/config/meson.build
+++ b/app/config/meson.build
@@ -1,18 +1,20 @@
-
-appconfigenums = custom_target('config-enums.c',
-  input : [ 'config-enums.h', ],
-  output: [ 'config-enums.c', ],
+stamp_config_enums = custom_target('stamp-config-enums.h',
+  input : [
+    files(
+      'config-enums.h'
+    ),
+  ],
+  output: [ 'stamp-config-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'config-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libappconfig_sources = [
@@ -32,7 +34,9 @@ libappconfig_sources = [
   'gimprc-unknown.c',
   'gimprc.c',
   'gimpxmlparser.c',
-  appconfigenums,
+
+  'config-enums.c',
+  stamp_config_enums,
 ]
 
 libappconfig = static_library('appconfig',
diff --git a/app/core/meson.build b/app/core/meson.build
index a23a48084d..cc07adc88c 100644
--- a/app/core/meson.build
+++ b/app/core/meson.build
@@ -1,17 +1,20 @@
-appcoreenums = custom_target('core-enums',
-  input : [ 'core-enums.h', ],
-  output: [ 'core-enums.c', ],
+stamp_core_enums = custom_target('stamp-core-enums.h',
+  input : [
+    files(
+      'core-enums.h'
+    ),
+  ],
+  output: [ 'stamp-core-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'core-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
 appcoremarshal = gnome.genmarshal('gimpmarshal',
@@ -20,8 +23,6 @@ appcoremarshal = gnome.genmarshal('gimpmarshal',
   install_header: false,
 )
 
-
-
 libappcore_sources = [
   'gimp-atomic.c',
   'gimp-batch.c',
@@ -250,7 +251,10 @@ libappcore_sources = [
   'gimpunit.c',
   'gimpviewable.c',
   'gimpwaitable.c',
-  appcoreenums,
+
+  'core-enums.c',
+  stamp_core_enums,
+
   appcoremarshal,
   cursors_sources,
   pickers_sources,
diff --git a/app/display/meson.build b/app/display/meson.build
index fece21c9ca..d15953289f 100644
--- a/app/display/meson.build
+++ b/app/display/meson.build
@@ -1,18 +1,20 @@
-
-appdisplayenums = custom_target('display-enums.c',
-  input : [ 'display-enums.h', ],
-  output: [ 'display-enums.c', ],
+stamp_display_enums = custom_target('stamp-display-enums.h',
+  input : [
+    files(
+      'display-enums.h'
+    ),
+  ],
+  output: [ 'stamp-display-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'display-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libappdisplay_sources = [
@@ -103,7 +105,10 @@ libappdisplay_sources = [
   'gimptooltransformgrid.c',
   'gimptoolwidget.c',
   'gimptoolwidgetgroup.c',
-  appdisplayenums,
+
+  'display-enums.c',
+  stamp_display_enums,
+
   gitversion_h,
 
   appcoremarshal[1],
diff --git a/app/gegl/meson.build b/app/gegl/meson.build
index a83c9771f6..b033eca63d 100644
--- a/app/gegl/meson.build
+++ b/app/gegl/meson.build
@@ -1,19 +1,21 @@
-
-appgeglenums = custom_target('gimp-gegl-enums.c',
-  input : [ 'gimp-gegl-enums.h', ],
-  output: [ 'gimp-gegl-enums.c', ],
+stamp_gegl_enums = custom_target('stamp-gimp-gegl-enums.h',
+  input : [
+    files(
+      'gimp-gegl-enums.h'
+    ),
+  ],
+  output: [ 'stamp-gimp-gegl-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "core/core-enums.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'gimp-gegl-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n' +
+    '#include "core/core-enums.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libappgegl_loops = simd.check('gimp-gegl-loops-simd',
@@ -40,7 +42,9 @@ libappgegl_sources = [
   'gimp-gegl.c',
   'gimpapplicator.c',
   'gimptilehandlervalidate.c',
-  appgeglenums,
+
+  'gimp-gegl-enums.c',
+  stamp_gegl_enums
 ]
 
 libappgegl = static_library('appgegl',
diff --git a/app/meson.build b/app/meson.build
index a9d19ca10f..fbb352d95a 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -1,23 +1,5 @@
 rootAppInclude = include_directories('.')
 
-app_mkenums_custom_target_commonargs = [
-  gimp_mkenums_custom_target_commonargs,
-  '--dtail','    { 0, NULL, NULL }\n'+
-            '  };\n'+
-            '\n'+
-            '  static GType type = 0;\n'+
-            '\n'+
-            '  if (G_UNLIKELY (! type))\n'+
-            '    {\n'+
-            '      type = g_@type@_register_static ("@EnumName@", values);\n'+
-            '      gimp_type_set_translation_context (type, "@enumnick@");\n'+
-            '      gimp_@type@_set_value_descriptions (type, descs);\n'+
-            '    }\n'+
-            '\n'+
-            '  return type;\n'+
-            '}\n',
-]
-
 subdir('actions')
 subdir('core')
 subdir('dialogs')
diff --git a/app/operations/meson.build b/app/operations/meson.build
index 8ffaf36bff..39765b6bce 100644
--- a/app/operations/meson.build
+++ b/app/operations/meson.build
@@ -1,21 +1,22 @@
-
-appoperationsenums = custom_target('operations-enums.c',
-  input : [ 'operations-enums.h', ],
-  output: [ 'operations-enums.c', ],
+stamp_operations_enums = custom_target('stamp-operations-enums.h',
+  input : [
+    files(
+      'operations-enums.h'
+    ),
+  ],
+  output: [ 'stamp-operations-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'operations-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
-
 libappoperations_sources = [
   'gimp-operation-config.c',
   'gimp-operations.c',
@@ -55,7 +56,9 @@ libappoperations_sources = [
   'gimpoperationshrink.c',
   'gimpoperationthreshold.c',
   'gimpoperationthresholdalpha.c',
-  appoperationsenums
+
+  'operations-enums.c',
+  stamp_operations_enums,
 ]
 
 libappoperations = static_library('appoperations',
diff --git a/app/paint/meson.build b/app/paint/meson.build
index ec733ed295..56113c09c3 100644
--- a/app/paint/meson.build
+++ b/app/paint/meson.build
@@ -1,21 +1,22 @@
-
-apppaintenums = custom_target('paint-enums.c',
-  input : [ 'paint-enums.h', ],
-  output: [ 'paint-enums.c', ],
+stamp_paint_enums = custom_target('stamp-paint-enums.h',
+  input : [
+    files(
+      'paint-enums.h'
+    ),
+  ],
+  output: [ 'stamp-paint-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'paint-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
-
 libapppaint_sources = [
   'gimp-paint.c',
   'gimpairbrush.c',
@@ -52,7 +53,9 @@ libapppaint_sources = [
   'gimpsmudgeoptions.c',
   'gimpsourcecore.c',
   'gimpsourceoptions.c',
-  apppaintenums,
+
+  'paint-enums.c',
+  stamp_paint_enums,
 ]
 
 libapppaint = static_library('apppaint',
diff --git a/app/plug-in/meson.build b/app/plug-in/meson.build
index 1cf44a5666..95e4c2e9b0 100644
--- a/app/plug-in/meson.build
+++ b/app/plug-in/meson.build
@@ -1,21 +1,22 @@
-
-apppluginenums = custom_target('plug-in-enums.c',
-  input : [ 'plug-in-enums.h', ],
-  output: [ 'plug-in-enums.c', ],
+stamp_plug_in_enums = custom_target('stamp-plug-in-enums.h',
+  input : [
+    files(
+      'plug-in-enums.h'
+    ),
+  ],
+  output: [ 'stamp-plug-in-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'plug-in-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
-
 libappplugin_sources = [
   'gimpenvirontable.c',
   'gimpgpparams.c',
@@ -43,7 +44,9 @@ libappplugin_sources = [
   'gimptemporaryprocedure.c',
   'plug-in-menu-path.c',
   'plug-in-rc.c',
-  apppluginenums,
+
+  'plug-in-enums.c',
+  stamp_plug_in_enums,
 
   appcoremarshal[1],
 ]
diff --git a/app/text/meson.build b/app/text/meson.build
index 30b85e4e8e..792b00bb4f 100644
--- a/app/text/meson.build
+++ b/app/text/meson.build
@@ -1,18 +1,20 @@
-
-apptextenums = custom_target('text-enums.c',
-  input : [ 'text-enums.h', ],
-  output: [ 'text-enums.c', ],
+stamp_text_enums = custom_target('stamp-text-enums.h',
+  input : [
+    files(
+      'text-enums.h'
+    ),
+  ],
+  output: [ 'stamp-text-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'text-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libapptext_sources = [
@@ -29,7 +31,9 @@ libapptext_sources = [
   'gimptextlayout-render.c',
   'gimptextlayout.c',
   'gimptextundo.c',
-  apptextenums,
+
+  'text-enums.c',
+  stamp_text_enums
 ]
 
 
diff --git a/app/tools/meson.build b/app/tools/meson.build
index 9627bb924e..6a5a278488 100644
--- a/app/tools/meson.build
+++ b/app/tools/meson.build
@@ -1,19 +1,21 @@
-
-apptoolsenums = custom_target('tools-enums.c',
-  input : [ 'tools-enums.h', ],
-  output: [ 'tools-enums.c', ],
+stamp_tools_enums = custom_target('stamp-tools-enums.h',
+  input : [
+    files(
+      'tools-enums.h'
+    ),
+  ],
+  output: [ 'stamp-tools-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "core/core-enums.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'tools-',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n' +
+    '#include "core/core-enums.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libapptools_sources = [
@@ -130,7 +132,8 @@ libapptools_sources = [
   'gimpwarpoptions.c',
   'gimpwarptool.c',
   'tool_manager.c',
-  apptoolsenums,
+  'tools-enums.c',
+  stamp_tools_enums,
 
   appcoremarshal[1],
 ]
diff --git a/app/widgets/meson.build b/app/widgets/meson.build
index d63f20cabb..e1b1d2d08a 100644
--- a/app/widgets/meson.build
+++ b/app/widgets/meson.build
@@ -1,21 +1,22 @@
-
-appwidgetsenums = custom_target('widgets-enums.c',
-  input : [ 'widgets-enums.h', ],
-  output: [ 'widgets-enums.c', ],
+stamp_widgets_enums = custom_target('stamp-widgets-enums.h',
+  input : [
+    files(
+      'widgets-enums.h'
+    ),
+  ],
+  output: [ 'stamp-widgets-enums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gtk/gtk.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "gimp-intl.h"\n',
-    app_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'widgets-',
+    '#include <gtk/gtk.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "gimp-intl.h"'
   ],
-  capture: true,
+  build_by_default: true
 )
 
-
 libappwidgets_sources = [
   'gimpaccellabel.c',
   'gimpaction-history.c',
@@ -233,7 +234,9 @@ libappwidgets_sources = [
   'gimpwidgets-utils.c',
   'gimpwindow.c',
   'gimpwindowstrategy.c',
-  appwidgetsenums,
+
+  'widgets-enums.c',
+  stamp_widgets_enums,
 
   appcoremarshal[1],
 ]
diff --git a/libgimp/meson.build b/libgimp/meson.build
index d379acb328..34263d3319 100644
--- a/libgimp/meson.build
+++ b/libgimp/meson.build
@@ -1,4 +1,7 @@
-
+# Similarly to libgimpthumb/gimpthumb-enums.c, libgimp/gimpenums.c is
+# not versionned so we don't use the mkenums_wrap.
+# Moreover it is generated in 2 steps, first with common mkenums
+# arguments, then concatenating with a "tail" file.
 gimpenums_notail = custom_target('gimpenums.c.notail',
   input : [ 'gimpenums.h', ],
   output: [ 'gimpenums.c.notail', ],
@@ -12,7 +15,31 @@ gimpenums_notail = custom_target('gimpenums.c.notail',
             + '#include "libgimpbase/gimpbase-private.h"\n'
             + '#include "libgimpconfig/gimpconfigenums.h"\n'
             + '#include "gimpenums.h"\n',
-    libgimp_mkenums_custom_target_commonargs,
+    '--fprod',
+      '/* enumerations from "@basename@" */',
+    '--vhead',
+      'GType\n'+
+      '@enum_name@_get_type (void)\n'+
+      '{\n'+
+      '  static const G@Type@Value values[] =\n'+
+      '  {',
+    '--vprod',
+      '    { @VALUENAME@, "@VALUENAME@", "@valuenick@" },',
+    '--vtail',
+      '    { 0, NULL, NULL }\n'+
+      '  };\n',
+    '--dhead',
+      '  static const Gimp@Type@Desc descs[] =\n'+
+      '  {',
+    '--dprod',
+      '    { @VALUENAME@, @valuedesc@, @valuehelp@ },'+
+      '@if (\'@valueabbrev@\' ne \'NULL\')@\n'+
+      '    /* Translators: this is an abbreviated version of @valueudesc@.\n'+
+      '       Keep it short. */\n'+
+      '    { @VALUENAME@, @valueabbrev@, NULL },'+
+      '@endif@',
+    '--dtail',
+      libgimp_mkenums_dtails,
     '@INPUT@',
   ],
   capture: true,
diff --git a/libgimpbase/meson.build b/libgimpbase/meson.build
index b5de0ac1d9..012e845234 100644
--- a/libgimpbase/meson.build
+++ b/libgimpbase/meson.build
@@ -8,37 +8,44 @@ gimpversion = configure_file(
   configuration: versionconfig,
 )
 
-
-gimpbaseenums = custom_target('gimpbaseenums.c',
-  input : [ 'gimpbaseenums.h', ],
-  output: [ 'gimpbaseenums.c', ],
+stamp_base_enums = custom_target('stamp-gimpbaseenums.h',
+  input : [
+    files(
+      'gimpbaseenums.h'
+    ),
+  ],
+  output: [ 'stamp-gimpbaseenums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <glib-object.h>\n'
-            + '#undef GIMP_DISABLE_DEPRECATED\n'
-            + '#include "gimpbasetypes.h"\n'
-            + '#include "libgimp/libgimp-intl.h"\n',
-    libgimp_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'gimpbase',
+    '#include <glib-object.h>\n'       +
+    '#undef GIMP_DISABLE_DEPRECATED\n' +
+    '#include "gimpbasetypes.h"\n'     +
+    '#include "libgimp/libgimp-intl.h"\n',
+    '',
+    libgimp_mkenums_dtails
   ],
-  capture: true,
+  build_by_default: true
 )
 
-gimpcompatenums = custom_target('gimpcompatenums.c',
-  input : [ 'gimpcompatenums.h', ],
-  output: [ 'gimpcompatenums.c', ],
+stamp_compat_enums = custom_target('stamp-gimpcompatenums.h',
+  input : [
+    files(
+      'gimpcompatenums.h'
+    ),
+  ],
+  output: [ 'stamp-gimpcompatenums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <glib-object.h>\n'
-            + '#include "gimpbasetypes.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "libgimp/libgimp-intl.h"\n',
-    libgimp_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(), meson.current_build_dir(),
+    'gimpcompat',
+    '#include <glib-object.h>\n'       +
+    '#include "gimpbasetypes.h"\n',
+    '#include "libgimp/libgimp-intl.h"',
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libgimpbase_sources_introspectable = files(
@@ -64,8 +71,12 @@ libgimpbase_sources = [
   'gimpprotocol.c',
   'gimpreloc.c',
   'gimpwire.c',
-  gimpbaseenums,
-  gimpcompatenums,
+
+  'gimpbaseenums.c',
+  stamp_base_enums,
+
+  'gimpcompatenums.c',
+  stamp_compat_enums
 ]
 
 libgimpbase_headers_introspectable = files(
diff --git a/libgimpconfig/meson.build b/libgimpconfig/meson.build
index ca3a8dcf17..db6a83eacd 100644
--- a/libgimpconfig/meson.build
+++ b/libgimpconfig/meson.build
@@ -1,18 +1,22 @@
 
-gimpconfigenums = custom_target('gimpconfigenums.c',
-  input : [ 'gimpconfigenums.h', ],
-  output: [ 'gimpconfigenums.c', ],
+stamp_config_enums = custom_target('stamp-gimpconfigenums.h',
+  input : [
+    files(
+      'gimpconfigenums.h'
+    ),
+  ],
+  output: [ 'stamp-gimpconfigenums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "libgimp/libgimp-intl.h"\n',
-    libgimp_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'gimpconfig',
+    '#include <gio/gio.h>\n' +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "libgimp/libgimp-intl.h"',
+    libgimp_mkenums_dtails
   ],
-  capture: true,
+  build_by_default: true
 )
 
 libgimpconfig_sources_introspectable = files(
@@ -31,7 +35,9 @@ libgimpconfig_sources_introspectable = files(
 
 libgimpconfig_sources = [
   libgimpconfig_sources_introspectable,
-  gimpconfigenums,
+
+  'gimpconfigenums.c',
+  stamp_config_enums
 ]
 
 libgimpconfig_headers_introspectable = files(
diff --git a/libgimpthumb/meson.build b/libgimpthumb/meson.build
index c106bb60a7..971605fcf5 100644
--- a/libgimpthumb/meson.build
+++ b/libgimpthumb/meson.build
@@ -1,4 +1,7 @@
-
+# Unlike other enums file, we don't use the mkenums_wrap because this
+# one is not versionned in the repository (not sure why). Moreover the
+# options are quite different from the other generated enums, so it
+# didn't make sense to overdo it.
 gimpthumbenums = custom_target('gimpthumb-enums.c',
   input : [ 'gimpthumb-enums.h', ],
   output: [ 'gimpthumb-enums.c', ],
@@ -7,7 +10,7 @@ gimpthumbenums = custom_target('gimpthumb-enums.c',
     '--fhead','#include "config.h"\n'+
               '#include <glib-object.h>\n'+
               '#include "gimpthumb-enums.h"\n',
-    '--fprod','/* enumerations from "@filename@" */\n',
+    '--fprod','/* enumerations from "@filename@" */',
     '--vhead','GType\n'+
               '@enum_name@_get_type (void)\n'+
               '{\n'+
diff --git a/libgimpwidgets/meson.build b/libgimpwidgets/meson.build
index 04125a7498..9364d673a5 100644
--- a/libgimpwidgets/meson.build
+++ b/libgimpwidgets/meson.build
@@ -1,18 +1,21 @@
-
-gimpwidgetsenums = custom_target('gimpwidgetsenums.c',
-  input : [ 'gimpwidgetsenums.h', ],
-  output: [ 'gimpwidgetsenums.c', ],
+stamp_widgets_enums = custom_target('stamp-gimpwidgetsenums.h',
+  input : [
+    files(
+      'gimpwidgetsenums.h'
+    ),
+  ],
+  output: [ 'stamp-gimpwidgetsenums.h', ],
   command: [
-    gimp_mkenums,
-    '--fhead','#include "config.h"\n'
-            + '#include <gio/gio.h>\n'
-            + '#include "libgimpbase/gimpbase.h"\n'
-            + '#include "@basename@"\n'
-            + '#include "libgimp/libgimp-intl.h"\n',
-    libgimp_mkenums_custom_target_commonargs,
-    '@INPUT@',
+    mkenums_wrap, perl,
+    meson.source_root(), meson.current_source_dir(),
+    meson.current_build_dir(),
+    'gimpwidgets',
+    '#include <gio/gio.h>\n'              +
+    '#include "libgimpbase/gimpbase.h"\n',
+    '#include "libgimp/libgimp-intl.h"',
+    libgimp_mkenums_dtails
   ],
-  capture: true,
+  build_by_default: true
 )
 
 gimpwidgetsmarshal = gnome.genmarshal('gimpwidgetsmarshal',
@@ -94,7 +97,9 @@ libgimpwidgets_sources = [
   'gimpeevl.c',
   'gimpwidgets-private.c',
 
-  gimpwidgetsenums,
+  'gimpwidgetsenums.c',
+  stamp_widgets_enums,
+
   gimpwidgetsmarshal,
   icons_imgs_sources,
   cursors_sources,
diff --git a/meson.build b/meson.build
index 967804e0f4..abf9d891e8 100644
--- a/meson.build
+++ b/meson.build
@@ -1186,52 +1186,25 @@ gimppath2svg        = find_program('tools'/'gimppath2svg.py')
 module_dependencies = find_program('tools'/'module-dependencies.py')
 meson_install_subdir= find_program('tools'/'meson_install_subdir.py')
 
-gimp_mkenums        = find_program('tools'/'gimp-mkenums')
-gimp_mkenums_custom_target_commonargs = [
-  '--fprod',
-    '/* enumerations from "@basename@" */',
-  '--vhead',
-    'GType\n'+
-    '@enum_name@_get_type (void)\n'+
-    '{\n'+
-    '  static const G@Type@Value values[] =\n'+
-    '  {',
-  '--vprod',
-    '    { @VALUENAME@, "@VALUENAME@", "@valuenick@" },',
-  '--vtail',
-    '    { 0, NULL, NULL }\n'+
-    '  };\n',
-  '--dhead',
-    '  static const Gimp@Type@Desc descs[] =\n'+
-    '  {',
-  '--dprod',
-    '    { @VALUENAME@, @valuedesc@, @valuehelp@ },'+
-    '@if (\'@valueabbrev@\' ne \'NULL\')@\n'+
-    '    /* Translators: this is an abbreviated version of @valueudesc@.\n'+
-    '       Keep it short. */\n'+
-    '    { @VALUENAME@, @valueabbrev@, NULL },'+
-    '@endif@',
-]
-
-libgimp_mkenums_custom_target_commonargs = [
-    gimp_mkenums_custom_target_commonargs,
-    '--dtail',
-      '    { 0, NULL, NULL }\n'+
-      '  };\n'+
-      '\n'+
-      '  static GType type = 0;\n'+
-      '\n'+
-      '  if (G_UNLIKELY (! type))\n'+
-      '    {\n'+
-      '      type = g_@type@_register_static ("@EnumName@", values);\n'+
-      '      gimp_type_set_translation_domain (type, GETTEXT_PACKAGE "-libgimp");\n'+
-      '      gimp_type_set_translation_context (type, "@enumnick@");\n'+
-      '      gimp_@type@_set_value_descriptions (type, descs);\n'+
-      '    }\n'+
-      '\n'+
-      '  return type;\n'+
-      '}\n',
-]
+gimp_mkenums = find_program('tools' / 'gimp-mkenums')
+mkenums_wrap = find_program(meson.current_source_dir() / 'tools' / 'meson-mkenums.sh')
+
+libgimp_mkenums_dtails = \
+    '    { 0, NULL, NULL }\n'                                                      + \
+    '  };\n'                                                                       + \
+    '\n'                                                                           + \
+    '  static GType type = 0;\n'                                                   + \
+    '\n'                                                                           + \
+    '  if (G_UNLIKELY (! type))\n'                                                 + \
+    '    {\n'                                                                      + \
+    '      type = g_@type@_register_static ("@EnumName@", values);\n'              + \
+    '      gimp_type_set_translation_domain (type, GETTEXT_PACKAGE "-libgimp");\n' + \
+    '      gimp_type_set_translation_context (type, "@enumnick@");\n'              + \
+    '      gimp_@type@_set_value_descriptions (type, descs);\n'                    + \
+    '    }\n'                                                                      + \
+    '\n'                                                                           + \
+    '  return type;\n'                                                             + \
+    '}\n'
 
 conf.set('ENABLE_NLS',   true)
 conf.set('HAVE_GETTEXT', true)
diff --git a/tools/meson-mkenums.sh b/tools/meson-mkenums.sh
new file mode 100755
index 0000000000..6e1968fdcd
--- /dev/null
+++ b/tools/meson-mkenums.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# This is a wrapper to the tools/gimp-mkenums perl script which:
+# * sets a few common values;
+# * updates the ${filebase}enums.c directly in the source directory in
+#   order for it to be versionned.
+# * Create a no-op stamp-header file to be included by the resulting
+#   enums.c. The goal is to make sure that meson will trigger a rebuild
+#   of the enums.c generation before compiling, if the enums.h changed.
+#   See the explanation here:
+#   https://github.com/mesonbuild/meson/issues/10196#issuecomment-1080742592
+#   This is also the trick used for pdbgen.
+
+# Arguments to this script:
+# The perl binary to use.
+PERL="$1"
+# Root of the source directory.
+top_srcdir="$2"
+# Current source folder.
+srcdir="$3"
+# Current build folder.
+builddir="$4"
+# Base of the generated enums.c file name.
+filebase="$5"
+# Includes before #include "${filebase}enums.h"
+preincludes="$6"
+# Includes after #include "${filebase}enums.h"
+postincludes="$7"
+# Value for --dtail option if the default doesn't fit.
+dtail="$8"
+
+if [ -z "$dtail" ]; then
+  dtail="    { 0, NULL, NULL }\n  };\n\n  static GType type = 0;\n\n  if (G_UNLIKELY (! type))\n    {\n      
type = g_@type@_register_static (\"@EnumName@\", values);\n      gimp_type_set_translation_context (type, 
\"@enumnick@\");\n      gimp_@type@_set_value_descriptions (type, descs);\n    }\n\n  return type;\n}\n"
+fi
+
+$PERL $top_srcdir/tools/gimp-mkenums \
+       --fhead "#include \"stamp-${filebase}enums.h\"\n#include \"config.h\"\n$preincludes#include 
\"${filebase}enums.h\"\n$postincludes" \
+       --fprod "\n/* enumerations from \"@basename@\" */" \
+       --vhead "GType\n@enum_name@_get_type (void)\n{\n  static const G@Type@Value values[] =\n  {" \
+       --vprod "    { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
+       --vtail "    { 0, NULL, NULL }\n  };\n" \
+       --dhead "  static const Gimp@Type@Desc descs[] =\n  {" \
+       --dprod "    { @VALUENAME@, @valuedesc@, @valuehelp@ },@if ('@valueabbrev@' ne 'NULL')@\n    /* 
Translators: this is an abbreviated version of @valueudesc@.\n       Keep it short. */\n    { @VALUENAME@, 
@valueabbrev@, NULL },@endif@" \
+       --dtail "$dtail" \
+       "$srcdir/${filebase}enums.h" > "$builddir/${filebase}enums-tmp.c"
+
+if ! cmp -s "$builddir/${filebase}enums-tmp.c" "$srcdir/${filebase}enums.c"; then
+  cp "$builddir/${filebase}enums-tmp.c" "$srcdir/${filebase}enums.c";
+else
+  touch "$srcdir/${filebase}enums.c"; 2> /dev/null || true;
+fi
+
+echo "/* Generated on `date`. */" > $builddir/stamp-${filebase}enums.h


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