sanity.c 11.1 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

21
#include <glib.h>
22
#include <fontconfig/fontconfig.h>
23
#include <pango/pango.h>
24
#include <pango/pangoft2.h>
25
#include <gegl.h>
26

27
#include "libgimpbase/gimpbase.h"
28

29
30
#include "sanity.h"

31
32
#include "gimp-intl.h"

33

34
static gchar * sanity_check_gimp              (void);
35
static gchar * sanity_check_glib              (void);
36
static gchar * sanity_check_pango             (void);
37
38
static gchar * sanity_check_fontconfig        (void);
static gchar * sanity_check_freetype          (void);
39
static gchar * sanity_check_babl              (void);
40
static gchar * sanity_check_gegl              (void);
41
42
static gchar * sanity_check_filename_encoding (void);

43

44
/*  public functions  */
45

46
const gchar *
47
sanity_check (void)
48
{
49
50
51
52
  gchar *abort_message = sanity_check_gimp ();

  if (! abort_message)
    abort_message = sanity_check_glib ();
53

54
55
56
  if (! abort_message)
    abort_message = sanity_check_pango ();

57
58
59
60
61
62
  if (! abort_message)
    abort_message = sanity_check_fontconfig ();

  if (! abort_message)
    abort_message = sanity_check_freetype ();

63
64
65
  if (! abort_message)
    abort_message = sanity_check_babl ();

66
67
68
  if (! abort_message)
    abort_message = sanity_check_gegl ();

69
70
71
72
73
74
75
76
77
  if (! abort_message)
    abort_message = sanity_check_filename_encoding ();

  return abort_message;
}


/*  private functions  */

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
static gchar *
sanity_check_gimp (void)
{
  if (GIMP_MAJOR_VERSION != gimp_major_version ||
      GIMP_MINOR_VERSION != gimp_minor_version ||
      GIMP_MICRO_VERSION != gimp_micro_version)
    {
      return g_strdup_printf
        ("Libgimp version mismatch!\n\n"
         "The GIMP binary cannot run with a libgimp version\n"
         "other than its own. This is GIMP %d.%d.%d, but the\n"
         "libgimp version is %d.%d.%d.\n\n"
         "Maybe you have GIMP versions in both /usr and /usr/local ?",
         GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION,
         gimp_major_version, gimp_minor_version, gimp_micro_version);
    }

  return NULL;
}

98
99
100
101
static gchar *
sanity_check_glib (void)
{
#define GLIB_REQUIRED_MAJOR 2
Sven Neumann's avatar
Sven Neumann committed
102
#define GLIB_REQUIRED_MINOR 16
103
#define GLIB_REQUIRED_MICRO 1
104

Sven Neumann's avatar
Sven Neumann committed
105
106
107
  const gchar *mismatch = glib_check_version (GLIB_REQUIRED_MAJOR,
                                              GLIB_REQUIRED_MINOR,
                                              GLIB_REQUIRED_MICRO);
108
109
110
111
112

  if (mismatch)
    {
      return g_strdup_printf
        ("%s\n\n"
Sven Neumann's avatar
Sven Neumann committed
113
         "GIMP requires GLib version %d.%d.%d or later.\n"
114
         "Installed GLib version is %d.%d.%d.\n\n"
115
         "Somehow you or your software packager managed\n"
Sven Neumann's avatar
Sven Neumann committed
116
         "to install GIMP with an older GLib version.\n\n"
117
         "Please upgrade to GLib version %d.%d.%d or later.",
118
119
120
121
122
         mismatch,
         GLIB_REQUIRED_MAJOR, GLIB_REQUIRED_MINOR, GLIB_REQUIRED_MICRO,
         glib_major_version, glib_minor_version, glib_micro_version,
         GLIB_REQUIRED_MAJOR, GLIB_REQUIRED_MINOR, GLIB_REQUIRED_MICRO);
    }
123

124
125
126
127
128
129
130
#undef GLIB_REQUIRED_MAJOR
#undef GLIB_REQUIRED_MINOR
#undef GLIB_REQUIRED_MICRO

  return NULL;
}

