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

« back to all changes in this revision

Viewing changes to jbsrc/lib/jb-resource.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-resource.h"
 
22
#include "jb-group.h"
 
23
#include "jb-variable.h"
 
24
#include "jb-util.h"
 
25
#include "jb-feature.h"
 
26
#include "jb-action.h"
 
27
 
 
28
#define INTLTOOL_MERGE_IN       "jbsrc/tools/intltool-merge.in"
 
29
#define INTLTOOL_MERGE_OUT      "build/jbsrc/tools/intltool-merge"
 
30
#define INTLTOOL_MERGE_CACHE    "build/jbsrc/tools/intltool-merge-cache"
 
31
 
 
32
static gboolean
 
33
has_template (const char *filename)
 
34
{
 
35
  char *template_input;
 
36
  gboolean result;
 
37
 
 
38
  if (jb_templates == NULL)
 
39
    return FALSE;
 
40
 
 
41
  template_input = g_strdup_printf("%s.in", filename);
 
42
  result = jb_string_hash_set_contains(jb_templates, template_input);
 
43
  g_free(template_input);
 
44
 
 
45
  return result;
 
46
}
 
47
 
 
48
static char *
 
49
get_input_file (const char *filename)
 
50
{
 
51
  if (has_template(filename))
 
52
    return g_strdup_printf("build/%s", filename);
 
53
  else
 
54
    return g_strdup(filename);
 
55
}
 
56
 
 
57
static char *
 
58
get_output_file (const char *filename)
 
59
{
 
60
  char *tmp;
 
61
  char *result;
 
62
 
 
63
  g_return_val_if_fail(filename != NULL, NULL);
 
64
  g_return_val_if_fail(g_str_has_suffix(filename, ".in"), NULL);
 
65
 
 
66
  tmp = jb_strip_extension(filename);
 
67
 
 
68
  /*
 
69
   * If the input file is already in build/, do not put the output
 
70
   * file in build/build/.
 
71
   */
 
72
  if (g_str_has_prefix(tmp, "build/"))
 
73
    result = g_strdup(tmp);
 
74
  else
 
75
    result = g_strdup_printf("build/%s", tmp);
 
76
 
 
77
  g_free(tmp);
 
78
 
 
79
  return result;
 
80
}
 
81
 
 
82
G_DEFINE_ABSTRACT_TYPE(JBResource, jb_resource, G_TYPE_OBJECT)
 
83
 
 
84
char *
 
85
jb_resource_to_string (JBResource *self)
 
86
{
 
87
  JBResourceClass *class;
 
88
 
 
89
  g_return_val_if_fail(JB_IS_RESOURCE(self), NULL);
 
90
 
 
91
  class = JB_RESOURCE_GET_CLASS(self);
 
92
 
 
93
  if (class->to_string != NULL)
 
94
    return class->to_string(self);
 
95
  else
 
96
    {
 
97
      g_error("to_string() not implemented for resource type %s", G_OBJECT_TYPE_NAME(self));
 
98
      return NULL;
 
99
    }
 
100
}
 
101
 
 
102
void
 
103
jb_resource_pre_build (JBResource *self)
 
104
{
 
105
  JBResourceClass *class;
 
106
 
 
107
  g_return_if_fail(JB_IS_RESOURCE(self));
 
108
 
 
109
  class = JB_RESOURCE_GET_CLASS(self);
 
110
 
 
111
  if (class->pre_build != NULL)
 
112
    class->pre_build(self);
 
113
}
 
114
 
 
115
void
 
116
jb_resource_build (JBResource *self)
 
117
{
 
118
  JBResourceClass *class;
 
119
 
 
120
  g_return_if_fail(JB_IS_RESOURCE(self));
 
121
 
 
122
  class = JB_RESOURCE_GET_CLASS(self);
 
123
 
 
124
  if (class->build != NULL)
 
125
    class->build(self);
 
126
}
 
127
 
 
128
void
 
129
jb_resource_install (JBResource *self)
 
130
{
 
131
  JBResourceClass *class;
 
132
 
 
133
  g_return_if_fail(JB_IS_RESOURCE(self));
 
134
 
 
135
  class = JB_RESOURCE_GET_CLASS(self);
 
136
 
 
137
  if (class->install != NULL)
 
138
    class->install(self);
 
139
}
 
140
 
 
141
void
 
142
jb_resource_makedist (JBResource *self)
 
143
{
 
144
  JBResourceClass *class;
 
145
 
 
146
  g_return_if_fail(JB_IS_RESOURCE(self));
 
147
 
 
148
  class = JB_RESOURCE_GET_CLASS(self);
 
149
 
 
150
  if (class->makedist != NULL)
 
151
    class->makedist(self);
 
152
}
 
153
 
 
154
void
 
155
jb_resource_clean (JBResource *self)
 
156
{
 
157
  JBResourceClass *class;
 
158
 
 
159
  g_return_if_fail(JB_IS_RESOURCE(self));
 
160
 
 
161
  class = JB_RESOURCE_GET_CLASS(self);
 
162
 
 
163
  if (class->clean != NULL)
 
164
    class->clean(self);
 
165
}
 
166
 
 
167
void
 
168
jb_resource_distclean (JBResource *self)
 
169
{
 
170
  JBResourceClass *class;
 
171
 
 
172
  g_return_if_fail(JB_IS_RESOURCE(self));
 
173
 
 
174
  class = JB_RESOURCE_GET_CLASS(self);
 
175
 
 
176
  if (class->distclean != NULL)
 
177
    class->distclean(self);
 
178
}
 
179
 
 
180
void
 
181
jb_resource_maintainerclean (JBResource *self)
 
182
{
 
183
  JBResourceClass *class;
 
184
 
 
185
  g_return_if_fail(JB_IS_RESOURCE(self));
 
186
 
 
187
  class = JB_RESOURCE_GET_CLASS(self);
 
188
 
 
189
  if (class->maintainerclean != NULL)
 
190
    class->maintainerclean(self);
 
191
}
 
192
 
 
193
static void
 
194
jb_resource_init (JBResource *self)
 
195
{
 
196
}
 
197
 
 
198
static void
 
199
jb_resource_class_init (JBResourceClass *class)
 
200
{
 
201
}
 
202
 
 
203
static void
 
204
resource_action_message (JBResource *self, const char *action)
 
205
{
 
206
  char *repr;
 
207
 
 
208
  g_return_if_fail(JB_IS_RESOURCE(self));
 
209
  g_return_if_fail(action != NULL);
 
210
 
 
211
  repr = jb_resource_to_string(self);
 
212
  jb_message("%s %s", action, repr);
 
213
  g_free(repr);
 
214
}
 
215
 
 
216
static void
 
217
resource_message_building (JBResource *self)
 
218
{
 
219
  g_return_if_fail(JB_IS_RESOURCE(self));
 
220
 
 
221
  resource_action_message(self, "building");
 
222
}
 
223
 
 
224
G_DEFINE_ABSTRACT_TYPE(JBGroupResource, jb_group_resource, JB_TYPE_RESOURCE)
 
225
 
 
226
static void
 
227
jb_group_resource_init (JBGroupResource *self)
 
228
{
 
229
}
 
230
 
 
231
static void
 
232
jb_group_resource_class_init (JBGroupResourceClass *class)
 
233
{
 
234
}
 
235
 
 
236
G_DEFINE_ABSTRACT_TYPE(JBObjectResource, jb_object_resource, JB_TYPE_RESOURCE)
 
237
 
 
238
static void
 
239
jb_object_resource_init (JBObjectResource *self)
 
240
{
 
241
}
 
242
 
 
243
static void
 
244
jb_object_resource_class_init (JBObjectResourceClass *class)
 
245
{
 
246
}
 
247
 
 
248
static char *
 
249
object_resource_get_object_file (JBObjectResource *self)
 
250
{
 
251
  JBObjectResourceClass *class;
 
252
 
 
253
  g_return_val_if_fail(JB_IS_OBJECT_RESOURCE(self), NULL);
 
254
 
 
255
  class = JB_OBJECT_RESOURCE_GET_CLASS(self);
 
256
 
 
257
  if (class->get_object_file != NULL)
 
258
    return class->get_object_file(self);
 
259
  else
 
260
    {
 
261
      g_error("get_object_file() not implemented for object resource type %s", G_OBJECT_TYPE_NAME(self));
 
262
      return NULL;
 
263
    }
 
264
}
 
265
 
 
266
G_DEFINE_TYPE(JBTemplate, jb_template, JB_TYPE_GROUP_RESOURCE)
 
267
 
 
268
JBTemplate *
 
269
jb_template_new (const char *filename)
 
270
{
 
271
  JBTemplate *self;
 
272
 
 
273
  g_return_val_if_fail(filename != NULL, NULL);
 
274
  g_return_val_if_fail(g_str_has_suffix(filename, ".in"), NULL);
 
275
 
 
276
  self = g_object_new(JB_TYPE_TEMPLATE, NULL);
 
277
  self->filename = g_strdup(filename);
 
278
 
 
279
  return self;
 
280
}
 
281
 
 
282
static char *
 
283
template_to_string (JBResource *res)
 
284
{
 
285
  JBTemplate *self = JB_TEMPLATE(res);
 
286
 
 
287
  return g_strdup_printf("template %s", self->filename);
 
288
}
 
289
 
 
290
static void
 
291
template_get_files (JBTemplate *self, char **infile, char **outfile)
 
292
{
 
293
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
294
 
 
295
  if (infile != NULL)
 
296
    *infile = g_strdup_printf("%s/%s", gres->group->srcdir, self->filename);
 
297
  if (outfile != NULL)
 
298
    {
 
299
      char *tmp;
 
300
 
 
301
      tmp = jb_strip_extension(self->filename);
 
302
      *outfile = g_strdup_printf("%s/%s", gres->group->builddir, tmp);
 
303
      g_free(tmp);
 
304
    }
 
305
}
 
306
 
 
307
static void
 
308
template_build (JBResource *res)
 
309
{
 
310
  JBTemplate *self = JB_TEMPLATE(res);
 
311
  char *infile;
 
312
  char *outfile;
 
313
 
 
314
  template_get_files(self, &infile, &outfile);
 
315
 
 
316
  if (! jb_is_uptodate(outfile, infile))
 
317
    {
 
318
      static GHashTable *variables = NULL;
 
319
 
 
320
      resource_message_building(res);
 
321
 
 
322
      if (variables == NULL)
 
323
        {
 
324
          GSList *l;
 
325
 
 
326
          variables = g_hash_table_new(g_str_hash, g_str_equal);
 
327
 
 
328
          JB_LIST_FOREACH(l, jb_variables)
 
329
            {
 
330
              JBVariable *variable = l->data;
 
331
 
 
332
              g_hash_table_insert(variables, variable->name, jb_variable_evaluate(variable));
 
333
            }
 
334
        }
 
335
 
 
336
      jb_mkdir_of_file(outfile);
 
337
 
 
338
      jb_subst(infile, outfile, variables);
 
339
    }
 
340
 
 
341
  g_free(infile);
 
342
  g_free(outfile);
 
343
}
 
