birb/birbversion.h

Tue, 28 Jan 2025 10:49:21 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 28 Jan 2025 10:49:21 -0600
changeset 40
b2c2ca3e8e72
parent 29
dd7afaa7d4ac
permissions
-rw-r--r--

Add a license file

Adding the license property to meson required bumping to version 1.1.0.

Testing Done:
Ran `meson dist`

Bugs closed: BIRB-9

Reviewed at https://reviews.imfreedom.org/r/3786/

/*
 * Copyright (C) 2023-2025 Birb Developers
 *
 * Birb is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed
 * with this source distribution
 *
 * 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.1 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/>.
 */

#ifndef BIRB_VERSION_H
#define BIRB_VERSION_H

#include <glib.h>

#include "birbversionconsts.h"

/* clang-format tries to remove the space after 'if', which confuses
 * gobject-introspection, so turn it off temporarily. */
/* clang-format off */
#if (defined(_WIN32) || defined(__CYGWIN__)) && \
	!defined(BIRB_STATIC_COMPILATION)
/* clang-format on */
#define _BIRB_EXPORT __declspec(dllexport)
#define _BIRB_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
#define _BIRB_EXPORT __attribute__((visibility("default")))
#define _BIRB_IMPORT
#else
#define _BIRB_EXPORT
#define _BIRB_IMPORT
#endif
#ifdef BIRB_COMPILATION
#define _BIRB_API _BIRB_EXPORT
#else
#define _BIRB_API _BIRB_IMPORT
#endif

#define _BIRB_EXTERN _BIRB_API extern

#ifdef BIRB_DISABLE_DEPRECATION_WARNINGS
#define BIRB_DEPRECATED _BIRB_EXTERN
#define BIRB_DEPRECATED_FOR(f) _BIRB_EXTERN
#define BIRB_UNAVAILABLE(maj, min) _BIRB_EXTERN
#define BIRB_UNAVAILABLE_MACRO(maj, min)
#define BIRB_UNAVAILABLE_STATIC_INLINE(maj, min)
#define BIRB_UNAVAILABLE_TYPE(maj, min)
#else
#define BIRB_DEPRECATED G_DEPRECATED _BIRB_EXTERN
#define BIRB_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _BIRB_EXTERN
#define BIRB_UNAVAILABLE(maj, min) G_UNAVAILABLE(maj, min) _BIRB_EXTERN
#define BIRB_UNAVAILABLE_MACRO(maj, min) G_UNAVAILABLE_MACRO(maj, min)
#define BIRB_UNAVAILABLE_STATIC_INLINE(maj, min) G_UNAVAILABLE(maj, min)
#define BIRB_UNAVAILABLE_TYPE(maj, min) G_UNAVAILABLE(maj, min)
#endif

/**
 * BIRB_VERSION_MIN_REQUIRED:
 *
 * A macro that should be defined by the user prior to including the `birb.h`
 * header.
 *
 * The definition should be one of the predefined Birb version macros:
 * %BIRB_VERSION_0_1, %BIRB_VERSION_0_2, ...
 *
 * This macro defines the earliest version of Birb that the package is required
 * to be able to compile against.
 *
 * If the compiler is configured to warn about the use of deprecated functions,
 * then using functions that were deprecated in version
 * %BIRB_VERSION_MIN_REQUIRED or earlier will cause warnings (but using
 * functions deprecated in later releases will not).
 *
 * Since: 0.1
 */

/**
 * BIRB_VERSION_CUR_STABLE:
 *
 * A macro that evaluates to the current stable version of birb, in a format
 * that can be used by the C pre-processor.
 *
 * Since: 0.1
 */
#define BIRB_VERSION_CUR_STABLE \
	(G_ENCODE_VERSION(BIRB_MAJOR_VERSION, BIRB_MINOR_VERSION))

/* If the package sets BIRB_VERSION_MIN_REQUIRED to some future
 * BIRB_VERSION_X_Y value that we don't know about, it will compare as 0 in
 * preprocessor tests.
 */
