# HG changeset patch
# Node ID 2c3c411cd857
# Parent  f44497b3f5d9
diff --git a/libpurple/protocols/ircv3/ircv3generategir.c b/libpurple/protocols/ircv3/ircv3generategir.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/ircv3/ircv3generategir.c
@@ -0,0 +1,10 @@
+#include <glib.h>
+
+#include <gplugin-introspection.h>
+
+int
+main(int argc, char *argv[]) {
+    return gplugin_introspection_introspect_plugin(&argc, &argv,
+                                                   PLUGIN_FILENAME);
+}
+
diff --git a/libpurple/protocols/ircv3/meson.build b/libpurple/protocols/ircv3/meson.build
--- a/libpurple/protocols/ircv3/meson.build
+++ b/libpurple/protocols/ircv3/meson.build
@@ -20,20 +20,85 @@
 	'purpleircv3sasl.h',
 ]
 
-if DYNAMIC_IRCV3
-	ircv3_resources = gnome.compile_resources('ircv3resource',
-		'resources/ircv3.gresource.xml',
-		source_dir : 'resources',
-		c_name : 'purple_ircv3')
-	IRCV3_SOURCES += ircv3_resources
+if not DYNAMIC_IRCV3
+	subdir_done()
+endif
+
+ircv3_filebase = f'purple-@purple_major_version@-ircv3'
+
+ircv3_includes = include_directories('.')
+ircv3_include_base = purple_include_base / 'protocols/ircv3'
+
+
+ircv3_resources = gnome.compile_resources('ircv3resource',
+	'resources/ircv3.gresource.xml',
+	source_dir : 'resources',
+	c_name : 'purple_ircv3')
+IRCV3_SOURCES += ircv3_resources
+
+ircv3_h_includes = []
+foreach header : IRCV3_HEADERS
+	ircv3_h_includes += f'#include <@header@>'
+endforeach
+ircv3_h_conf = configuration_data()
+ircv3_h_conf.set('IRCV3_H_INCLUDES', '\n'.join(ircv3_h_includes))
+
+ircv3_h = configure_file(input : 'purpleircv3.h.in',
+                          output : 'purpleircv3.h',
+                          configuration : ircv3_h_conf,
+                          install : true,
+                          install_dir : get_option('includedir') / ircv3_include_base)
+
+install_headers(IRCV3_HEADERS,
+	subdir : ircv3_include_base)
+
+ircv3_prpl = shared_library('ircv3', IRCV3_SOURCES + IRCV3_HEADERS + ircv3_h,
+	c_args : ['-DPURPLE_IRCV3_COMPILATION', '-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="Purple-IRCv3"'],
+	dependencies : [libpurple_dep, glib, gio, hasl, ws2_32],
+	install : true,
+	install_dir : PURPLE_PLUGINDIR)
 