344
 
 
345
static void
 
346
template_makedist (JBResource *res)
 
347
{
 
348
  JBTemplate *self = JB_TEMPLATE(res);
 
349
  char *infile;
 
350
 
 
351
  template_get_files(self, &infile, NULL);
 
352
 
 
353
  jb_action_add_to_dist(infile);
 
354
 
 
355
  g_free(infile);
 
356
}
 
357
 
 
358
static void
 
359
template_clean (JBResource *res)
 
360
{
 
361
  JBTemplate *self = JB_TEMPLATE(res);
 
362
  char *outfile;
 
363
 
 
364
  template_get_files(self, NULL, &outfile);
 
365
 
 
366
  jb_action_rm(outfile);
 
367
 
 
368
  g_free(outfile);
 
369
}
 
370
 
 
371
static void
 
372
jb_template_init (JBTemplate *self)
 
373
{
 
374
}
 
375
 
 
376
static void
 
377
jb_template_class_init (JBTemplateClass *class)
 
378
{
 
379
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
380
 
 
381
  rclass->to_string = template_to_string;
 
382
  rclass->build = template_build;
 
383
  rclass->makedist = template_makedist;
 
384
  rclass->clean = template_clean;
 
385
}
 
386
 
 
387
G_DEFINE_TYPE(JBDataFile, jb_data_file, JB_TYPE_GROUP_RESOURCE)
 
388
 
 
389
JBDataFile *
 
390
jb_data_file_new (const char *filename)
 
391
{
 
392
  JBDataFile *self;
 
393
 
 
394
  g_return_val_if_fail(filename != NULL, NULL);
 
395
 
 
396
  self = g_object_new(JB_TYPE_DATA_FILE, NULL);
 
397
  self->filename = g_strdup(filename);
 
398
 
 
399
  return self;
 
400
}
 
401
 
 
402
static char *
 
403
data_file_to_string (JBResource *res)
 
404
{
 
405
  JBDataFile *self = JB_DATA_FILE(res);
 
406
 
 
407
  return g_strdup_printf("data file %s", self->filename);
 
408
}
 
409
 
 
410
static void
 
411
data_file_install (JBResource *res)
 
412
{
 
413
  JBDataFile *self = JB_DATA_FILE(res);
 
414
  JBGroupResource *gres = JB_GROUP_RESOURCE(res);
 
415
  char *srcfile;
 
416
  char *real_srcfile;
 
417
  char *dstfile;
 
418
 
 
419
  srcfile = g_strdup_printf("%s/%s", gres->group->srcdir, self->filename);
 
420
  real_srcfile = get_input_file(srcfile);
 
421
  dstfile = g_path_get_basename(self->filename);
 
422
 
 
423
  jb_install_options_install_data(&self->install_options, real_srcfile, dstfile);
 
424
 
 
425
  g_free(srcfile);
 
426
  g_free(real_srcfile);
 
427
  g_free(dstfile);
 
428
}
 
429
 
 
430
static void
 
431
data_file_makedist (JBResource *res)
 
432
{
 
433
  JBDataFile *self = JB_DATA_FILE(res);
 
434
  JBGroupResource *gres = JB_GROUP_RESOURCE(res);
 
435
  char *file;
 
436
 
 
437
  file = g_strdup_printf("%s/%s", gres->group->srcdir, self->filename);
 
438
 
 
439
  if (! has_template(file))
 
440
    jb_action_add_to_dist(file);
 
441
 
 
442
  g_free(file);
 
443
}
 
444
 
 
445
static void
 
446
jb_data_file_init (JBDataFile *self)
 
447
{
 
448
  jb_install_options_init(&self->install_options);
 
449
}
 
450
 
 
451
static void
 
452
jb_data_file_class_init (JBDataFileClass *class)
 
453
{
 
454
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
455
 
 
456
  rclass->to_string = data_file_to_string;
 
457
  rclass->install = data_file_install;
 
458
  rclass->makedist = data_file_makedist;
 
459
}
 
460
 
 
461
static GSList *
 
462
parse_depsfile (const char *depsfile)
 
463
{
 
464
  char *contents;
 
465
  char **lines;
 
466
  GSList *deps = NULL;
 
467
  int i;
 
468
 
 
469
  contents = jb_read_file(depsfile, NULL);
 
470
  if (contents == NULL)
 
471
    return NULL;                /* depsfile is optional */
 
472
 
 
473
  lines = g_strsplit(contents, "\n", 0);
 
474
  g_free(contents);
 
475
 
 
476
  for (i = 0; lines[i] != NULL; i++)
 
477
    {
 
478
      char *p;
 
479
      char **files;
 
480
      int j;
 
481
 
 
482
      p = strchr(lines[i], ':');
 
483
      if (p != NULL)
 
484
        p++;
 
485
      else
 
486
        p = lines[i];
 
487
 
 
488
      files = g_strsplit(p, " ", 0);
 
489
 
 
490
      for (j = 0; files[j] != NULL; j++)
 
491
        {
 
492
          char *file;
 
493
 
 
494
          file = g_strdup(files[j]);
 
495
          file = g_strstrip(file);
 
496
 
 
497
          if (*file != '\0' && *file != '\\')
 
498
            deps = g_slist_prepend(deps, g_strdup(file));
 
499
 
 
500
          g_free(file);
 
501
        }
 
502
 
 
503
      g_strfreev(files);
 
504
    }
 
505
 
 
506
  return deps;
 
507
}
 
508
 
 
509
static char *
 
510
object_file_get_depsfile (const char *ofile)
 
511
{
 
512
  return g_strdup_printf("%s.deps", ofile);
 
513
}
 
514
 
 
515
static gboolean
 
516
object_file_is_uptodate (const char *ofile, const char *cfile)
 
517
{
 
518
  char *depsfile;
 
519
  GSList *deps;
 
520
 
 
521
  if (! jb_variable_get_bool("cc-dependency-tracking"))
 
522
    return FALSE;
 
523
 
 
524
  if (! jb_is_uptodate(ofile, cfile))
 
525
    return FALSE;
 
526
 
 
527
  depsfile = object_file_get_depsfile(ofile);
 
528
  deps = parse_depsfile(depsfile);
 
529
  g_free(depsfile);
 
530
 
 
531
  if (deps != NULL)
 
532
    {
 
533
      gboolean is_uptodate;
 
534
 
 
535
      is_uptodate = jb_is_uptodate_list(ofile, deps);
 
536
 
 
537
      jb_g_slist_free_deep(deps);
 
538
 
 
539
      return is_uptodate;
 
540
    }
 
541
  else
 
542
    return TRUE;
 
543
}
 
544
 
 
545
static void
 
546
object_file_build (JBObject *object, const char *ofile, const char *cfile)
 
547
{
 
548
  JBGroupResource *gres = JB_GROUP_RESOURCE(object);
 
549
  JBObjectClass *object_class;
 
550
  char *depsfile;
 
551
  char *depsflags = NULL;
 
552
 
 
553
  object_class = JB_OBJECT_GET_CLASS(object);
 
554
 
 
555
  depsfile = object_file_get_depsfile(ofile);
 
556
 
 
557
  if (jb_variable_get_bool("cc-dependency-tracking"))
 
558
    depsflags = jb_variable_expand(" -MT $ofile -MD -MP -MF $depsfile",
 
559
                                   "ofile", ofile,
 
560
                                   "depsfile", depsfile,
 
561
                                   NULL);
 
562
 
 
563
  jb_mkdir_of_file(ofile);
 
564
 
 
565
  jb_action_exec("$cc $package-cflags $group-cflags $object-cflags $stock-cflags $cflags"
 
566
                 " $package-cppflags $group-cppflags $object-cppflags $stock-cppflags $cppflags"
 
567
                 " $depsflags -c -o $ofile $cfile",
 
568
                 "package-cflags", jb_compile_options.cflags->str,
 
569
                 "group-cflags", gres->group->compile_options.cflags->str,
 
570
                 "object-cflags", object->compile_options.cflags->str,
 
571
                 "stock-cflags", object_class->stock_cflags,
 
572
                 "package-cppflags", jb_compile_options_get_effective_cppflags(&jb_compile_options),
 
573
                 "group-cppflags", jb_compile_options_get_effective_cppflags(&gres->group->compile_options),
 
574
                 "object-cppflags", jb_compile_options_get_effective_cppflags(&object->compile_options),
 
575
                 "stock-cppflags", object_class->stock_cppflags,
 
576
                 "depsflags", depsflags,
 
577
                 "ofile", ofile,
 
578
                 "cfile", cfile,
 
579
                 NULL);
 
580
 
 
581
  g_free(depsfile);
 
582
  g_free(depsflags);
 
583
}
 
584
 
 
585
static void
 
586
object_file_clean (const char *ofile)
 
587
{
 
588
  char *depsfile;
 
589
 
 
590
  depsfile = object_file_get_depsfile(ofile);
 
591
 
 
592
  jb_action_rm(ofile);
 
593
  jb_action_rm(depsfile);
 
594
 
 
595
  g_free(depsfile);
 
596
}
 
597
 
 
598
G_DEFINE_TYPE(JBSource, jb_source, JB_TYPE_OBJECT_RESOURCE)
 
599
 
 
600
JBSource *
 
601
jb_source_new (const char *filename)
 
602
{
 
603
  JBSource *self;
 
604
 
 
605
  g_return_val_if_fail(filename != NULL, NULL);
 
606
 
 
607
  self = g_object_new(JB_TYPE_SOURCE, NULL);
 
608
  self->filename = g_strdup(filename);
 
609
 
 
610
  return self;
 
611
}
 
612
 
 
613
static char *
 
614
source_to_string (JBResource *res)
 
615
{
 
616
  JBSource *self = JB_SOURCE(res);
 
617
  char *base_filename;
 
618
  char *str;
 
619
 
 
620
  base_filename = g_path_get_basename(self->filename);
 
621
  str = g_strdup_printf("C source %s", base_filename);
 
622
  g_free(base_filename);
 
623
 
 
624
  return str;
 
625
}
 
626
 
 
627
static void
 
628
source_get_files (JBSource *self, char **ofile, char **cfile)
 