#ifndef BIRB_VERSION_MIN_REQUIRED
#define BIRB_VERSION_MIN_REQUIRED (BIRB_VERSION_CUR_STABLE)
#elif BIRB_VERSION_MIN_REQUIRED == 0
#undef BIRB_VERSION_MIN_REQUIRED
#define BIRB_VERSION_MIN_REQUIRED (BIRB_VERSION_CUR_STABLE + 1)
#endif /* BIRB_VERSION_MIN_REQUIRED */

#if !defined(BIRB_VERSION_MAX_ALLOWED) || (BIRB_VERSION_MAX_ALLOWED == 0)
#undef BIRB_VERSION_MAX_ALLOWED
#define BIRB_VERSION_MAX_ALLOWED (BIRB_VERSION_CUR_STABLE)
#endif /* BIRB_VERSION_MAX_ALLOWED */

/* sanity checks */
#if BIRB_VERSION_MIN_REQUIRED > BIRB_VERSION_CUR_STABLE
#error "BIRB_VERSION_MIN_REQUIRED must be <= BIRB_VERSION_CUR_STABLE"
#endif
#if BIRB_VERSION_MAX_ALLOWED < BIRB_VERSION_MIN_REQUIRED
#error "BIRB_VERSION_MAX_ALLOWED must be >= BIRB_VERSION_MIN_REQUIRED"
#endif
#if BIRB_VERSION_MIN_REQUIRED < G_ENCODE_VERSION(0, 1)
#error "BIRB_VERSION_MIN_REQUIRED must be >= BIRB_VERSION_0_1"
#endif

#define BIRB_VAR _BIRB_EXTERN
#define BIRB_AVAILABLE_IN_ALL _BIRB_EXTERN

/**
 * BIRB_VERSION_0_1:
 *
 * A macro that evaluates to the 0.1 version of birb, in a format that can be
 * used by the C pre-processor.
 *
 * Since: 0.1
 */
#define BIRB_VERSION_0_1 (G_ENCODE_VERSION(0, 1))

#if BIRB_VERSION_MAX_ALLOWED < BIRB_VERSION_0_1
#define BIRB_AVAILABLE_IN_0_1 BIRB_UNAVAILABLE(0, 1)
#define BIRB_AVAILABLE_ENUMERATOR_IN_0_1 BIRB_UNAVAILABLE_ENUMERATOR(0, 1)
#define BIRB_AVAILABLE_MACRO_IN_0_1 BIRB_UNAVAILABLE_MACRO(0, 1)
#define BIRB_AVAILABLE_STATIC_INLINE_IN_0_1 BIRB_UNAVAILABLE_STATIC_INLINE(0, 1)
#define BIRB_AVAILABLE_TYPE_IN_0_1 BIRB_UNAVAILABLE_TYPE(0, 1)
#else
#define BIRB_AVAILABLE_IN_0_1 _BIRB_EXTERN
#define BIRB_AVAILABLE_ENUMERATOR_IN_0_1
#define BIRB_AVAILABLE_MACRO_IN_0_1
#define BIRB_AVAILABLE_STATIC_INLINE_IN_0_1
#define BIRB_AVAILABLE_TYPE_IN_0_1
#endif

/**
 * BIRB_VERSION_0_2:
 *
 * A macro that evaluates to the 0.2 version of birb, in a format that can be
 * used by the C pre-processor.
 *
 * Since: 0.2
 */
#define BIRB_VERSION_0_2 (G_ENCODE_VERSION(0, 2))

#if BIRB_VERSION_MAX_ALLOWED < BIRB_VERSION_0_2
#define BIRB_AVAILABLE_IN_0_2 BIRB_UNAVAILABLE(0, 2)
#define BIRB_AVAILABLE_ENUMERATOR_IN_0_2 BIRB_UNAVAILABLE_ENUMERATOR(0, 2)
#define BIRB_AVAILABLE_MACRO_IN_0_2 BIRB_UNAVAILABLE_MACRO(0, 2)
#define BIRB_AVAILABLE_STATIC_INLINE_IN_0_2 BIRB_UNAVAILABLE_STATIC_INLINE(0, 2)
#define BIRB_AVAILABLE_TYPE_IN_0_2 BIRB_UNAVAILABLE_TYPE(0, 2)
#else
#define BIRB_AVAILABLE_IN_0_2 _BIRB_EXTERN
#define BIRB_AVAILABLE_ENUMERATOR_IN_0_2
#define BIRB_AVAILABLE_MACRO_IN_0_2
#define BIRB_AVAILABLE_STATIC_INLINE_IN_0_2
#define BIRB_AVAILABLE_TYPE_IN_0_2
#endif

