2
* JB, the Jean-Yves Lefort's Build System
3
* Copyright (C) 2008 Jean-Yves Lefort <jylefort@brutele.be>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
#include "jb-feature.h"
23
#include "jb-variable.h"
25
#include "jb-resource.h"
28
GSList *jb_groups = NULL;
30
JBStringHashSet *jb_templates = NULL;
32
G_DEFINE_TYPE(JBGroup, jb_group, G_TYPE_OBJECT)
35
jb_group_init (JBGroup *self)
40
jb_group_class_init (JBGroupClass *class)
45
jb_group_new (const char *name)
51
g_return_val_if_fail(name != NULL, NULL);
53
self = g_object_new(JB_TYPE_GROUP, NULL);
55
self->name = g_strdup(name);
57
self->srcdir = g_strdup(name);
58
self->builddir = g_strdup_printf("build/%s", self->srcdir);
60
jb_compile_options_init(&self->compile_options);
62
/* srcdir for the C headers, builddir for the generated C headers */
63
cppflags = g_strdup_printf("-I%s -I%s", self->srcdir, self->builddir);
64
jb_compile_options_add_cppflags(&self->compile_options, cppflags);
67
gob2flags = g_strdup_printf("--output-dir=%s", self->builddir);
68
jb_compile_options_add_gob2flags(&self->compile_options, gob2flags);
75
jb_group_add (JBGroup *group)
79
g_return_if_fail(JB_IS_GROUP(group));
81
JB_LIST_FOREACH(l, group->resources)
83
JBResource *res = l->data;
85
if (JB_IS_TEMPLATE(res))
87
JBTemplate *template = JB_TEMPLATE(res);
90
filename = g_strdup_printf("%s/%s", group->srcdir, template->filename);
92
if (jb_templates == NULL)
93
jb_templates = jb_string_hash_set_new();
95
if (! jb_string_hash_set_add(jb_templates, filename))
96
g_error("template file \"%s\" specified multiple times", filename);
102
jb_groups = g_slist_append(jb_groups, group);
106
jb_group_get (const char *name)
110
g_return_val_if_fail(name != NULL, NULL);
112
JB_LIST_FOREACH(l, jb_groups)
114
JBGroup *group = l->data;
116
if (! strcmp(group->name, name))
124
jb_group_add_resource (JBGroup *self, JBGroupResource *res)
126
g_return_if_fail(JB_IS_GROUP(self));
127
g_return_if_fail(JB_IS_GROUP_RESOURCE(res));
128
g_return_if_fail(res->group == NULL);
132
self->resources = g_slist_append(self->resources, res);
136
jb_group_add_dbus_interface (JBGroup *self,
140
const char *server_prefix)
142
g_return_if_fail(JB_IS_GROUP(self));
143
g_return_if_fail(name != NULL);
146
jb_group_add_resource(self, JB_GROUP_RESOURCE(jb_dbus_interface_client_new(name, client)));
148
jb_group_add_resource(self, JB_GROUP_RESOURCE(jb_dbus_interface_server_new(name, server, server_prefix)));
152
jb_group_add_data_file (JBGroup *self,
154
const char *installdir)
156
JBDataFile *data_file;
158
g_return_if_fail(JB_IS_GROUP(self));
159
g_return_if_fail(file != NULL);
161
data_file = jb_data_file_new(file);
163
jb_install_options_set_installdir(&data_file->install_options, installdir);
165
jb_group_add_resource(self, JB_GROUP_RESOURCE(data_file));
169
jb_group_add_data_files (JBGroup *self, const char *file, ...)
173
g_return_if_fail(JB_IS_GROUP(self));
175
va_start(args, file);
179
const char *installdir;
181
installdir = va_arg(args, const char *);
182
g_assert(installdir != NULL);
184
jb_group_add_data_file(self, file, installdir);
186
file = va_arg(args, const char *);
193
jb_group_add_data_files_list (JBGroup *self,
195
const char *installdir)
199
g_return_if_fail(JB_IS_GROUP(self));
201
JB_LIST_FOREACH(l, files)
203
const char *file = l->data;
205
jb_group_add_data_file(self, file, installdir);
210
jb_group_add_data_files_pattern (JBGroup *self,
212
const char *installdir)
216
g_return_if_fail(JB_IS_GROUP(self));
217
g_return_if_fail(pattern != NULL);
220
* We must chdir to srcdir for matching, because the file list must
221
* be relative to srcdir.
223
jb_chdir(self->srcdir);
224
files = jb_match_files(pattern);
225
jb_chdir(jb_topsrcdir);
227
jb_group_add_data_files_list(self, files, installdir);
228
jb_g_slist_free_deep(files);
232
jb_group_add_dist_file (JBGroup *self, const char *file)
234
g_return_if_fail(JB_IS_GROUP(self));
235
g_return_if_fail(file != NULL);
237
jb_group_add_data_file(self, file, NULL);
241
jb_group_add_dist_files (JBGroup *self, const char *file, ...)
245
g_return_if_fail(JB_IS_GROUP(self));
247
va_start(args, file);
251
jb_group_add_dist_file(self, file);
253
file = va_arg(args, const char *);
260
add_intltool_file (JBGroup *self,
262
const char *filename,
263
const char *merge_flags,
264
const char *installdir)
266
JBIntltoolFile *file;
268
file = jb_intltool_file_new(type, filename, merge_flags);
270
jb_install_options_set_installdir(&file->install_options, installdir);
272
jb_group_add_resource(self, JB_GROUP_RESOURCE(file));
276
jb_group_add_desktop_file (JBGroup *self,
277
const char *filename,
278
const char *installdir)
280
g_return_if_fail(JB_IS_GROUP(self));
281
g_return_if_fail(filename != NULL);
282
g_return_if_fail(installdir != NULL);
284
add_intltool_file(self,
292
jb_group_add_gconf_schemas (JBGroup *self, const char *filename)
294
g_return_if_fail(JB_IS_GROUP(self));
295
g_return_if_fail(filename != NULL);
296
g_return_if_fail(jb_feature_is_enabled(&jb_gconf_feature));
297
g_return_if_fail(jb_feature_is_enabled(&jb_intltool_feature));
298
g_return_if_fail(jb_intltool_use_xml);
300
add_intltool_file(self,
304
"$gconf-schemas-dir");
308
jb_group_add_bonobo_server (JBGroup *self, const char *filename)
310
g_return_if_fail(JB_IS_GROUP(self));
311
g_return_if_fail(filename != NULL);
312
g_return_if_fail(jb_feature_is_enabled(&jb_intltool_feature));
313
g_return_if_fail(jb_intltool_use_xml);
315
add_intltool_file(self,
319
"$libdir/bonobo/servers");
323
jb_group_add_translations (JBGroup *self, const char *languages)
328
g_return_if_fail(self != NULL);
329
g_return_if_fail(jb_feature_is_enabled(&jb_gettext_feature));
331
array = g_strsplit(languages, " ", 0);
332
for (i = 0; array[i] != NULL; i++)
333
jb_group_add_resource(self, JB_GROUP_RESOURCE(jb_translations_new(array[i])));