629
{
 
630
  JBObjectResource *ores = JB_OBJECT_RESOURCE(self);
 
631
  JBGroupResource *gres = JB_GROUP_RESOURCE(ores->object);
 
632
  char *base_filename;
 
633
  char *base_prefix;
 
634
 
 
635
  base_filename = g_path_get_basename(self->filename);
 
636
  base_prefix = jb_strip_extension(base_filename);
 
637
 
 
638
  if (ofile != NULL)
 
639
    *ofile = g_strdup_printf("%s/%s-%s.o",
 
640
                             gres->group->builddir,
 
641
                             ores->object->name,
 
642
                             base_prefix);
 
643
  if (cfile != NULL)
 
644
    *cfile = g_strdup_printf("%s/%s", gres->group->srcdir, self->filename);
 
645
 
 
646
  g_free(base_filename);
 
647
  g_free(base_prefix);
 
648
}
 
649
 
 
650
static void
 
651
source_build (JBResource *res)
 
652
{
 
653
  JBObjectResource *ores = JB_OBJECT_RESOURCE(res);
 
654
  JBSource *self = JB_SOURCE(res);
 
655
  char *ofile;
 
656
  char *cfile;
 
657
 
 
658
  source_get_files(self, &ofile, &cfile);
 
659
 
 
660
  if (! object_file_is_uptodate(ofile, cfile))
 
661
    {
 
662
      resource_message_building(res);
 
663
      object_file_build(ores->object, ofile, cfile);
 
664
    }
 
665
 
 
666
  g_free(ofile);
 
667
  g_free(cfile);
 
668
}
 
669
 
 
670
static void
 
671
source_makedist (JBResource *res)
 
672
{
 
673
  JBSource *self = JB_SOURCE(res);
 
674
  char *cfile;
 
675
 
 
676
  source_get_files(self, NULL, &cfile);
 
677
 
 
678
  jb_action_add_to_dist(cfile);
 
679
 
 
680
  g_free(cfile);
 
681
}
 
682
 
 
683
static void
 
684
source_clean (JBResource *res)
 
685
{
 
686
  JBSource *self = JB_SOURCE(res);
 
687
  char *ofile;
 
688
 
 
689
  source_get_files(self, &ofile, NULL);
 
690
 
 
691
  object_file_clean(ofile);
 
692
 
 
693
  g_free(ofile);
 
694
}
 
695
 
 
696
static char *
 
697
source_get_object_file (JBObjectResource *res)
 
698
{
 
699
  JBSource *self = JB_SOURCE(res);
 
700
  char *ofile;
 
701
 
 
702
  source_get_files(self, &ofile, NULL);
 
703
 
 
704
  return ofile;
 
705
}
 
706
 
 
707
static void
 
708
jb_source_init (JBSource *self)
 
709
{
 
710
}
 
711
 
 
712
static void
 
713
jb_source_class_init (JBSourceClass *class)
 
714
{
 
715
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
716
  JBObjectResourceClass *orclass = JB_OBJECT_RESOURCE_CLASS(class);
 
717
 
 
718
  rclass->to_string = source_to_string;
 
719
  rclass->build = source_build;
 
720
  rclass->makedist = source_makedist;
 
721
  rclass->clean = source_clean;
 
722
 
 
723
  orclass->get_object_file = source_get_object_file;
 
724
}
 
725
 
 
726
G_DEFINE_TYPE(JBGobClass, jb_gob_class, JB_TYPE_OBJECT_RESOURCE)
 
727
 
 
728
JBGobClass *
 
729
jb_gob_class_new (const char *name)
 
730
{
 
731
  JBGobClass *self;
 
732
 
 
733
  g_return_val_if_fail(name != NULL, NULL);
 
734
  g_return_val_if_fail(jb_feature_is_enabled(&jb_gob2_feature), NULL);
 
735
 
 
736
  self = g_object_new(JB_TYPE_GOB_CLASS, NULL);
 
737
  self->name = g_strdup(name);
 
738
 
 
739
  return self;
 
740
}
 
741
 
 
742
static void
 
743
gob_class_get_gob_files (JBGobClass *self, char **gobfile, char **stamp)
 
744
{
 
745
  JBGroupResource *gres = JB_GROUP_RESOURCE(JB_OBJECT_RESOURCE(self)->object);
 
746
  char *prefix;
 
747
 
 
748
  prefix = g_strdelimit(g_ascii_strdown(self->name, -1), ":", '-');
 
749
  if (gobfile != NULL)
 
750
    *gobfile = g_strdup_printf("%s/%s.gob", gres->group->srcdir, prefix);
 
751
  if (stamp != NULL)
 
752
    *stamp = g_strdup_printf("%s/%s.gob.stamp", gres->group->builddir, prefix);
 
753
  g_free(prefix);
 
754
}
 
755
 
 
756
static void
 
757
gob_class_pre_build (JBResource *res)
 
758
{
 
759
  JBGobClass *self = JB_GOB_CLASS(res);
 
760
  char *gobfile;
 
761
  char *stamp;
 
762
 
 
763
  gob_class_get_gob_files(self, &gobfile, &stamp);
 
764
 
 
765
  if (! jb_is_uptodate(stamp, gobfile))
 
766
    {
 
767
      JBObjectResource *ores = JB_OBJECT_RESOURCE(res);
 
768
      JBGroupResource *gres = JB_GROUP_RESOURCE(ores->object);
 
769
      const char *error;
 
770
 
 
771
      error = jb_variable_get_string_or_null("gob2-error");
 
772
      if (error != NULL)
 
773
        jb_error("%s", error);
 
774
 
 
775
      jb_message("building GOB class %s", self->name);
 
776
 
 
777
      jb_mkdir(gres->group->builddir);
 
778
 
 
779
      jb_action_exec("$gob2 $package-gob2flags $group-gob2flags $object-gob2flags $gobfile",
 
780
                     "package-gob2flags", jb_compile_options.gob2flags->str,
 
781
                     "group-gob2flags", gres->group->compile_options.gob2flags->str,
 
782
                     "object-gob2flags", ores->object->compile_options.gob2flags->str,
 
783
                     "gobfile", gobfile,
 
784
                     NULL);
 
785
 
 
786
      jb_action_exec("touch $stamp",
 
787
                     "stamp", stamp,
 
788
                     NULL);
 
789
    }
 
790
 
 
791
  g_free(gobfile);
 
792
  g_free(stamp);
 
793
}
 
794
 
 
795
static void
 
796
gob_class_get_c_files (JBGobClass *self,
 
797
                       char **ofile,
 
798
                       char **cfile,
 
799
                       char **hfile,
 
800
                       char **phfile)
 
801
{
 
802
  JBObjectResource *ores = JB_OBJECT_RESOURCE(self);
 
803
  JBGroupResource *gres = JB_GROUP_RESOURCE(ores->object);
 
804
  char *prefix;
 
805
 
 
806
  prefix = g_strdelimit(g_ascii_strdown(self->name, -1), ":", '-');
 
807
 
 
808
  if (ofile != NULL)
 
809
    *ofile = g_strdup_printf("%s/%s-%s.o",
 
810
                             gres->group->builddir,
 
811
                             ores->object->name,
 
812
                             prefix);
 
813
  if (cfile != NULL)
 
814
    *cfile = g_strdup_printf("%s/%s.c", gres->group->builddir, prefix);
 
815
  if (hfile != NULL)
 
816
    *hfile = g_strdup_printf("%s/%s.h", gres->group->builddir, prefix);
 
817
  if (phfile != NULL)
 
818
    *phfile = g_strdup_printf("%s/%s-private.h", gres->group->builddir, prefix);
 
819
 
 
820
  g_free(prefix);
 
821
}
 
822
 
 
823
static void
 
824
gob_class_build (JBResource *res)
 
825
{
 
826
  JBGobClass *self = JB_GOB_CLASS(res);
 
827
  char *ofile;
 
828
  char *cfile;
 
829
 
 
830
  gob_class_get_c_files(self, &ofile, &cfile, NULL, NULL);
 
831
 
 
832
  if (! object_file_is_uptodate(ofile, cfile))
 
833
    {
 
834
      JBObjectResource *ores = JB_OBJECT_RESOURCE(res);
 
835
      char *class_name;
 
836
 
 
837
      class_name = jb_strip_chars(self->name, ":");
 
838
      jb_message("building class %s", class_name);
 
839
      g_free(class_name);
 
840
 
 
841
      object_file_build(ores->object, ofile, cfile);
 
842
    }
 
843
 
 
844
  g_free(ofile);
 
845
  g_free(cfile);
 
846
}
 
847
 
 
848
static void
 
849
gob_class_makedist (JBResource *res)
 
850
{
 
851
  JBGobClass *self = JB_GOB_CLASS(res);
 
852
  char *gobfile;
 
853
  char *stamp;
 
854
  char *cfile;
 
855
  char *hfile;
 
856
  char *phfile;
 
857
 
 
858
  gob_class_get_gob_files(self, &gobfile, &stamp);
 
859
  gob_class_get_c_files(self, NULL, &cfile, &hfile, &phfile);
 
860
 
 
861
  jb_action_add_to_dist(gobfile);
 
862
  jb_action_add_to_dist(stamp);
 
863
  jb_action_add_to_dist(cfile);
 
864
  jb_action_add_to_dist(hfile);
 
865
  jb_action_add_to_dist(phfile);
 
866
 
 
867
  g_free(gobfile);
 
868
  g_free(stamp);
 
869
  g_free(cfile);
 
870
  g_free(hfile);
 
871
  g_free(phfile);
 
872
}
 
873
 
 
874
static void
 
875
gob_class_clean (JBResource *res)
 
876
{
 
877
  JBGobClass *self = JB_GOB_CLASS(res);
 
878
  char *ofile;
 
879
 
 
880
  gob_class_get_c_files(self, &ofile, NULL, NULL, NULL);
 
881
 
 
882
  object_file_clean(ofile);
 
883
 
 
884
  g_free(ofile);
 
885
}
 
886
 
 
887
static void
 
888
gob_class_maintainerclean (JBResource *res)
 
889
{
 
890
  JBGobClass *self = JB_GOB_CLASS(res);
 
891
  char *stamp;
 
892
  char *cfile;
 
893
  char *hfile;
 
894
  char *phfile;
 
895
 
 
896
  gob_class_get_gob_files(self, NULL, &stamp);
 
897
  gob_class_get_c_files(self, NULL, &cfile, &hfile, &phfile);
 
898
 
 
899
  jb_action_rm(stamp);
 
900
  jb_action_rm(cfile);
 
901
  jb_action_rm(hfile);
 
902
  jb_action_rm(phfile);
 
903
 
 
904
  g_free(stamp);
 
905
  g_free(cfile);
 
906
  g_free(hfile);
 
907
  g_free(phfile);
 
908
}
 
909
 
 
910
static char *
 
911
gob_class_get_object_file (JBObjectResource *res)
 
