~ubuntu-branches/debian/sid/link-monitor-applet/sid

« back to all changes in this revision

Viewing changes to jbsrc/lib/jb-group.c

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2008-03-30 22:26:13 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080330222613-5aubcuo9mgg2n7st
Tags: upstream-3.0
ImportĀ upstreamĀ versionĀ 3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JB, the Jean-Yves Lefort's Build System
 
3
 * Copyright (C) 2008 Jean-Yves Lefort <jylefort@brutele.be>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include <string.h>
 
21
#include "jb-group.h"
 
22
#include "jb-feature.h"
 
23
#include "jb-variable.h"
 
24
#include "jb-util.h"
 
25
#include "jb-resource.h"
 
26
#include "jb-main.h"
 
27
 
 
28
GSList *jb_groups = NULL;
 
29
 
 
30
JBStringHashSet *jb_templates = NULL;
 
31
 
 
32
G_DEFINE_TYPE(JBGroup, jb_group, G_TYPE_OBJECT)
 
33
 
 
34
static void
 
35
jb_group_init (JBGroup *self)
 
36
{
 
37
}
 
38
 
 
39
static void
 
40
jb_group_class_init (JBGroupClass *class)
 
41
{
 
42
}
 
43
 
 
44
JBGroup *
 
45
jb_group_new (const char *name)
 
46
{
 
47
  JBGroup *self;
 
48
  char *cppflags;
 
49
  char *gob2flags;
 
50
 
 
51
  g_return_val_if_fail(name != NULL, NULL);
 
52
 
 
53
  self = g_object_new(JB_TYPE_GROUP, NULL);
 
54
 
 
55
  self->name = g_strdup(name);
 
56
 
 
57
  self->srcdir = g_strdup(name);
 
58
  self->builddir = g_strdup_printf("build/%s", self->srcdir);
 
59
 
 
60
  jb_compile_options_init(&self->compile_options);
 
61
 
 
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);
 
65
  g_free(cppflags);
 
66
 
 
67
  gob2flags = g_strdup_printf("--output-dir=%s", self->builddir);
 
68
  jb_compile_options_add_gob2flags(&self->compile_options, gob2flags);
 
69
  g_free(gob2flags);
 
70
 
 
71
  return self;
 
72
}
 
73
 
 
74
void
 
75
jb_group_add (JBGroup *group)
 
76
{
 
77
  GSList *l;
 
78
 
 
79
  g_return_if_fail(JB_IS_GROUP(group));
 
80
 
 
81
  JB_LIST_FOREACH(l, group->resources)
 
82
    {
 
83
      JBResource *res = l->data;
 
84
 
 
85
      if (JB_IS_TEMPLATE(res))
 
86
        {
 
87
          JBTemplate *template = JB_TEMPLATE(res);
 
88
          char *filename;
 
89
 
 
90
          filename = g_strdup_printf("%s/%s", group->srcdir, template->filename);
 
91
 
 
92
          if (jb_templates == NULL)
 
93
            jb_templates = jb_string_hash_set_new();
 
94
 
 
95
          if (! jb_string_hash_set_add(jb_templates, filename))
 
96
            g_error("template file \"%s\" specified multiple times", filename);
 
97
 
 
98
          g_free(filename);
 
99
        }
 
100
    }
 
101
 
 
102
  jb_groups = g_slist_append(jb_groups, group);
 
103
}
 
104
 
 
105
JBGroup *
 
106
jb_group_get (const char *name)
 
107
{
 
108
  GSList *l;
 
109
 
 
110
  g_return_val_if_fail(name != NULL, NULL);
 
111
 
 
112
  JB_LIST_FOREACH(l, jb_groups)
 
113
    {
 
114
      JBGroup *group = l->data;
 
115
 
 
116
      if (! strcmp(group->name, name))
 
117
        return group;
 
118
    }
 
119
 
 
120
  return NULL;
 
121
}
 
122
 
 
123
void
 
124
jb_group_add_resource (JBGroup *self, JBGroupResource *res)
 
125
{
 
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);
 
129
 
 
130
  res->group = self;
 
131
 
 
132
  self->resources = g_slist_append(self->resources, res);
 
133
}
 
134
 
 
135
void
 
136
jb_group_add_dbus_interface (JBGroup *self,
 
137
                             const char *name,
 
138
                             const char *client,
 
139
                             const char *server,
 
140
                             const char *server_prefix)
 
141
{
 
142
  g_return_if_fail(JB_IS_GROUP(self));
 
143
  g_return_if_fail(name != NULL);
 
144
 
 
145
  if (client != NULL)
 
146
    jb_group_add_resource(self, JB_GROUP_RESOURCE(jb_dbus_interface_client_new(name, client)));
 
147
  if (server != NULL)
 
148
    jb_group_add_resource(self, JB_GROUP_RESOURCE(jb_dbus_interface_server_new(name, server, server_prefix)));
 
149
}
 
150
 
 
151
void
 
152
jb_group_add_data_file (JBGroup *self,
 
153
                        const char *file,
 
154
                        const char *installdir)
 
155
{
 
156
  JBDataFile *data_file;
 
157
 
 
158
  g_return_if_fail(JB_IS_GROUP(self));
 
159
  g_return_if_fail(file != NULL);
 
160
 
 
161
  data_file = jb_data_file_new(file);
 
162
 
 
163
  jb_install_options_set_installdir(&data_file->install_options, installdir);
 
164
 
 
165
  jb_group_add_resource(self, JB_GROUP_RESOURCE(data_file));
 
166
}
 
