regex: Add FIRSTLINE compile flag
[platform/upstream/glib.git] / glib / gversion.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1998  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "config.h"
28
29 #include "gversion.h"
30
31 /**
32  * SECTION:version
33  * @Title: Version Information
34  * @Short_description: variables and functions to check the GLib version
35  *
36  * GLib provides version information, primarily useful in configure
37  * checks for builds that have a configure script. Applications will
38  * not typically use the features described here.
39  *
40  * The GLib headers annotate deprecated APIs in a way that produces
41  * compiler warnings if these deprecated APIs are used. The warnings
42  * can be turned off by defining the macro %GLIB_DISABLE_DEPRECATION_WARNINGS
43  * before including the glib.h header.
44  *
45  * GLib also provides support for building applications against
46  * defined subsets of deprecated or new GLib APIs. Define the macro
47  * %GLIB_VERSION_MIN_REQUIRED to specify up to what version of GLib
48  * you want to receive warnings about deprecated APIs. Define the
49  * macro %GLIB_VERSION_MAX_ALLOWED to specify the newest version of
50  * GLib whose API you want to use.
51  */
52
53 /**
54  * GLIB_MAJOR_VERSION:
55  *
56  * The major version number of the GLib library.
57  *
58  * Like #glib_major_version, but from the headers used at
59  * application compile time, rather than from the library
60  * linked against at application run time.
61  */
62
63 /**
64  * GLIB_MINOR_VERSION:
65  *
66  * The minor version number of the GLib library.
67  *
68  * Like #gtk_minor_version, but from the headers used at
69  * application compile time, rather than from the library
70  * linked against at application run time.
71  */
72
73 /**
74  * GLIB_MICRO_VERSION:
75  *
76  * The micro version number of the GLib library.
77  *
78  * Like #gtk_micro_version, but from the headers used at
79  * application compile time, rather than from the library
80  * linked against at application run time.
81  */
82
83 /**
84  * GLIB_CHECK_VERSION:
85  * @major: the major version to check for
86  * @minor: the minor version to check for
87  * @micro: the micro version to check for
88  *
89  * Checks the version of the GLib library that is being compiled
90  * against.
91  *
92  * <example>
93  * <title>Checking the version of the GLib library</title>
94  * <programlisting>
95  *   if (!GLIB_CHECK_VERSION (1, 2, 0))
96  *     g_error ("GLib version 1.2.0 or above is needed");
97  * </programlisting>
98  * </example>
99  *
100  * See glib_check_version() for a runtime check.
101  *
102  * Returns: %TRUE if the version of the GLib header files
103  * is the same as or newer than the passed-in version.
104  */
105
106 const guint glib_major_version = GLIB_MAJOR_VERSION;
107 const guint glib_minor_version = GLIB_MINOR_VERSION;
108 const guint glib_micro_version = GLIB_MICRO_VERSION;
109 const guint glib_interface_age = GLIB_INTERFACE_AGE;
110 const guint glib_binary_age = GLIB_BINARY_AGE;
111
112 /**
113  * glib_check_version:
114  * @required_major: the required major version.
115  * @required_minor: the required minor version.
116  * @required_micro: the required micro version.
117  *
118  * Checks that the GLib library in use is compatible with the
119  * given version. Generally you would pass in the constants
120  * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION
121  * as the three arguments to this function; that produces
122  * a check that the library in use is compatible with
123  * the version of GLib the application or module was compiled
124  * against.
125  *
126  * Compatibility is defined by two things: first the version
127  * of the running library is newer than the version
128  * @required_major.required_minor.@required_micro. Second
129  * the running library must be binary compatible with the
130  * version @required_major.required_minor.@required_micro
131  * (same major version.)
132  *
133  * Return value: %NULL if the GLib library is compatible with the
134  *   given version, or a string describing the version mismatch.
135  *   The returned string is owned by GLib and must not be modified
136  *   or freed.
137  *
138  * Since: 2.6
139  */
140 const gchar *
141 glib_check_version (guint required_major,
142                     guint required_minor,
143                     guint required_micro)
144 {
145   gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
146   gint required_effective_micro = 100 * required_minor + required_micro;
147
148   if (required_major > GLIB_MAJOR_VERSION)
149     return "GLib version too old (major mismatch)";
150   if (required_major < GLIB_MAJOR_VERSION)
151     return "GLib version too new (major mismatch)";
152   if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
153     return "GLib version too new (micro mismatch)";
154   if (required_effective_micro > glib_effective_micro)
155     return "GLib version too old (micro mismatch)";
156   return NULL;
157 }