912
{
 
913
  JBGobClass *self = JB_GOB_CLASS(res);
 
914
  char *ofile;
 
915
 
 
916
  gob_class_get_c_files(self, &ofile, NULL, NULL, NULL);
 
917
 
 
918
  return ofile;
 
919
}
 
920
 
 
921
static void
 
922
jb_gob_class_init (JBGobClass *self)
 
923
{
 
924
}
 
925
 
 
926
static void
 
927
jb_gob_class_class_init (JBGobClassClass *class)
 
928
{
 
929
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
930
  JBObjectResourceClass *orclass = JB_OBJECT_RESOURCE_CLASS(class);
 
931
 
 
932
  rclass->pre_build = gob_class_pre_build;
 
933
  rclass->build = gob_class_build;
 
934
  rclass->makedist = gob_class_makedist;
 
935
  rclass->clean = gob_class_clean;
 
936
  rclass->maintainerclean = gob_class_maintainerclean;
 
937
 
 
938
  orclass->get_object_file = gob_class_get_object_file;
 
939
}
 
940
 
 
941
G_DEFINE_TYPE(JBDBusInterfaceClient, jb_dbus_interface_client, JB_TYPE_GROUP_RESOURCE)
 
942
 
 
943
JBDBusInterfaceClient *
 
944
jb_dbus_interface_client_new (const char *name, const char *client)
 
945
{
 
946
  JBDBusInterfaceClient *self;
 
947
 
 
948
  g_return_val_if_fail(name != NULL, NULL);
 
949
  g_return_val_if_fail(client != NULL, NULL);
 
950
  g_return_val_if_fail(jb_feature_is_enabled(&jb_dbus_feature), NULL);
 
951
 
 
952
  self = g_object_new(JB_TYPE_DBUS_INTERFACE_CLIENT, NULL);
 
953
  self->name = g_strdup(name);
 
954
  self->client = g_strdup(client);
 
955
 
 
956
  return self;
 
957
}
 
958
 
 
959
static char *
 
960
dbus_interface_client_to_string (JBResource *res)
 
961
{
 
962
  JBDBusInterfaceClient *self = JB_DBUS_INTERFACE_CLIENT(res);
 
963
 
 
964
  return g_strdup_printf("client of D-Bus interface %s", self->name);
 
965
}
 
966
 
 
967
static void
 
968
dbus_interface_client_get_files (JBDBusInterfaceClient *self,
 
969
                                 char **xmlfile,
 
970
                                 char **clientfile)
 
971
{
 
972
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
973
  char *cprefix;
 
974
 
 
975
  cprefix = jb_strdelimit(self->name, ".", '-');
 
976
  if (xmlfile != NULL)
 
977
    *xmlfile = g_strdup_printf("%s/%s.xml", gres->group->srcdir, cprefix);
 
978
  if (clientfile != NULL)
 
979
    *clientfile = g_strdup_printf("%s/%s", gres->group->builddir, self->client);
 
980
  g_free(cprefix);
 
981
}
 
982
 
 
983
static void
 
984
dbus_interface_client_pre_build (JBResource *res)
 
985
{
 
986
  JBDBusInterfaceClient *self = JB_DBUS_INTERFACE_CLIENT(res);
 
987
  char *xmlfile;
 
988
  char *clientfile;
 
989
 
 
990
  dbus_interface_client_get_files(self, &xmlfile, &clientfile);
 
991
 
 
992
  if (! jb_is_uptodate(clientfile, xmlfile))
 
993
    {
 
994
      JBGroupResource *gres = JB_GROUP_RESOURCE(res);
 
995
 
 
996
      resource_message_building(res);
 
997
 
 
998
      jb_mkdir(gres->group->builddir);
 
999
 
 
1000
      jb_action_exec("$dbus-binding-tool --mode=glib-client $xmlfile > $clientfile.tmp && mv -f $clientfile.tmp $clientfile",
 
1001
                     "xmlfile", xmlfile,
 
1002
                     "clientfile", clientfile,
 
1003
                     NULL);
 
1004
    }
 
1005
 
 
1006
  g_free(xmlfile);
 
1007
  g_free(clientfile);
 
1008
}
 
1009
 
 
1010
static void
 
1011
dbus_interface_client_makedist (JBResource *res)
 
1012
{
 
1013
  JBDBusInterfaceClient *self = JB_DBUS_INTERFACE_CLIENT(res);
 
1014
  char *xmlfile;
 
1015
 
 
1016
  dbus_interface_client_get_files(self, &xmlfile, NULL);
 
1017
 
 
1018
  jb_action_add_to_dist(xmlfile);
 
1019
 
 
1020
  g_free(xmlfile);
 
1021
}
 
1022
 
 
1023
static void
 
1024
dbus_interface_client_clean (JBResource *res)
 
1025
{
 
1026
  JBDBusInterfaceClient *self = JB_DBUS_INTERFACE_CLIENT(res);
 
1027
  char *clientfile;
 
1028
 
 
1029
  dbus_interface_client_get_files(self, NULL, &clientfile);
 
1030
 
 
1031
  jb_action_rm(clientfile);
 
1032
 
 
1033
  g_free(clientfile);
 
1034
}
 
1035
 
 
1036
static void
 
1037
jb_dbus_interface_client_init (JBDBusInterfaceClient *self)
 
1038
{
 
1039
}
 
1040
 
 
1041
static void
 
1042
jb_dbus_interface_client_class_init (JBDBusInterfaceClientClass *class)
 
1043
{
 
1044
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
1045
 
 
1046
  rclass->to_string = dbus_interface_client_to_string;
 
1047
  rclass->pre_build = dbus_interface_client_pre_build;
 
1048
  rclass->makedist = dbus_interface_client_makedist;
 
1049
  rclass->clean = dbus_interface_client_clean;
 
1050
}
 
1051
 
 
1052
G_DEFINE_TYPE(JBDBusInterfaceServer, jb_dbus_interface_server, JB_TYPE_GROUP_RESOURCE)
 
1053
 
 
1054
JBDBusInterfaceServer *
 
1055
jb_dbus_interface_server_new (const char *name,
 
1056
                              const char *server,
 
1057
                              const char *server_prefix)
 
1058
{
 
1059
  JBDBusInterfaceServer *self;
 
1060
 
 
1061
  g_return_val_if_fail(name != NULL, NULL);
 
1062
  g_return_val_if_fail(server != NULL, NULL);
 
1063
  g_return_val_if_fail(server_prefix != NULL, NULL);
 
1064
  g_return_val_if_fail(jb_feature_is_enabled(&jb_dbus_feature), NULL);
 
1065
 
 
1066
  self = g_object_new(JB_TYPE_DBUS_INTERFACE_SERVER, NULL);
 
1067
  self->name = g_strdup(name);
 
1068
  self->server = g_strdup(server);
 
1069
  self->server_prefix = g_strdup(server_prefix);
 
1070
 
 
1071
  return self;
 
1072
}
 
1073
 
 
1074
static char *
 
1075
dbus_interface_server_to_string (JBResource *res)
 
1076
{
 
1077
  JBDBusInterfaceServer *self = JB_DBUS_INTERFACE_SERVER(res);
 
1078
 
 
1079
  return g_strdup_printf("server of D-Bus interface %s", self->name);
 
1080
}
 
1081
 
 
1082
static void
 
1083
dbus_interface_server_get_files (JBDBusInterfaceServer *self,
 
1084
                                 char **xmlfile,
 
1085
                                 char **serverfile)
 
1086
{
 
1087
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1088
  char *cprefix;
 
1089
 
 
1090
  cprefix = jb_strdelimit(self->name, ".", '-');
 
1091
  if (xmlfile != NULL)
 
1092
    *xmlfile = g_strdup_printf("%s/%s.xml", gres->group->srcdir, cprefix);
 
1093
  if (serverfile != NULL)
 
1094
    *serverfile = g_strdup_printf("%s/%s", gres->group->builddir, self->server);
 
1095
  g_free(cprefix);
 
1096
}
 
1097
 
 
1098
static void
 
1099
dbus_interface_server_pre_build (JBResource *res)
 
1100
{
 
1101
  JBDBusInterfaceServer *self = JB_DBUS_INTERFACE_SERVER(res);
 
1102
  char *xmlfile;
 
1103
  char *serverfile;
 
1104
 
 
1105
  dbus_interface_server_get_files(self, &xmlfile, &serverfile);
 
1106
 
 
1107
  if (! jb_is_uptodate(serverfile, xmlfile))
 
1108
    {
 
1109
      JBGroupResource *gres = JB_GROUP_RESOURCE(res);
 
1110
 
 
1111
      resource_message_building(res);
 
1112
 
 
1113
      jb_mkdir(gres->group->builddir);
 
1114
 
 
1115
      jb_action_exec("$dbus-binding-tool --mode=glib-server --prefix=$server-prefix $xmlfile > $serverfile.tmp && mv -f $serverfile.tmp $serverfile",
 
1116
                     "server-prefix", self->server_prefix,
 
1117
                     "xmlfile", xmlfile,
 
1118
                     "serverfile", serverfile,
 
1119
                     NULL);
 
1120
    }
 
1121
 
 
1122
  g_free(xmlfile);
 
1123
  g_free(serverfile);
 
1124
}
 
1125
 
 
1126
static void
 
1127
dbus_interface_server_makedist (JBResource *res)
 
1128
{
 
1129
  JBDBusInterfaceServer *self = JB_DBUS_INTERFACE_SERVER(res);
 
1130
  char *xmlfile;
 
1131
 
 
1132
  dbus_interface_server_get_files(self, &xmlfile, NULL);
 
1133
 
 
1134
  jb_action_add_to_dist(xmlfile);
 
1135
 
 
1136
  g_free(xmlfile);
 
1137
}
 
1138
 
 
1139
static void
 
1140
dbus_interface_server_clean (JBResource *res)
 
1141
{
 
1142
  JBDBusInterfaceServer *self = JB_DBUS_INTERFACE_SERVER(res);
 
1143
  char *serverfile;
 
1144
 
 
1145
  dbus_interface_server_get_files(self, NULL, &serverfile);
 
1146
 
 
1147
  jb_action_rm(serverfile);
 
1148
 
 
1149
  g_free(serverfile);
 
1150
}
 
1151
 
 
1152
static void
 
1153
jb_dbus_interface_server_init (JBDBusInterfaceServer *self)
 
1154
{
 
1155
}
 
1156
 
 
1157
static void
 
1158
jb_dbus_interface_server_class_init (JBDBusInterfaceServerClass *class)
 
1159
{
 
1160
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
1161
 
 
1162
  rclass->to_string = dbus_interface_server_to_string;
 
1163
  rclass->pre_build = dbus_interface_server_pre_build;
 
1164
  rclass->makedist = dbus_interface_server_makedist;
 
1165
  rclass->clean = dbus_interface_server_clean;
 
1166
}
 