131
132
133
134
135
136
137
static gchar *
sanity_check_pango (void)
{
#define PANGO_REQUIRED_MAJOR 1
#define PANGO_REQUIRED_MINOR 18
#define PANGO_REQUIRED_MICRO 0

Sven Neumann's avatar
Sven Neumann committed
138
139
140
  const gchar *mismatch = pango_version_check (PANGO_REQUIRED_MAJOR,
                                               PANGO_REQUIRED_MINOR,
                                               PANGO_REQUIRED_MICRO);
141
142
143

  if (mismatch)
    {
Sven Neumann's avatar
Sven Neumann committed
144
145
146
147
      const gint pango_major_version = pango_version () / 100 / 100;
      const gint pango_minor_version = pango_version () / 100 % 100;
      const gint pango_micro_version = pango_version () % 100;

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
      return g_strdup_printf
        ("%s\n\n"
         "GIMP requires Pango version %d.%d.%d or later.\n"
         "Installed Pango version is %d.%d.%d.\n\n"
         "Somehow you or your software packager managed\n"
         "to install GIMP with an older Pango version.\n\n"
         "Please upgrade to Pango version %d.%d.%d or later.",
         mismatch,
         PANGO_REQUIRED_MAJOR, PANGO_REQUIRED_MINOR, PANGO_REQUIRED_MICRO,
         pango_major_version, pango_minor_version, pango_micro_version,
         PANGO_REQUIRED_MAJOR, PANGO_REQUIRED_MINOR, PANGO_REQUIRED_MICRO);
    }

#undef PANGO_REQUIRED_MAJOR
#undef PANGO_REQUIRED_MINOR
#undef PANGO_REQUIRED_MICRO

  return NULL;
}

168
169
170
static gchar *
sanity_check_fontconfig (void)
{
Sven Neumann's avatar
Sven Neumann committed
171
  const gint fc_version = FcGetVersion ();
172
173
174
175
176

#define FC_REQUIRED_MAJOR 2
#define FC_REQUIRED_MINOR 2
#define FC_REQUIRED_MICRO 0

177
178
179
180
  if (fc_version < ((FC_REQUIRED_MAJOR * 10000) +
                    (FC_REQUIRED_MINOR *   100) +
                    (FC_REQUIRED_MICRO *     1)))
    {
Sven Neumann's avatar
Sven Neumann committed
181
182
183
184
      const gint fc_major_version = fc_version / 100 / 100;
      const gint fc_minor_version = fc_version / 100 % 100;
      const gint fc_micro_version = fc_version % 100;

185
      return g_strdup_printf
186
        ("The Fontconfig version being used is too old!\n\n"
Sven Neumann's avatar
Sven Neumann committed
187
188
         "GIMP requires Fontconfig version %d.%d.%d or later.\n"
         "The Fontconfig version loaded by GIMP is %d.%d.%d.\n\n"
189
190
191
192
193
194
         "This may be caused by another instance of libfontconfig.so.1\n"
         "being installed in the system, probably in /usr/X11R6/lib.\n"
         "Please correct the situation or report it to someone who can.",
         FC_REQUIRED_MAJOR, FC_REQUIRED_MINOR, FC_REQUIRED_MICRO,
         fc_major_version, fc_minor_version, fc_micro_version);
    }
195
196
197
198

#undef FC_REQUIRED_MAJOR
#undef FC_REQUIRED_MINOR
#undef FC_REQUIRED_MICRO
199

200
201
  return NULL;
}
202

203
204
205
206
207
208
209
210
static gchar *
sanity_check_freetype (void)
{
  FT_Library ft_library;
  FT_Int     ft_major_version;
  FT_Int     ft_minor_version;
  FT_Int     ft_micro_version;
  FT_Int     ft_version;
211
212
213
214
215

#define FT_REQUIRED_MAJOR 2
#define FT_REQUIRED_MINOR 1
#define FT_REQUIRED_MICRO 7

216
217
218
219
220
221
222
  if (FT_Init_FreeType (&ft_library) != 0)
    g_error ("FT_Init_FreeType() failed");

  FT_Library_Version (ft_library,
                      &ft_major_version,
                      &ft_minor_version,
                      &ft_micro_version);
223

224
225
226
227
228
229
230
231
232
233
234
235
236
  if (FT_Done_FreeType (ft_library) != 0)
    g_error ("FT_Done_FreeType() failed");

  ft_version = (ft_major_version * 10000 +
                ft_minor_version *   100 +
                ft_micro_version *     1);

  if (ft_version < ((FT_REQUIRED_MAJOR * 10000) +
                    (FT_REQUIRED_MINOR *   100) +
                    (FT_REQUIRED_MICRO *     1)))
    {
      return g_strdup_printf
        ("FreeType version too old!\n\n"
Sven Neumann's avatar
Sven Neumann committed
237
         "GIMP requires FreeType version %d.%d.%d or later.\n"
238
239
         "Installed FreeType version is %d.%d.%d.\n\n"
         "Somehow you or your software packager managed\n"
Sven Neumann's avatar
Sven Neumann committed
240
         "to install GIMP with an older FreeType version.\n\n"
241
242
243
244
245
         "Please upgrade to FreeType version %d.%d.%d or later.",
         FT_REQUIRED_MAJOR, FT_REQUIRED_MINOR, FT_REQUIRED_MICRO,
         ft_major_version, ft_minor_version, ft_micro_version,
         FT_REQUIRED_MAJOR, FT_REQUIRED_MINOR, FT_REQUIRED_MICRO);
    }
246
247
248
249
250

#undef FT_REQUIRED_MAJOR
#undef FT_REQUIRED_MINOR
#undef FT_REQUIRED_MICRO

251
  return NULL;
252
}
253