-	ircv3_prpl = shared_library('ircv3', IRCV3_SOURCES + IRCV3_HEADERS,
-		c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="Purple-IRCv3"'],
-		dependencies : [libpurple_dep, glib, gio, hasl, ws2_32],
+ircv3_dep = declare_dependency(
+	sources : [IRCV3_SOURCES, IRCV3_HEADERS],
+	include_directories : ircv3_includes,
+	dependencies : [libpurple_dep, glib, gio, hasl, ws2_32])
+
+pkgconfig.generate(
+	# we purposely don't put the library here because you should not be
+	# linking to the plugin, everything will be resolved during runtime.
+	name : 'ircv3',
+	description : 'a purple3 protocol plugin for IRCv3',
+	version : meson.project_version(),
+	subdirs : [ircv3_include_base],
+	filebase : ircv3_filebase,
+	requires : [gio, glib, 'gplugin', 'hasl', libpurple])
+
+meson.override_dependency(ircv3_filebase, ircv3_dep)
+
+devenv.append('PURPLE_PLUGIN_PATH', meson.current_build_dir())
+
+if get_option('introspection')
+	GPLUGIN_INTROSPECTION = dependency('gplugin-introspection')
+
+	plugin_filename = ircv3_prpl.full_path()
+
+	ircv3_introspection_stub = executable('ircv3generategir',
+		sources : 'ircv3generategir.c',
+		dependencies : [ircv3_dep, libpurple_dep, glib, gio, hasl, ws2_32, GPLUGIN_INTROSPECTION],
+		c_args : ['-DPURPLE_IRCV3_COMPILATION', f'-DPLUGIN_FILENAME="@plugin_filename@"'],
+		install : false)
+
+	ircv3_gir = gnome.generate_gir(
+		ircv3_introspection_stub,
+		sources : [IRCV3_SOURCES, IRCV3_HEADERS],
+		includes : ['GLib-2.0', 'GObject-2.0', 'GPlugin-1.0', libpurple_gir[0]],
+		namespace : 'PurpleIRCv3',
+		symbol_prefix : 'purple_ircv3',
+		nsversion : '1.0',
 		install : true,
-		install_dir : PURPLE_PLUGINDIR)
+	    dependencies: [gplugin_dep],
+		export_packages : ['ircv3'],
+		extra_args : ['-DPURPLE_IRCV3_COMPILATION', '--verbose'])
+endif
 
-	devenv.append('PURPLE_PLUGIN_PATH', meson.current_build_dir())
-
-	subdir('tests')
-endif
+subdir('tests')
diff --git a/libpurple/protocols/ircv3/purpleircv3.h.in b/libpurple/protocols/ircv3/purpleircv3.h.in
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/ircv3/purpleircv3.h.in
@@ -0,0 +1,40 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef PURPLE_IRCV3_H
+#define PURPLE_IRCV3_H
+
+#ifndef __GI_SCANNER__ /* hide this bit from g-ir-scanner */
+# ifdef PURPLE_IRCV3_COMPILATION
+#  error "ircv3 source files should not be including purpleircv3.h"
+# endif /* PURPLE_IRCV3_COMPILATION */
+#endif /* __GI_SCANNER__ */
+
+#ifndef PURPLE_IRCV3_GLOBAL_HEADER_INSIDE
+# define PURPLE_IRCV3_GLOBAL_HEADER_INSIDE
+#endif /* PURPLE_IRCV3_GLOBAL_HEADER_INSIDE */
+
+@IRCV3_H_INCLUDES@
+
+#undef PURPLE_IRCV3_GLOBAL_HEADER_INSIDE
+
+#endif /* PURPLE_IRCV3_H */
diff --git a/libpurple/protocols/ircv3/purpleircv3capabilities.h b/libpurple/protocols/ircv3/purpleircv3capabilities.h
--- a/libpurple/protocols/ircv3/purpleircv3capabilities.h
+++ b/libpurple/protocols/ircv3/purpleircv3capabilities.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_CAPABILITIES_H
 #define PURPLE_IRCV3_CAPABILITIES_H
@@ -35,6 +39,14 @@
 
 #include "purpleircv3connection.h"
 
+/**
+ * purple_ircv3_capabilities_register: (skip)
+ * @plugin: The [class@GPlugin.NativePlugin] instance.
+ *
+ * Dynamically registers the PurpleIRCv3Capabilities type.
+ *
+ * Since: 3.0.0
+ */
 G_GNUC_INTERNAL void purple_ircv3_capabilities_register(GPluginNativePlugin *plugin);
 
 G_GNUC_INTERNAL PurpleIRCv3Capabilities *purple_ircv3_capabilities_new(PurpleIRCv3Connection *connection);
diff --git a/libpurple/protocols/ircv3/purpleircv3connection.h b/libpurple/protocols/ircv3/purpleircv3connection.h
--- a/libpurple/protocols/ircv3/purpleircv3connection.h
+++ b/libpurple/protocols/ircv3/purpleircv3connection.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_CONNECTION_H
 #define PURPLE_IRCV3_CONNECTION_H