1167
 
 
1168
G_DEFINE_TYPE(JBIntltoolFile, jb_intltool_file, JB_TYPE_GROUP_RESOURCE)
 
1169
 
 
1170
JBIntltoolFile *
 
1171
jb_intltool_file_new (const char *type,
 
1172
                      const char *filename,
 
1173
                      const char *merge_flags)
 
1174
{
 
1175
  JBIntltoolFile *self;
 
1176
 
 
1177
  g_return_val_if_fail(type != NULL, NULL);
 
1178
  g_return_val_if_fail(filename != NULL, NULL);
 
1179
  g_return_val_if_fail(g_str_has_suffix(filename, ".in"), NULL);
 
1180
  g_return_val_if_fail(merge_flags != NULL, NULL);
 
1181
 
 
1182
  self = g_object_new(JB_TYPE_INTLTOOL_FILE, NULL);
 
1183
  self->type = g_strdup(type);
 
1184
  self->filename = g_strdup(filename);
 
1185
  self->merge_flags = g_strdup(merge_flags);
 
1186
 
 
1187
  return self;
 
1188
}
 
1189
 
 
1190
static char *
 
1191
intltool_file_to_string (JBResource *res)
 
1192
{
 
1193
  JBIntltoolFile *self = JB_INTLTOOL_FILE(res);
 
1194
 
 
1195
  return g_strdup_printf("%s %s", self->type, self->filename);
 
1196
}
 
1197
 
 
1198
static void
 
1199
intltool_file_get_files (JBIntltoolFile *self, char **infile, char **outfile)
 
1200
{
 
1201
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1202
  char *filename;
 
1203
 
 
1204
  filename = g_strdup_printf("%s/%s", gres->group->srcdir, self->filename);
 
1205
 
 
1206
  if (infile != NULL)
 
1207
    *infile = get_input_file(filename);
 
1208
  if (outfile != NULL)
 
1209
    *outfile = get_output_file(filename);
 
1210
 
 
1211
  g_free(filename);
 
1212
}
 
1213
 
 
1214
static void
 
1215
intltool_file_build (JBResource *res)
 
1216
{
 
1217
  JBIntltoolFile *self = JB_INTLTOOL_FILE(res);
 
1218
  char *infile;
 
1219
  char *outfile;
 
1220
  GSList *deps = NULL;
 
1221
 
 
1222
  if (! jb_is_uptodate(INTLTOOL_MERGE_OUT, INTLTOOL_MERGE_IN))
 
1223
    {
 
1224
      GHashTable *variables;
 
1225
 
 
1226
      jb_message("building intltool-merge");
 
1227
 
 
1228
      jb_mkdir_of_file(INTLTOOL_MERGE_OUT);
 
1229
 
 
1230
      variables = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
 
1231
      g_hash_table_insert(variables, "INTLTOOL_PERL", jb_variable_expand("$perl", NULL));
 
1232
      g_hash_table_insert(variables, "INTLTOOL_LIBDIR", jb_variable_expand("$perl", NULL));
 
1233
 
 
1234
      jb_subst(INTLTOOL_MERGE_IN, INTLTOOL_MERGE_OUT, variables);
 
1235
 
 
1236
      g_hash_table_destroy(variables);
 
1237
 
 
1238
      jb_chmod(INTLTOOL_MERGE_OUT, 0755);
 
1239
    }
 
1240
 
 
1241
  intltool_file_get_files(self, &infile, &outfile);
 
1242
 
 
1243
  deps = g_slist_append(deps, g_strdup(infile));
 
1244
  deps = g_slist_append(deps, g_strdup(INTLTOOL_MERGE_OUT));
 
1245
  deps = g_slist_concat(deps, jb_match_files("po/*.po"));
 
1246
 
 
1247
  if (! jb_is_uptodate_list(outfile, deps))
 
1248
    {
 
1249
      resource_message_building(res);
 
1250
 
 
1251
      jb_mkdir_of_file(outfile);
 
1252
      jb_mkdir_of_file(INTLTOOL_MERGE_CACHE);
 
1253
 
 
1254
      jb_action_exec("LC_ALL=C " INTLTOOL_MERGE_OUT " $merge-flags -u -c " INTLTOOL_MERGE_CACHE " po $infile $outfile",
 
1255
                     "merge-flags", self->merge_flags,
 
1256
                     "infile", infile,
 
1257
                     "outfile", outfile,
 
1258
                     NULL);
 
1259
    }
 
1260
 
 
1261
  g_free(infile);
 
1262
  g_free(outfile);
 
1263
  jb_g_slist_free_deep(deps);
 
1264
}
 
1265
 
 
1266
static void
 
1267
intltool_file_install (JBResource *res)
 
1268
{
 
1269
  JBIntltoolFile *self = JB_INTLTOOL_FILE(res);
 
1270
  char *outfile;
 
1271
 
 
1272
  intltool_file_get_files(self, NULL, &outfile);
 
1273
 
 
1274
  jb_install_options_install_data(&self->install_options, outfile, NULL);
 
1275
 
 
1276
  g_free(outfile);
 
1277
}
 
1278
 
 
1279
static void
 
1280
intltool_file_makedist (JBResource *res)
 
1281
{
 
1282
  JBIntltoolFile *self = JB_INTLTOOL_FILE(res);
 
1283
  JBGroupResource *gres = JB_GROUP_RESOURCE(res);
 
1284
  char *filename;
 
1285
 
 
1286
  filename = g_strdup_printf("%s/%s", gres->group->srcdir, self->filename);
 
1287
 
 
1288
  jb_action_add_to_dist(INTLTOOL_MERGE_IN);
 
1289
 
 
1290
  if (! has_template(filename))
 
1291
    jb_action_add_to_dist(filename);
 
1292
 
 
1293
  g_free(filename);
 
1294
}
 
1295
 
 
1296
static void
 
1297
intltool_file_clean (JBResource *res)
 
1298
{
 
1299
  JBIntltoolFile *self = JB_INTLTOOL_FILE(res);
 
1300
  char *outfile;
 
1301
 
 
1302
  intltool_file_get_files(self, NULL, &outfile);
 
1303
 
 
1304
  jb_action_rm(INTLTOOL_MERGE_OUT);
 
1305
  jb_action_rm(INTLTOOL_MERGE_CACHE);
 
1306
  jb_action_rm(outfile);
 
1307
 
 
1308
  g_free(outfile);
 
1309
}
 
1310
 
 
1311
static void
 
1312
intltool_file_maintainerclean (JBResource *res)
 
1313
{
 
1314
  jb_action_rm(INTLTOOL_MERGE_IN);
 
1315
}
 
1316
 
 
1317
static void
 
1318
jb_intltool_file_init (JBIntltoolFile *self)
 
1319
{
 
1320
  jb_install_options_init(&self->install_options);
 
1321
}
 
1322
 
 
1323
static void
 
1324
jb_intltool_file_class_init (JBIntltoolFileClass *class)
 
1325
{
 
1326
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
1327
 
 
1328
  rclass->to_string = intltool_file_to_string;
 
1329
  rclass->build = intltool_file_build;
 
1330
  rclass->install = intltool_file_install;
 
1331
  rclass->makedist = intltool_file_makedist;
 
1332
  rclass->clean = intltool_file_clean;
 
1333
  rclass->maintainerclean = intltool_file_maintainerclean;
 
1334
}
 
1335
 
 
1336
G_DEFINE_TYPE(JBGnomeHelp, jb_gnome_help, JB_TYPE_GROUP_RESOURCE)
 
1337
 
 
1338
JBGnomeHelp *
 
1339
jb_gnome_help_new (const char *lang, const char *entities)
 
1340
{
 
1341
  JBGnomeHelp *self;
 
1342
 
 
1343
  g_return_val_if_fail(lang != NULL, NULL);
 
1344
  g_return_val_if_fail(jb_feature_is_enabled(&jb_gnome_help_feature), NULL);
 
1345
 
 
1346
  self = g_object_new(JB_TYPE_GNOME_HELP, NULL);
 
1347
  self->name = g_strdup(jb_variable_get_string("package"));
 
1348
  self->lang = g_strdup(lang);
 
1349
  self->entities = g_strsplit(entities != NULL ? entities : "", " ", 0);
 
1350
 
 
1351
  return self;
 
1352
}
 
1353
 
 
1354
static char *
 
1355
gnome_help_to_string (JBResource *res)
 
1356
{
 
1357
  JBGnomeHelp *self = JB_GNOME_HELP(res);
 
1358
 
 
1359
  return g_strdup_printf("GNOME help %s [%s]", self->name, self->lang);
 
1360
}
 
1361
 
 
1362
static void
 
1363
gnome_help_get_files (JBGnomeHelp *self,
 
1364
                      char **inomf,
 
1365
                      char **outomf,
 
1366
                      char **helpdir,
 
1367
                      char **xmlfile,
 
1368
                      GSList **entities,
 
1369
                      GSList **figures)
 
1370
{
 
1371
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1372
  char *_inomf;
 
1373
 
 
1374
  _inomf = g_strdup_printf("%s/%s/%s-%s.omf.in",
 
1375
                           gres->group->srcdir,
 
1376
                           self->lang,
 
1377
                           self->name,
 
1378
                           self->lang);
 
1379
 
 
1380
  if (inomf != NULL)
 
1381
    *inomf = g_strdup(_inomf);
 
1382
  if (outomf != NULL)
 
1383
    *outomf = get_output_file(_inomf);
 
1384
  if (helpdir != NULL)
 
1385
    *helpdir = jb_variable_expand("$help-dir/$name/$lang",
 
1386
                                  "name", self->name,
 
1387
                                  "lang", self->lang,
 
1388
                                  NULL);
 
1389
  if (xmlfile != NULL)
 
1390
    *xmlfile = g_strdup_printf("%s/%s/%s.xml",
 
1391
                               gres->group->srcdir,
 
1392
                               self->lang,
 
1393
                               self->name);
 
1394
  if (entities != NULL)
 
1395
    {
 
1396
      int i;
 
1397
      GSList *list = NULL;
 
1398
 
 
1399
      for (i = 0; self->entities[i] != NULL; i++)
 
1400
        list = g_slist_append(list, g_strdup_printf("%s/%s/%s",
 
1401
                                                    gres->group->srcdir,
 
1402
                                                    self->lang,
 
1403
                                                    self->entities[i]));
 
1404
 
 
1405
      *entities = list;
 
1406
    }
 
1407
  if (figures != NULL)
 
1408
    {
 
1409
      char *pattern;
 
1410
 
 
1411
      pattern = g_strdup_printf("%s/%s/figures/*.png",
 
1412
                                gres->group->srcdir,
 
1413
                                self->lang);
 
1414
      *figures = jb_match_files(pattern);
 
1415
      g_free(pattern);
 
1416
    }
 
1417
 
 
1418
  g_free(_inomf);
 
1419
}
 