254
255
256
257
258
259
260
261
262
static gchar *
sanity_check_babl (void)
{
  gint babl_major_version;
  gint babl_minor_version;
  gint babl_micro_version;

#define BABL_REQUIRED_MAJOR 0
#define BABL_REQUIRED_MINOR 0
263
#define BABL_REQUIRED_MICRO 22
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

  babl_get_version (&babl_major_version,
                    &babl_minor_version,
                    &babl_micro_version);

  if (babl_major_version < BABL_REQUIRED_MAJOR ||
      babl_minor_version < BABL_REQUIRED_MINOR ||
      babl_micro_version < BABL_REQUIRED_MICRO)
    {
      return g_strdup_printf
        ("BABL version too old!\n\n"
         "GIMP requires BABL version %d.%d.%d or later.\n"
         "Installed BABL version is %d.%d.%d.\n\n"
         "Somehow you or your software packager managed\n"
         "to install GIMP with an older BABL version.\n\n"
         "Please upgrade to BABL version %d.%d.%d or later.",
         BABL_REQUIRED_MAJOR, BABL_REQUIRED_MINOR, BABL_REQUIRED_MICRO,
         babl_major_version, babl_minor_version, babl_micro_version,
         BABL_REQUIRED_MAJOR, BABL_REQUIRED_MINOR, BABL_REQUIRED_MICRO);
    }

#undef BABL_REQUIRED_MAJOR
#undef BABL_REQUIRED_MINOR
#undef BABL_REQUIRED_MICRO

  return NULL;
}

292
293
294
295
296
297
298
299
300
static gchar *
sanity_check_gegl (void)
{
  gint gegl_major_version;
  gint gegl_minor_version;
  gint gegl_micro_version;

#define GEGL_REQUIRED_MAJOR 0
#define GEGL_REQUIRED_MINOR 0
301
#define GEGL_REQUIRED_MICRO 18
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

  gegl_get_version (&gegl_major_version,
                    &gegl_minor_version,
                    &gegl_micro_version);

  if (gegl_major_version < GEGL_REQUIRED_MAJOR ||
      gegl_minor_version < GEGL_REQUIRED_MINOR ||
      gegl_micro_version < GEGL_REQUIRED_MICRO)
    {
      return g_strdup_printf
        ("GEGL version too old!\n\n"
         "GIMP requires GEGL version %d.%d.%d or later.\n"
         "Installed GEGL version is %d.%d.%d.\n\n"
         "Somehow you or your software packager managed\n"
         "to install GIMP with an older GEGL version.\n\n"
         "Please upgrade to GEGL version %d.%d.%d or later.",
         GEGL_REQUIRED_MAJOR, GEGL_REQUIRED_MINOR, GEGL_REQUIRED_MICRO,
         gegl_major_version, gegl_minor_version, gegl_micro_version,
         GEGL_REQUIRED_MAJOR, GEGL_REQUIRED_MINOR, GEGL_REQUIRED_MICRO);
    }

#undef GEGL_REQUIRED_MAJOR
#undef GEGL_REQUIRED_MINOR
#undef GEGL_REQUIRED_MICRO

  return NULL;
}

330
331
332
333
334
335
static gchar *
sanity_check_filename_encoding (void)
{
  gchar  *result;
  GError *error = NULL;

336
  result = g_filename_to_utf8 ("", -1, NULL, NULL, &error);
337

338
  if (! result)
339
    {
340
341
342
343
344
345
346
347
348
      gchar *msg =
        g_strdup_printf
        (_("The configured filename encoding cannot be converted to UTF-8: "
           "%s\n\n"
           "Please check the value of the environment variable "
           "G_FILENAME_ENCODING."),
         error->message);

      g_error_free (error);
349

350
      return msg;
351
    }
352
353
354
355
356
357

  g_free (result);

  result = g_filename_to_utf8 (gimp_directory (), -1, NULL, NULL, &error);

  if (! result)
358
359
360
    {
      gchar *msg =
        g_strdup_printf
361
362
363
        (_("The name of the directory holding the GIMP user configuration "
           "cannot be converted to UTF-8: "
           "%s\n\n"
364
365
           "Your filesystem probably stores files in an encoding "
           "other than UTF-8 and you didn't tell GLib about this. "
366
           "Please set the environment variable G_FILENAME_ENCODING."),
367
368
369
370
371
372
         error->message);

      g_error_free (error);

      return msg;
    }
373
374
375
376

  g_free (result);

  return NULL;
377
}