@@ -43,8 +47,26 @@
 	gpointer reserved[8];
 };
 
+/**
+ * purple_ircv3_connection_register: (skip)
+ * @plugin: The GTypeModule
+ *
+ * Registers the dynamic type using @plugin.
+ *
+ * Since: 3.0.0
+ */
 G_GNUC_INTERNAL void purple_ircv3_connection_register(GPluginNativePlugin *plugin);
 
+/**
+ * purple_ircv3_connection_get_cancellable: (skip)
+ * @connection: The instance.
+ *
+ * This is a private method that is not exposed externally.
+ *
+ * Gets the cancellable for @connection.
+ *
+ * Since: 3.0.0
+ */
 G_GNUC_INTERNAL GCancellable *purple_ircv3_connection_get_cancellable(PurpleIRCv3Connection *connection);
 
 /**
@@ -66,7 +88,7 @@
  *
  * Gets the list of capabilities that the server supplied during registration.
  *
- * Returns: The list of capabilities that the server supports.
+ * Returns: (transfer none): The list of capabilities that the server supports.
  */
 PurpleIRCv3Capabilities *purple_ircv3_connection_get_capabilities(PurpleIRCv3Connection *connection);
 
diff --git a/libpurple/protocols/ircv3/purpleircv3core.h b/libpurple/protocols/ircv3/purpleircv3core.h
--- a/libpurple/protocols/ircv3/purpleircv3core.h
+++ b/libpurple/protocols/ircv3/purpleircv3core.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_CORE_H
 #define PURPLE_IRCV3_CORE_H
diff --git a/libpurple/protocols/ircv3/purpleircv3core.c b/libpurple/protocols/ircv3/purpleircv3core.c
--- a/libpurple/protocols/ircv3/purpleircv3core.c
+++ b/libpurple/protocols/ircv3/purpleircv3core.c
@@ -58,6 +58,7 @@
 		"website", PURPLE_WEBSITE,
 		"abi-version", PURPLE_ABI_VERSION,
 		"flags", flags,
+		"bind-global", TRUE,
 		NULL);
 }
 
@@ -76,13 +77,16 @@
 	purple_ircv3_connection_register(GPLUGIN_NATIVE_PLUGIN(plugin));
 	purple_ircv3_protocol_register(GPLUGIN_NATIVE_PLUGIN(plugin));
 
-	manager = purple_protocol_manager_get_default();
+	ircv3_protocol = purple_ircv3_protocol_new();
 
-	ircv3_protocol = purple_ircv3_protocol_new();
-	if(!purple_protocol_manager_register(manager, ircv3_protocol, error)) {
-		g_clear_object(&ircv3_protocol);
+	manager = purple_protocol_manager_get_default();
+	/* Manager can be NULL when we're generating the GIR stuff. */
+	if(PURPLE_IS_PROTOCOL_MANAGER(manager)) {
+		if(!purple_protocol_manager_register(manager, ircv3_protocol, error)) {
+			g_clear_object(&ircv3_protocol);
 
-		return FALSE;
+			return FALSE;
+		}
 	}
 
 	return TRUE;
@@ -103,8 +107,13 @@
 	}
 
 	manager = purple_protocol_manager_get_default();