1420
 
 
1421
static void
 
1422
gnome_help_build (JBResource *res)
 
1423
{
 
1424
  JBGnomeHelp *self = JB_GNOME_HELP(res);
 
1425
  char *inomf;
 
1426
  char *outomf;
 
1427
  char *helpdir;
 
1428
 
 
1429
  gnome_help_get_files(self, &inomf, &outomf, &helpdir, NULL, NULL, NULL);
 
1430
 
 
1431
  if (! jb_is_uptodate(outomf, inomf))
 
1432
    {
 
1433
      resource_message_building(res);
 
1434
 
 
1435
      jb_mkdir_of_file(outomf);
 
1436
 
 
1437
      jb_action_exec("$scrollkeeper-preinstall \"$helpdir/$helpname.xml\" $inomf $outomf",
 
1438
                     "helpdir", helpdir,
 
1439
                     "helpname", self->name,
 
1440
                     "inomf", inomf,
 
1441
                     "outomf", outomf,
 
1442
                     NULL);
 
1443
    }
 
1444
 
 
1445
  g_free(inomf);
 
1446
  g_free(outomf);
 
1447
  g_free(helpdir);
 
1448
}
 
1449
 
 
1450
static void
 
1451
gnome_help_install (JBResource *res)
 
1452
{
 
1453
  JBGnomeHelp *self = JB_GNOME_HELP(res);
 
1454
  char *outomf;
 
1455
  char *helpdir;
 
1456
  char *omfdir;
 
1457
  char *xmlfile;
 
1458
  GSList *entities;
 
1459
  GSList *figures;
 
1460
  char *figdir;
 
1461
 
 
1462
  gnome_help_get_files(self, NULL, &outomf, &helpdir, &xmlfile, &entities, &figures);
 
1463
 
 
1464
  omfdir = g_strdup_printf("$omf-dir/%s", self->name);
 
1465
 
 
1466
  figdir = g_strdup_printf("%s/figures", helpdir);
 
1467
 
 
1468
  jb_action_install_data(xmlfile, helpdir);
 
1469
 
 
1470
  jb_action_install_data_list(entities, helpdir);
 
1471
 
 
1472
  jb_action_install_data_list(figures, figdir);
 
1473
 
 
1474
  jb_action_install_data(outomf, omfdir);
 
1475
 
 
1476
  jb_action_exec("-$scrollkeeper-update -p \"$destdir$scrollkeeper-dir\" -o \"$destdir$omfdir\"",
 
1477
                 "omfdir", omfdir,
 
1478
                 NULL);
 
1479
 
 
1480
  g_free(outomf);
 
1481
  g_free(helpdir);
 
1482
  g_free(omfdir);
 
1483
  g_free(xmlfile);
 
1484
  jb_g_slist_free_deep(entities);
 
1485
  jb_g_slist_free_deep(figures);
 
1486
  g_free(figdir);
 
1487
}
 
1488
 
 
1489
static void
 
1490
gnome_help_makedist (JBResource *res)
 
1491
{
 
1492
  JBGnomeHelp *self = JB_GNOME_HELP(res);
 
1493
  char *inomf;
 
1494
  char *xmlfile;
 
1495
  GSList *entities;
 
1496
  GSList *figures;
 
1497
 
 
1498
  gnome_help_get_files(self, &inomf, NULL, NULL, &xmlfile, &entities, &figures);
 
1499
 
 
1500
  jb_action_add_to_dist(inomf);
 
1501
  jb_action_add_to_dist(xmlfile);
 
1502
  jb_action_add_to_dist_list(entities);
 
1503
  jb_action_add_to_dist_list(figures);
 
1504
 
 
1505
  g_free(inomf);
 
1506
  g_free(xmlfile);
 
1507
  jb_g_slist_free_deep(entities);
 
1508
  jb_g_slist_free_deep(figures);
 
1509
}
 
1510
 
 
1511
static void
 
1512
gnome_help_clean (JBResource *res)
 
1513
{
 
1514
  JBGnomeHelp *self = JB_GNOME_HELP(res);
 
1515
  char *outomf;
 
1516
 
 
1517
  gnome_help_get_files(self, NULL, &outomf, NULL, NULL, NULL, NULL);
 
1518
 
 
1519
  jb_action_rm(outomf);
 
1520
 
 
1521
  g_free(outomf);
 
1522
}
 
1523
 
 
1524
static void
 
1525
jb_gnome_help_init (JBGnomeHelp *self)
 
1526
{
 
1527
}
 
1528
 
 
1529
static void
 
1530
jb_gnome_help_class_init (JBGnomeHelpClass *class)
 
1531
{
 
1532
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
1533
 
 
1534
  rclass->to_string = gnome_help_to_string;
 
1535
  rclass->build = gnome_help_build;
 
1536
  rclass->install = gnome_help_install;
 
1537
  rclass->makedist = gnome_help_makedist;
 
1538
  rclass->clean = gnome_help_clean;
 
1539
}
 
1540
 
 
1541
G_DEFINE_TYPE(JBTranslations, jb_translations, JB_TYPE_GROUP_RESOURCE)
 
1542
 
 
1543
static void
 
1544
translations_get_files (JBTranslations *self, char **infile, char **outfile)
 
1545
{
 
1546
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1547
 
 
1548
  if (infile != NULL)
 
1549
    *infile = g_strdup_printf("%s/%s.po", gres->group->srcdir, self->lang);
 
1550
  if (outfile != NULL)
 
1551
    *outfile = g_strdup_printf("%s/%s.mo", gres->group->builddir, self->lang);
 
1552
}
 
1553
 
 
1554
JBTranslations *
 
1555
jb_translations_new (const char *lang)
 
1556
{
 
1557
  JBTranslations *self;
 
1558
 
 
1559
  g_return_val_if_fail(lang != NULL, NULL);
 
1560
  g_return_val_if_fail(jb_feature_is_enabled(&jb_gettext_feature), NULL);
 
1561
 
 
1562
  self = g_object_new(JB_TYPE_TRANSLATIONS, NULL);
 
1563
  self->lang = g_strdup(lang);
 
1564
 
 
1565
  return self;
 
1566
}
 
1567
 
 
1568
static char *
 
1569
translations_to_string (JBResource *res)
 
1570
{
 
1571
  JBTranslations *self = JB_TRANSLATIONS(res);
 
1572
 
 
1573
  return g_strdup_printf("%s translations", self->lang);
 
1574
}
 
1575
 
 
1576
static void
 
1577
translations_build (JBResource *res)
 
1578
{
 
1579
  JBTranslations *self = JB_TRANSLATIONS(res);
 
1580
  char *infile;
 
1581
  char *outfile;
 
1582
 
 
1583
  translations_get_files(self, &infile, &outfile);
 
1584
 
 
1585
  if (! jb_is_uptodate(outfile, infile))
 
1586
    {
 
1587
      resource_message_building(res);
 
1588
 
 
1589
      jb_mkdir_of_file(outfile);
 
1590
 
 
1591
      jb_action_exec("$msgfmt -o $outfile.tmp $infile && mv -f $outfile.tmp $outfile",
 
1592
                     "outfile", outfile,
 
1593
                     "infile", infile,
 
1594
                     NULL);
 
1595
    }
 
1596
 
 
1597
  g_free(infile);
 
1598
  g_free(outfile);
 
1599
}
 
1600
 
 
1601
static void
 
1602
translations_install (JBResource *res)
 
1603
{
 
1604
  JBTranslations *self = JB_TRANSLATIONS(res);
 
1605
  char *outfile;
 
1606
  char *installfile;
 
1607
 
 
1608
  translations_get_files(self, NULL, &outfile);
 
1609
 
 
1610
  installfile = g_strdup_printf("$prefix/share/locale/%s/LC_MESSAGES/$package.mo", self->lang);
 
1611
 
 
1612
  jb_action_install_data_to_file(outfile, installfile);
 
1613
 
 
1614
  g_free(outfile);
 
1615
  g_free(installfile);
 
1616
}
 
1617
 
 
1618
static void
 
1619
translations_makedist (JBResource *res)
 
1620
{
 
1621
  JBTranslations *self = JB_TRANSLATIONS(res);
 
1622
  char *infile;
 
1623
 
 
1624
  translations_get_files(self, &infile, NULL);
 
1625
 
 
1626
  jb_action_add_to_dist(infile);
 
1627
 
 
1628
  g_free(infile);
 
1629
}
 
1630
 
 
1631
static void
 
1632
translations_clean (JBResource *res)
 
1633
{
 
1634
  JBTranslations *self = JB_TRANSLATIONS(res);
 
1635
  char *outfile;
 
1636
 
 
1637
  translations_get_files(self, NULL, &outfile);
 
1638
 
 
1639
  jb_action_rm(outfile);
 
1640
 
 
1641
  g_free(outfile);
 
1642
}
 
1643
 
 
1644
static void
 
1645
jb_translations_init (JBTranslations *self)
 
1646
{
 
1647
}
 
1648
 
 
1649
static void
 
1650
jb_translations_class_init (JBTranslationsClass *class)
 
1651
{
 
1652
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
1653
 
 
1654
  rclass->to_string = translations_to_string;
 
1655
  rclass->build = translations_build;
 
1656
  rclass->install = translations_install;
 
1657
  rclass->makedist = translations_makedist;
 
1658
  rclass->clean = translations_clean;
 
1659
}
 
1660
 
 
1661
G_DEFINE_TYPE(JBRule, jb_rule, JB_TYPE_GROUP_RESOURCE)
 
1662
 
 
1663
JBRule *
 
1664
jb_rule_new (void)
 
1665
{
 
1666
  return g_object_new(JB_TYPE_RULE, NULL);
 
1667
}
 
1668
 
 
1669
/*
 
1670
 * This could be inferred by mapping input files to the resources that
 
1671
 * produce them, but it would require a more complex JBResource
 
1672
 * design. For now this is good enough.
 
1673
 */
 
1674
void
 
1675
jb_rule_add_dependency (JBRule *self, JBGroupResource *res)
 
1676
{
 
1677
  g_return_if_fail(JB_IS_RULE(self));
 
1678
  g_return_if_fail(JB_IS_GROUP_RESOURCE(res));
 
1679
 
 
1680
  self->dependencies = g_slist_append(self->dependencies, g_object_ref(res));
 
1681
}
 
1682
 
 
1683
void
 
1684
jb_rule_add_input_file (JBRule *self, const char *format, ...)
 