/**
 * BIRB_VERSION_0_3:
 *
 * A macro that evaluates to the 0.3 version of birb, in a format that can be
 * used by the C pre-processor.
 *
 * Since: 0.3
 */
#define BIRB_VERSION_0_3 (G_ENCODE_VERSION(0, 3))

#if BIRB_VERSION_MAX_ALLOWED < BIRB_VERSION_0_3
#define BIRB_AVAILABLE_IN_0_3 BIRB_UNAVAILABLE(0, 3)
#define BIRB_AVAILABLE_ENUMERATOR_IN_0_3 BIRB_UNAVAILABLE_ENUMERATOR(0, 3)
#define BIRB_AVAILABLE_MACRO_IN_0_3 BIRB_UNAVAILABLE_MACRO(0, 3)
#define BIRB_AVAILABLE_STATIC_INLINE_IN_0_3 BIRB_UNAVAILABLE_STATIC_INLINE(0, 3)
#define BIRB_AVAILABLE_TYPE_IN_0_3 BIRB_UNAVAILABLE_TYPE(0, 3)
#else
#define BIRB_AVAILABLE_IN_0_3 _BIRB_EXTERN
#define BIRB_AVAILABLE_ENUMERATOR_IN_0_3
#define BIRB_AVAILABLE_MACRO_IN_0_3
#define BIRB_AVAILABLE_STATIC_INLINE_IN_0_3
#define BIRB_AVAILABLE_TYPE_IN_0_3
#endif

G_BEGIN_DECLS

/**
 * BIRB_CHECK_VERSION:
 * @major: The major version to check for.
 * @minor: The minor version to check for.
 * @micro: The micro version to check for.
 *
 * Checks the version of birb being compiled against. See [func@check_version]
 * for a runtime check.
 *
 * Returns: %TRUE if the version is the same or newer than the passed-in
 *          version.
 *
 * Since: 0.1
 */
#define BIRB_CHECK_VERSION(major, minor, micro) ((major) == BIRB_MAJOR_VERSION && \
                                                 ((minor) < BIRB_MINOR_VERSION || \
                                                  ((minor) == BIRB_MINOR_VERSION && (micro) <= BIRB_MICRO_VERSION)))

/**
 * birb_check_version:
 * @required_major: the required major version.
 * @required_minor: the required minor version.
 * @required_micro: the required micro version.
 *
 * Checks that the birb version is compatible with the requested version.
 *
 * Returns: %NULL if the versions are compatible, or a string describing
 *          the version mismatch if not compatible.
 *
 * Since: 0.1
 */
BIRB_AVAILABLE_IN_ALL
const char *birb_check_version(guint required_major, guint required_minor, guint required_micro);

/**
 * birb_version:
 *
 * The full version string of the running birb.
 *
 * Since: 0.1
 */
BIRB_VAR const char *birb_version;

/**
 * birb_major_version:
 *
 * The major version of the running birb. Contrast with #BIRB_MAJOR_VERSION,
 * which expands at compile time to the major version of birb being compiled
 * against.
 *
 * Since: 0.1
 */
BIRB_VAR const guint birb_major_version;

/**
 * birb_minor_version:
 *
 * The minor version of the running birb. Contrast with #BIRB_MINOR_VERSION,
 * which expands at compile time to the minor version of birb being compiled
 * against.
 *
 * Since: 0.1
 */
BIRB_VAR const guint birb_minor_version;

/**
 * birb_micro_version:
 *
 * The micro version of the running birb. Contrast with #BIRB_MICRO_VERSION,
 * which expands at compile time to the micro version of birb being compiled
 * against.
 *
 * Since: 0.1
 */
BIRB_VAR const guint birb_micro_version;

G_END_DECLS

#endif /* BIRB_VERSION_H */

mercurial