cleanup specfile for packaging
[profile/ivi/cogl.git] / cogl / cogl-config.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2011 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  *
23  * Authors:
24  *   Robert Bragg <robert@linux.intel.com>
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "cogl-debug.h"
32 #include "cogl-config-private.h"
33
34 #include <glib.h>
35
36 char *_cogl_config_driver;
37 char *_cogl_config_renderer;
38
39 static void
40 _cogl_config_process (GKeyFile *key_file)
41 {
42   char *value;
43
44   value = g_key_file_get_string (key_file, "global", "COGL_DEBUG", NULL);
45   if (value)
46     {
47       _cogl_parse_debug_string (value,
48                                 TRUE /* enable the flags */,
49                                 TRUE /* ignore help option */);
50       g_free (value);
51     }
52
53   value = g_key_file_get_string (key_file, "global", "COGL_NO_DEBUG", NULL);
54   if (value)
55     {
56       _cogl_parse_debug_string (value,
57                                 FALSE /* disable the flags */,
58                                 TRUE /* ignore help option */);
59       g_free (value);
60     }
61
62   value = g_key_file_get_string (key_file, "global", "COGL_DRIVER", NULL);
63   if (value)
64     {
65       if (_cogl_config_driver)
66         g_free (_cogl_config_driver);
67
68       _cogl_config_driver = value;
69     }
70
71   value = g_key_file_get_string (key_file, "global", "COGL_RENDERER", NULL);
72   if (value)
73     {
74       if (_cogl_config_renderer)
75         g_free (_cogl_config_renderer);
76
77       _cogl_config_renderer = value;
78     }
79 }
80
81 void
82 _cogl_config_read (void)
83 {
84   GKeyFile *key_file = g_key_file_new ();
85   const char * const *system_dirs = g_get_system_config_dirs ();
86   char *filename;
87   gboolean status = FALSE;
88   int i;
89
90   for (i = 0; system_dirs[i]; i++)
91     {
92       filename = g_build_filename (system_dirs[i], "cogl", "cogl.conf", NULL);
93       status = g_key_file_load_from_file (key_file,
94                                           filename,
95                                           0,
96                                           NULL);
97       g_free (filename);
98       if (status)
99         {
100           _cogl_config_process (key_file);
101           g_key_file_free (key_file);
102           key_file = g_key_file_new ();
103           break;
104         }
105     }
106
107   filename = g_build_filename (g_get_user_config_dir (), "cogl", "cogl.conf", NULL);
108   status = g_key_file_load_from_file (key_file,
109                                       filename,
110                                       0,
111                                       NULL);
112   g_free (filename);
113
114   if (status)
115     _cogl_config_process (key_file);
116
117   g_key_file_free (key_file);
118 }