1685
{
 
1686
  va_list args;
 
1687
 
 
1688
  g_return_if_fail(JB_IS_RULE(self));
 
1689
  g_return_if_fail(format != NULL);
 
1690
 
 
1691
  va_start(args, format);
 
1692
  self->input_files = g_slist_append(self->input_files, g_strdup_vprintf(format, args));
 
1693
  va_end(args);
 
1694
}
 
1695
 
 
1696
void
 
1697
jb_rule_add_output_file (JBRule *self, const char *format, ...)
 
1698
{
 
1699
  va_list args;
 
1700
 
 
1701
  g_return_if_fail(JB_IS_RULE(self));
 
1702
  g_return_if_fail(format != NULL);
 
1703
 
 
1704
  va_start(args, format);
 
1705
  self->output_files = g_slist_append(self->output_files, g_strdup_vprintf(format, args));
 
1706
  va_end(args);
 
1707
}
 
1708
 
 
1709
void
 
1710
jb_rule_set_build_message (JBRule *self, const char *format, ...)
 
1711
{
 
1712
  va_list args;
 
1713
 
 
1714
  g_return_if_fail(JB_IS_RULE(self));
 
1715
  g_return_if_fail(format != NULL);
 
1716
 
 
1717
  g_free(self->build_message);
 
1718
 
 
1719
  va_start(args, format);
 
1720
  self->build_message = g_strdup_vprintf(format, args);
 
1721
  va_end(args);
 
1722
}
 
1723
 
 
1724
void
 
1725
jb_rule_add_build_command (JBRule *self, const char *format, ...)
 
1726
{
 
1727
  va_list args;
 
1728
 
 
1729
  g_return_if_fail(JB_IS_RULE(self));
 
1730
  g_return_if_fail(format != NULL);
 
1731
 
 
1732
  va_start(args, format);
 
1733
  self->build_commands = g_slist_append(self->build_commands, g_strdup_vprintf(format, args));
 
1734
  va_end(args);
 
1735
}
 
1736
 
 
1737
void
 
1738
jb_rule_set_install_message (JBRule *self, const char *format, ...)
 
1739
{
 
1740
  va_list args;
 
1741
 
 
1742
  g_return_if_fail(JB_IS_RULE(self));
 
1743
  g_return_if_fail(format != NULL);
 
1744
 
 
1745
  g_free(self->install_message);
 
1746
 
 
1747
  va_start(args, format);
 
1748
  self->install_message = g_strdup_vprintf(format, args);
 
1749
  va_end(args);
 
1750
}
 
1751
 
 
1752
void
 
1753
jb_rule_add_install_command (JBRule *self, const char *format, ...)
 
1754
{
 
1755
  va_list args;
 
1756
 
 
1757
  g_return_if_fail(JB_IS_RULE(self));
 
1758
  g_return_if_fail(format != NULL);
 
1759
 
 
1760
  va_start(args, format);
 
1761
  self->install_commands = g_slist_append(self->install_commands, g_strdup_vprintf(format, args));
 
1762
  va_end(args);
 
1763
}
 
1764
 
 
1765
static GSList *
 
1766
rule_expand_variables (JBRule *self, GSList *strings)
 
1767
{
 
1768
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1769
  GSList *result = NULL;
 
1770
  GSList *l;
 
1771
 
 
1772
  JB_LIST_FOREACH(l, strings)
 
1773
    {
 
1774
      const char *str = l->data;
 
1775
      char *expanded;
 
1776
 
 
1777
      expanded = jb_variable_expand(str,
 
1778
                                    "srcdir", gres->group->srcdir,
 
1779
                                    "builddir", gres->group->builddir,
 
1780
                                    NULL);
 
1781
 
 
1782
      result = g_slist_append(result, expanded);
 
1783
    }
 
1784
 
 
1785
  return result;
 
1786
}
 
1787
 
 
1788
static void
 
1789
rule_perform (JBRule *self, const char *message, GSList *commands)
 
1790
{
 
1791
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1792
  GSList *l;
 
1793
 
 
1794
  if (commands == NULL)
 
1795
    return;
 
1796
 
 
1797
  jb_message("%s", message);
 
1798
 
 
1799
  JB_LIST_FOREACH(l, commands)
 
1800
    {
 
1801
      const char *command = l->data;
 
1802
 
 
1803
      jb_action_exec(command,
 
1804
                     "srcdir", gres->group->srcdir,
 
1805
                     "builddir", gres->group->builddir,
 
1806
                     NULL);
 
1807
    }
 
1808
}
 
1809
 
 
1810
static void
 
1811
rule_build (JBResource *res)
 
1812
{
 
1813
  JBRule *self = JB_RULE(res);
 
1814
  GSList *l;
 
1815
 
 
1816
  JB_LIST_FOREACH(l, self->dependencies)
 
1817
    {
 
1818
      JBResource *dep = l->data;
 
1819
      jb_resource_build(dep);
 
1820
    }
 
1821
 
 
1822
  if (self->output_files != NULL)
 
1823
    {
 
1824
      GSList *input_files;
 
1825
      GSList *output_files;
 
1826
      gboolean is_uptodate;
 
1827
 
 
1828
      input_files = rule_expand_variables(self, self->input_files);
 
1829
      output_files = rule_expand_variables(self, self->output_files);
 
1830
 
 
1831
      is_uptodate = jb_is_uptodate_list_list(output_files, input_files);
 
1832
 
 
1833
      jb_g_slist_free_deep(input_files);
 
1834
      jb_g_slist_free_deep(output_files);
 
1835
 
 
1836
      if (is_uptodate)
 
1837
        return;
 
1838
    }
 
1839
 
 
1840
  rule_perform(self, self->build_message, self->build_commands);
 
1841
}
 
1842
 
 
1843
static void
 
1844
rule_install (JBResource *res)
 
1845
{
 
1846
  JBRule *self = JB_RULE(res);
 
1847
 
 
1848
  rule_perform(self, self->install_message, self->install_commands);
 
1849
}
 
1850
 
 
1851
static void
 
1852
rule_clean (JBResource *res)
 
1853
{
 
1854
  JBRule *self = JB_RULE(res);
 
1855
  GSList *output_files;
 
1856
 
 
1857
  output_files = rule_expand_variables(self, self->output_files);
 
1858
 
 
1859
  jb_action_rm_list(output_files);
 
1860
 
 
1861
  jb_g_slist_free_deep(output_files);
 
1862
}
 
1863
 
 
1864
static void
 
1865
jb_rule_init (JBRule *self)
 
1866
{
 
1867
}
 
1868
 
 
1869
static void
 
1870
jb_rule_class_init (JBRuleClass *class)
 
1871
{
 
1872
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
1873
 
 
1874
  rclass->build = rule_build;
 
1875
  rclass->install = rule_install;
 
1876
  rclass->clean = rule_clean;
 
1877
}
 
1878
 
 
1879
G_DEFINE_ABSTRACT_TYPE(JBObject, jb_object, JB_TYPE_GROUP_RESOURCE)
 
1880
 
 
1881
static char *
 
1882
object_to_string (JBResource *res)
 
1883
{
 
1884
  JBObject *self = JB_OBJECT(res);
 
1885
  JBObjectClass *class = JB_OBJECT_GET_CLASS(self);
 
1886
 
 
1887
  return g_strdup_printf("%s %s", class->type, self->name);
 
1888
}
 
1889
 
 
1890
static char *
 
1891
object_get_output_file (JBObject *self)
 
1892
{
 
1893
  JBObjectClass *class;
 
1894
 
 
1895
  g_return_val_if_fail(JB_IS_OBJECT(self), NULL);
 
1896
 
 
1897
  class = JB_OBJECT_GET_CLASS(self);
 
1898
 
 
1899
  if (class->get_output_file != NULL)
 
1900
    return class->get_output_file(self);
 
1901
  else
 
1902
    {
 
1903
      g_error("get_output_file() not implemented for object type %s", G_OBJECT_TYPE_NAME(self));
 
1904
      return NULL;
 
1905
    }
 
1906
}
 
1907
 
 
1908
static GSList *
 
1909
object_get_object_files (JBObject *self)
 
1910
{
 
1911
  GSList *list = NULL;
 
1912
  GSList *l;
 
1913
 
 
1914
  JB_LIST_FOREACH(l, self->resources)
 
1915
    list = g_slist_append(list, object_resource_get_object_file(l->data));
 
1916
 
 
1917
  return list;
 
1918
}
 
1919
 
 
1920
static GSList *
 
1921
object_get_headers (JBObject *self)
 
1922
{
 
1923
  JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1924
  GSList *list = NULL;
 
1925
  GSList *l;
 
1926
 
 
1927
  JB_LIST_FOREACH(l, self->headers)
 
1928
    {
 
1929
      const char *header = l->data;
 
1930
 
 
1931
      list = g_slist_append(list, g_strdup_printf("%s/%s",
 
1932
                                                  gres->group->srcdir,
 
1933
                                                  header));
 
1934
    }
 
1935
 
 
1936
  return list;
 
1937
}
 
1938
 
 
1939
static void
 
1940
object_pre_build (JBResource *res)
 
1941
{
 
1942
  JBObject *self = JB_OBJECT(res);
 
1943
  GSList *l;
 
1944
 
 
1945
  JB_LIST_FOREACH(l, self->resources)
 
1946
    jb_resource_pre_build(l->data);
 
1947
}
 
1948
 
 
1949
static void
 
1950
object_build (JBResource *res)
 
1951
{
 
1952
  JBObject *self = JB_OBJECT(res);
 
1953
  char *outfile;
 
1954
  GSList *object_files_list;
 
1955
  GSList *l;
 
1956
 
 
1957
  JB_LIST_FOREACH(l, self->resources)
 
1958
    jb_resource_build(l->data);
 
1959
 
 
1960
  outfile = object_get_output_file(self);
 
1961
  object_files_list = object_get_object_files(self);
 
1962
 
 
1963
  if (! jb_is_uptodate_list(outfile, object_files_list))
 
1964
    {
 
1965
      JBGroupResource *gres = JB_GROUP_RESOURCE(self);
 
1966
      JBObjectClass *object_class;
 
1967
      char *object_files;
 
1968
 
 
1969
      resource_message_building(res);
 
1970
 
 
1971
      object_class = JB_OBJECT_GET_CLASS(self);
 
1972
 
 
1973
      object_files = jb_string_list_join(object_files_list, " ");
 
1974
 
 
1975
      jb_mkdir(gres->group->builddir);
 
1976
 
 
1977
      jb_action_exec("$cc $package-cflags $group-cflags $object-cflags $cflags"
 
1978
                     " $package-ldflags $group-ldflags $object-ldflags $stock-ldflags $ldflags"
 
1979
                     " -o $outfile $object-files",
 
1980
                     "package-cflags", jb_compile_options.cflags->str,
 
1981
                     "group-cflags", gres->group->compile_options.cflags->str,
 
1982
                     "object-cflags", self->compile_options.cflags->str,
 
1983
                     "package-ldflags", jb_compile_options.ldflags->str,
 
1984
                     "group-ldflags", gres->group->compile_options.ldflags->str,
 
1985
                     "object-ldflags", self->compile_options.ldflags->str,
 
1986
                     "stock-ldflags", object_class->stock_ldflags,
 
1987
                     "outfile", outfile,
 
1988
                     "object-files", object_files,
 
1989
                     NULL);
 
1990
 
 
1991
      g_free(object_files);
 
1992
    }
 
1993
 
 
1994
  g_free(outfile);
 
1995
  jb_g_slist_free_deep(object_files_list);
 
1996
}
 
