/*
 * Copyright (C) 2011-2023 Gary Kramlich <grim@reaperworld.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * 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/>.
 */

#include "gplugin-gtk-version.h"

/******************************************************************************
 * GPluginGtkVersion API
 *****************************************************************************/

/**
 * GPLUGIN_GTK_MAJOR_VERSION:
 *
 * This is the major version number of GPluginGtk that was compiled against.
 */

/**
 * GPLUGIN_GTK_MINOR_VERSION:
 *
 * This is the minor version number of GPluginGtk that was compiled against.
 */

/**
 * GPLUGIN_GTK_MICRO_VERSION:
 *
 * This is the micro version number of GPluginGtk that was compiled against.
 */

/**
 * GPLUGIN_GTK_EXTRA_VERSION:
 *
 * This is the extra version string of GPluginGtk that was compiled against.
 */

/**
 * GPLUGIN_GTK_VERSION:
 *
 * This is the string version number of GPluginGtk that was compiled against.
 */

/**
 * GPLUGIN_GTK_VERSION_CHECK:
 * @major: The major version to compare for.
 * @minor: The minor version to compare for.
 * @micro: The micro version to compare for.
 *
 * Checks the version of the GPluginGtk library that is being compiled
 * against.
 *
 * Returns: %TRUE if the version of the GPluginGtk header files is the same as
 *          or newer than the passed-in version.
 */

/**
 * gplugin_gtk_version_check:
 * @major: The required major version.
 * @minor: The required minor version.
 * @micro: The required micro version.
 *
 * Checks that the GPluginGtk library in use is compatible with the given
 * version.
 *
 * Generally you would pass in the constants [const@MAJOR_VERSION],
 * [const@MINOR_VERSION], [const@MICRO_VERSION] as the three arguments to this
 * function; that produces a check that the library in use is compatible with
 * the version of GPluginGtk the application or module was compiled against.
 *
 * Compatibility is defined by two things: first the version of the running
 * library is newer than the version @major.@minor.@micro. Second the running
 * library must be binary compatible with the version @major.@minor.@micro
 * (same major version).
 *
 * Returns: %NULL if the GPluginGtk library is compatible with the given
 *          version, or a string describing the version mismatch. The returned
 *          string is owned by GPluginGtk and must not be modified or freed.
 */
const gchar *
gplugin_version_check(guint major, guint minor, guint micro)
{
	if(major > GPLUGIN_GTK_MAJOR_VERSION) {
		return "gplugin version too old (major mismatch)";
	}

#if GPLUGIN_GTK_VERSION_CHECK(1, 0, 0)
	if(major < GPLUGIN_GTK_MAJOR_VERSION) {
		return "gplugin version too new (major mismatch)";
	}
#endif

	if(minor > GPLUGIN_GTK_MINOR_VERSION) {
		return "gplugin version too old (minor mismatch)";
	}

	if(minor == GPLUGIN_GTK_MINOR_VERSION &&
	   micro > GPLUGIN_GTK_MICRO_VERSION) {
		return "gplugin version too old (micro mismatch)";
	}

	return NULL;
}