-	if(!purple_protocol_manager_unregister(manager, ircv3_protocol, error)) {
-		return FALSE;
+	/* Manager can be NULL when we're generating the GIR stuff. */
+	if(PURPLE_IS_PROTOCOL_MANAGER(manager)) {
+		if(!purple_protocol_manager_unregister(manager, ircv3_protocol,
+		                                       error))
+		{
+			return FALSE;
+		}
 	}
 
 	g_clear_object(&ircv3_protocol);
diff --git a/libpurple/protocols/ircv3/purpleircv3messagehandlers.h b/libpurple/protocols/ircv3/purpleircv3messagehandlers.h
--- a/libpurple/protocols/ircv3/purpleircv3messagehandlers.h
+++ b/libpurple/protocols/ircv3/purpleircv3messagehandlers.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_MESSAGE_HANDLERS_H
 #define PURPLE_IRCV3_MESSAGE_HANDLERS_H
@@ -32,8 +36,8 @@
  * @source: The source of the command.
  * @command: The command or numeric of the message.
  * @n_params: The number of parameters.
- * @params: (array_length=n_params): The parameters of the message.
- * @error: (nullable) (optional): A return address for a [type@GLib.Error].
+ * @params: (array length=n_params): The parameters of the message.
+ * @error: (nullable): A return address for a [type@GLib.Error].
  * @data: The user data that was passed to [method@PurpleIRCv3.Parser.parse].
  *
  * Defines the type of a function that will be called to handle a message.
diff --git a/libpurple/protocols/ircv3/purpleircv3parser.h b/libpurple/protocols/ircv3/purpleircv3parser.h
--- a/libpurple/protocols/ircv3/purpleircv3parser.h
+++ b/libpurple/protocols/ircv3/purpleircv3parser.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_PARSER_H
 #define PURPLE_IRCV3_PARSER_H
diff --git a/libpurple/protocols/ircv3/purpleircv3protocol.h b/libpurple/protocols/ircv3/purpleircv3protocol.h
--- a/libpurple/protocols/ircv3/purpleircv3protocol.h
+++ b/libpurple/protocols/ircv3/purpleircv3protocol.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_PROTOCOL_H
 #define PURPLE_IRCV3_PROTOCOL_H
@@ -41,6 +45,14 @@
 	gpointer reserved[4];
 };
 
+/**
+ * purple_ircv3_protocol_register: (skip)
+ * @plugin: The GTypeModule
+ *
+ * Registers the dynamic type using @plugin.
+ *
+ * Since: 3.0.0
+ */
 G_GNUC_INTERNAL void purple_ircv3_protocol_register(GPluginNativePlugin *plugin);
 
 G_GNUC_INTERNAL PurpleProtocol *purple_ircv3_protocol_new(void);
diff --git a/libpurple/protocols/ircv3/purpleircv3protocolim.h b/libpurple/protocols/ircv3/purpleircv3protocolim.h
--- a/libpurple/protocols/ircv3/purpleircv3protocolim.h
+++ b/libpurple/protocols/ircv3/purpleircv3protocolim.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_PROTOCOL_IM_H
 #define PURPLE_IRCV3_PROTOCOL_IM_H
diff --git a/libpurple/protocols/ircv3/purpleircv3sasl.h b/libpurple/protocols/ircv3/purpleircv3sasl.h
--- a/libpurple/protocols/ircv3/purpleircv3sasl.h
+++ b/libpurple/protocols/ircv3/purpleircv3sasl.h
@@ -15,6 +15,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+    !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
 
 #ifndef PURPLE_IRCV3_SASL_H
 #define PURPLE_IRCV3_SASL_H
diff --git a/libpurple/protocols/ircv3/tests/meson.build b/libpurple/protocols/ircv3/tests/meson.build
--- a/libpurple/protocols/ircv3/tests/meson.build
+++ b/libpurple/protocols/ircv3/tests/meson.build
@@ -6,7 +6,8 @@
 	e = executable(
 		f'test_ircv3_@prog@', f'test_ircv3_@prog@.c',
 		dependencies : [libpurple_dep, glib, hasl],
-		objects : ircv3_prpl.extract_all_objects())
+		objects : ircv3_prpl.extract_all_objects(),
+		c_args : ['-DPURPLE_IRCV3_COMPILATION'])
 
 	test(f'ircv3_@prog@', e)
 endforeach
diff --git a/subprojects/gplugin.wrap b/subprojects/gplugin.wrap
--- a/subprojects/gplugin.wrap
+++ b/subprojects/gplugin.wrap
@@ -1,4 +1,4 @@
 [wrap-hg]
 directory = gplugin
 url = https://keep.imfreedom.org/gplugin/gplugin
-revision = v0.40.0
+revision = v0.41.0