1997
 
 
1998
static void
 
1999
object_makedist (JBResource *res)
 
2000
{
 
2001
  JBObject *self = JB_OBJECT(res);
 
2002
  GSList *l;
 
2003
  GSList *headers;
 
2004
 
 
2005
  JB_LIST_FOREACH(l, self->resources)
 
2006
    jb_resource_makedist(l->data);
 
2007
 
 
2008
  headers = object_get_headers(self);
 
2009
  jb_action_add_to_dist_list(headers);
 
2010
  jb_g_slist_free_deep(headers);
 
2011
}
 
2012
 
 
2013
static void
 
2014
object_clean (JBResource *res)
 
2015
{
 
2016
  JBObject *self = JB_OBJECT(res);
 
2017
  GSList *l;
 
2018
  char *outfile;
 
2019
 
 
2020
  JB_LIST_FOREACH(l, self->resources)
 
2021
    jb_resource_clean(l->data);
 
2022
 
 
2023
  outfile = object_get_output_file(self);
 
2024
 
 
2025
  jb_action_rm(outfile);
 
2026
 
 
2027
  g_free(outfile);
 
2028
}
 
2029
 
 
2030
static void
 
2031
object_distclean (JBResource *res)
 
2032
{
 
2033
  JBObject *self = JB_OBJECT(res);
 
2034
  GSList *l;
 
2035
 
 
2036
  JB_LIST_FOREACH(l, self->resources)
 
2037
    jb_resource_distclean(l->data);
 
2038
}
 
2039
 
 
2040
static void
 
2041
object_maintainerclean (JBResource *res)
 
2042
{
 
2043
  JBObject *self = JB_OBJECT(res);
 
2044
  GSList *l;
 
2045
 
 
2046
  JB_LIST_FOREACH(l, self->resources)
 
2047
    jb_resource_maintainerclean(l->data);
 
2048
}
 
2049
 
 
2050
static void
 
2051
object_add_resource (JBObject *self, JBObjectResource *res)
 
2052
{
 
2053
  g_return_if_fail(JB_IS_OBJECT(self));
 
2054
  g_return_if_fail(JB_IS_OBJECT_RESOURCE(res));
 
2055
  g_return_if_fail(res->object == NULL);
 
2056
 
 
2057
  res->object = self;
 
2058
 
 
2059
  self->resources = g_slist_append(self->resources, res);
 
2060
}
 
2061
 
 
2062
static void
 
2063
object_add_header (JBObject *self, const char *filename)
 
2064
{
 
2065
  g_return_if_fail(JB_IS_OBJECT(self));
 
2066
  g_return_if_fail(filename != NULL);
 
2067
 
 
2068
  self->headers = g_slist_append(self->headers, g_strdup(filename));
 
2069
}
 
2070
 
 
2071
void
 
2072
jb_object_add_source (JBObject *self, const char *name)
 
2073
{
 
2074
  g_return_if_fail(JB_IS_OBJECT(self));
 
2075
  g_return_if_fail(name != NULL);
 
2076
 
 
2077
  if (strchr(name, ':') != NULL)
 
2078
    object_add_resource(self, JB_OBJECT_RESOURCE(jb_gob_class_new(name)));
 
2079
  else if (strchr(name, '.') == NULL)
 
2080
    {
 
2081
      char *cfile;
 
2082
      char *hfile;
 
2083
 
 
2084
      cfile = g_strdup_printf("%s.c", name);
 
2085
      hfile = g_strdup_printf("%s.h", name);
 
2086
 
 
2087
      object_add_resource(self, JB_OBJECT_RESOURCE(jb_source_new(cfile)));
 
2088
      object_add_header(self, hfile);
 
2089
 
 
2090
      g_free(cfile);
 
2091
      g_free(hfile);
 
2092
    }
 
2093
  else
 
2094
    {
 
2095
      if (g_str_has_suffix(name, ".c"))
 
2096
        object_add_resource(self, JB_OBJECT_RESOURCE(jb_source_new(name)));
 
2097
      else if (g_str_has_suffix(name, ".h"))
 
2098
        object_add_header(self, name);
 
2099
      else
 
2100
        g_error("the extension of source file \"%s\" is not .c or .h", name);
 
2101
    }
 
2102
}
 
2103
 
 
2104
void
 
2105
jb_object_add_sources (JBObject *self, const char *name, ...)
 
2106
{
 
2107
  va_list args;
 
2108
 
 
2109
  g_return_if_fail(JB_IS_OBJECT(self));
 
2110
 
 
2111
  va_start(args, name);
 
2112
 
 
2113
  while (name != NULL)
 
2114
    {
 
2115
      jb_object_add_source(self, name);
 
2116
      name = va_arg(args, const char *);
 
2117
    }
 
2118
 
 
2119
  va_end(args);
 
2120
}
 
2121
 
 
2122
static void
 
2123
jb_object_init (JBObject *self)
 
2124
{
 
2125
  jb_compile_options_init(&self->compile_options);
 
2126
  jb_install_options_init(&self->install_options);
 
2127
}
 
2128
 
 
2129
static void
 
2130
jb_object_class_init (JBObjectClass *class)
 
2131
{
 
2132
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
2133
 
 
2134
  rclass->to_string = object_to_string;
 
2135
  rclass->pre_build = object_pre_build;
 
2136
  rclass->build = object_build;
 
2137
  rclass->makedist = object_makedist;
 
2138
  rclass->clean = object_clean;
 
2139
  rclass->distclean = object_distclean;
 
2140
  rclass->maintainerclean = object_maintainerclean;
 
2141
}
 
2142
 
 
2143
G_DEFINE_TYPE(JBProgram, jb_program, JB_TYPE_OBJECT)
 
2144
 
 
2145
JBProgram *
 
2146
jb_program_new (const char *name)
 
2147
{
 
2148
  JBProgram *self;
 
2149
 
 
2150
  g_return_val_if_fail(name != NULL, NULL);
 
2151
 
 
2152
  self = g_object_new(JB_TYPE_PROGRAM, NULL);
 
2153
  JB_OBJECT(self)->name = g_strdup(name);
 
2154
 
 
2155
  return self;
 
2156
}
 
2157
 
 
2158
static void
 
2159
program_install (JBResource *res)
 
2160
{
 
2161
  JBObject *object = JB_OBJECT(res);
 
2162
  char *outfile;
 
2163
 
 
2164
  outfile = object_get_output_file(object);
 
2165
 
 
2166
  jb_install_options_install_program(&object->install_options, outfile, NULL);
 
2167
 
 
2168
  g_free(outfile);
 
2169
}
 
2170
 
 
2171
static char *
 
2172
program_get_output_file (JBObject *object)
 
2173
{
 
2174
  JBGroupResource *gres = JB_GROUP_RESOURCE(object);
 
2175
 
 
2176
  return g_strdup_printf("%s/%s", gres->group->builddir, object->name);
 
2177
}
 
2178
 
 
2179
static void
 
2180
jb_program_init (JBProgram *self)
 
2181
{
 
2182
  JBObject *object = JB_OBJECT(self);
 
2183
 
 
2184
  jb_install_options_set_installdir(&object->install_options, "$bindir");
 
2185
}
 
2186
 
 
2187
static void
 
2188
jb_program_class_init (JBProgramClass *class)
 
2189
{
 
2190
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
2191
  JBObjectClass *oclass = JB_OBJECT_CLASS(class);
 
2192
 
 
2193
  rclass->install = program_install;
 
2194
 
 
2195
  oclass->type = "program";
 
2196
  oclass->get_output_file = program_get_output_file;
 
2197
}
 
2198
 
 
2199
G_DEFINE_TYPE(JBModule, jb_module, JB_TYPE_OBJECT)
 
2200
 
 
2201
JBModule *
 
2202
jb_module_new (const char *name)
 
2203
{
 
2204
  JBModule *self;
 
2205
 
 
2206
  g_return_val_if_fail(name != NULL, NULL);
 
2207
 
 
2208
  self = g_object_new(JB_TYPE_MODULE, NULL);
 
2209
  JB_OBJECT(self)->name = g_strdup(name);
 
2210
 
 
2211
  return self;
 
2212
}
 
2213
 
 
2214
static void
 
2215
module_install (JBResource *res)
 
2216
{
 
2217
  JBObject *object = JB_OBJECT(res);
 
2218
  char *outfile;
 
2219
 
 
2220
  outfile = object_get_output_file(object);
 
2221
 
 
2222
  jb_install_options_install_library(&object->install_options, outfile, NULL);
 
2223
 
 
2224
  g_free(outfile);
 
2225
}
 
2226
 
 
2227
static char *
 
2228
module_get_output_file (JBObject *object)
 
2229
{
 
2230
  JBGroupResource *gres = JB_GROUP_RESOURCE(object);
 
2231
 
 
2232
  return g_strdup_printf("%s/%s.so", gres->group->builddir, object->name);
 
2233
}
 
2234
 
 
2235
static void
 
2236
jb_module_init (JBModule *self)
 
2237
{
 
2238
  JBObject *object = JB_OBJECT(self);
 
2239
 
 
2240
  jb_install_options_set_installdir(&object->install_options, "$pkglibdir");
 
2241
}
 
2242
 
 
2243
static void
 
2244
jb_module_class_init (JBModuleClass *class)
 
2245
{
 
2246
  JBResourceClass *rclass = JB_RESOURCE_CLASS(class);
 
2247
  JBObjectClass *oclass = JB_OBJECT_CLASS(class);
 
2248
 
 
2249
  rclass->install = module_install;
 
2250
 
 
2251
  oclass->type = "module";
 
2252
  oclass->stock_cflags = "-fPIC";
 
2253
  oclass->stock_cppflags = "-DPIC";
 
2254
  oclass->stock_ldflags = "-shared -fPIC";
 
2255
  oclass->get_output_file = module_get_output_file;
 
2256
}