167
 
 
168
void
 
169
jb_group_add_data_files (JBGroup *self, const char *file, ...)
 
170
{
 
171
  va_list args;
 
172
 
 
173
  g_return_if_fail(JB_IS_GROUP(self));
 
174
 
 
175
  va_start(args, file);
 
176
 
 
177
  while (file != NULL)
 
178
    {
 
179
      const char *installdir;
 
180
 
 
181
      installdir = va_arg(args, const char *);
 
182
      g_assert(installdir != NULL);
 
183
 
 
184
      jb_group_add_data_file(self, file, installdir);
 
185
 
 
186
      file = va_arg(args, const char *);
 
187
    }
 
188
 
 
189
  va_end(args);
 
190
}
 
191
 
 
192
void
 
193
jb_group_add_data_files_list (JBGroup *self,
 
194
                              GSList *files,
 
195
                              const char *installdir)
 
196
{
 
197
  GSList *l;
 
198
 
 
199
  g_return_if_fail(JB_IS_GROUP(self));
 
200
 
 
201
  JB_LIST_FOREACH(l, files)
 
202
    {
 
203
      const char *file = l->data;
 
204
 
 
205
      jb_group_add_data_file(self, file, installdir);
 
206
    }
 
207
}
 
208
 
 
209
void
 
210
jb_group_add_data_files_pattern (JBGroup *self,
 
211
                                 const char *pattern,
 
212
                                 const char *installdir)
 
213
{
 
214
  GSList *files;
 
215
 
 
216
  g_return_if_fail(JB_IS_GROUP(self));
 
217
  g_return_if_fail(pattern != NULL);
 
218
 
 
219
  /*
 
220
   * We must chdir to srcdir for matching, because the file list must
 
221
   * be relative to srcdir.
 
222
   */
 
223
  jb_chdir(self->srcdir);
 
224
  files = jb_match_files(pattern);
 
225
  jb_chdir(jb_topsrcdir);
 
226
 
 
227
  jb_group_add_data_files_list(self, files, installdir);
 
228
  jb_g_slist_free_deep(files);
 
229
}
 
230
 
 
231
void
 
232
jb_group_add_dist_file (JBGroup *self, const char *file)
 
233
{
 
234
  g_return_if_fail(JB_IS_GROUP(self));
 
235
  g_return_if_fail(file != NULL);
 
236
 
 
237
  jb_group_add_data_file(self, file, NULL);
 
238
}
 
239
 
 
240
void
 
241
jb_group_add_dist_files (JBGroup *self, const char *file, ...)
 
242
{
 
243
  va_list args;
 
244
 
 
245
  g_return_if_fail(JB_IS_GROUP(self));
 
246
 
 
247
  va_start(args, file);
 
248
 
 
249
  while (file != NULL)
 
250
    {
 
251
      jb_group_add_dist_file(self, file);
 
252
 
 
253
      file = va_arg(args, const char *);
 
254
    }
 
255
 
 
256
  va_end(args);
 
257
}
 
258
 
 
259
static void
 
260
add_intltool_file (JBGroup *self,
 
261
                   const char *type,
 
262
                   const char *filename,
 
263
                   const char *merge_flags,
 
264
                   const char *installdir)
 
265
{
 
266
  JBIntltoolFile *file;
 
267
 
 
268
  file = jb_intltool_file_new(type, filename, merge_flags);
 
269
 
 
270
  jb_install_options_set_installdir(&file->install_options, installdir);
 
271
 
 
272
  jb_group_add_resource(self, JB_GROUP_RESOURCE(file));
 
273
}
 
274
 
 
275
void
 
276
jb_group_add_desktop_file (JBGroup *self,
 
277
                           const char *filename,
 
278
                           const char *installdir)
 
279
{
 
280
  g_return_if_fail(JB_IS_GROUP(self));
 
281
  g_return_if_fail(filename != NULL);
 
282
  g_return_if_fail(installdir != NULL);
 
283
 
 
284
  add_intltool_file(self,
 
285
                    "desktop file",
 
286
                    filename,
 
287
                    "-d",
 
288
                    installdir);
 
289
}
 
290
 
 
291
void
 
292
jb_group_add_gconf_schemas (JBGroup *self, const char *filename)
 
293
{
 
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);
 
299
 
 
300
  add_intltool_file(self,
 
301
                    "GConf schemas",
 
302
                    filename,
 
303
                    "-s",
 
304
                    "$gconf-schemas-dir");
 
305
}
 
306
 
 
307
void
 
308
jb_group_add_bonobo_server (JBGroup *self, const char *filename)
 
309
{
 
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);
 
314
 
 
315
  add_intltool_file(self,
 
316
                    "Bonobo server",
 
317
                    filename,
 
318
                    "-b",
 
319
                    "$libdir/bonobo/servers");
 
320
}
 
321
 
 
322
void
 
323
jb_group_add_translations (JBGroup *self, const char *languages)
 
324
{
 
325
  char **array;
 
326
  int i;
 
327
 
 
328
  g_return_if_fail(self != NULL);
 
329
  g_return_if_fail(jb_feature_is_enabled(&jb_gettext_feature));
 
330
 
 
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])));
 
334
  g_strfreev(array);
 
335
}