aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/bin/target.hxx
blob: 8f2a92e444670018445a4f9c35d9ab309f4972bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
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
292
293
294
295
296
297
298
299
300
301
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// file      : libbuild2/bin/target.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef LIBBUILD2_BIN_TARGET_HXX
#define LIBBUILD2_BIN_TARGET_HXX

#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>

#include <libbuild2/target.hxx>

#include <libbuild2/bin/export.hxx>

namespace build2
{
  namespace bin
  {
    // The obj{} target group.
    //
    // Common base of all objX{} object files.
    //
    class LIBBUILD2_BIN_SYMEXPORT objx: public file
    {
    public:
      objx (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT obje: public objx
    {
    public:
      obje (context& c, dir_path d, dir_path o, string n)
        : objx (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT obja: public objx
    {
    public:
      obja (context& c, dir_path d, dir_path o, string n)
        : objx (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT objs: public objx
    {
    public:
      objs (context& c, dir_path d, dir_path o, string n)
        : objx (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Note: this is a "choice" target group.
    //
    class LIBBUILD2_BIN_SYMEXPORT obj: public target
    {
    public:
      obj (context& c, dir_path d, dir_path o, string n)
        : target (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Binary module interface (BMI).
    //
    // While currently there are only C++ modules, if things pan out, chances
    // are we will have C (or Obj-C) modules. And in that case it is plausible
    // we will also have some binutils to examine BMIs, similar to objdump,
    // etc. So that's why this target type is in bin and not cxx.
    //
    // bmi*{} is similar to obj*{} though the semantics is a bit different:
    // the idea is that we should try hard to re-use a single bmiX{} file for
    // an entire "build" but if that's not possible (because the compilation
    // options are too different), then compile a private version for
    // ourselves (the definition of "too different" is, of course, compiler-
    // specific).
    //
    // When we compile a module interface unit, we end up with bmi*{} and
    // obj*{}. How that obj*{} is produced is compiler-dependent. While it
    // makes sense to decouple the production of the two in order to increase
    // parallelism, doing so will further complicate the already hairy
    // organization. So, at least for now, we produce the two at the same time
    // and make obj*{} an ad hoc member of bmi*{}.
    //
    // There are also header units for which we define a parallel hbmi*{}
    // hierarchy. Note that hbmix{} is-a bmix{} (we think of header BMIs as a
    // more specialized kind of BMI) so where you need to distinguish between
    // header and module BMIs, you should check for headers first. Note also
    // that in case of a header unit there may be no obj*{}.
    //
    // Common base of all bmiX{} interface files.
    //
    class LIBBUILD2_BIN_SYMEXPORT bmix: public file
    {
    public:
      bmix (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Common base of all hbmiX{} interface files.
    //
    class LIBBUILD2_BIN_SYMEXPORT hbmix: public bmix
    {
    public:
      hbmix (context& c, dir_path d, dir_path o, string n)
        : bmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT bmie: public bmix
    {
    public:
      bmie (context& c, dir_path d, dir_path o, string n)
        : bmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT hbmie: public hbmix
    {
    public:
      hbmie (context& c, dir_path d, dir_path o, string n)
        : hbmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT bmia: public bmix
    {
    public:
      bmia (context& c, dir_path d, dir_path o, string n)
        : bmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT hbmia: public hbmix
    {
    public:
      hbmia (context& c, dir_path d, dir_path o, string n)
        : hbmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT bmis: public bmix
    {
    public:
      bmis (context& c, dir_path d, dir_path o, string n)
        : bmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT hbmis: public hbmix
    {
    public:
      hbmis (context& c, dir_path d, dir_path o, string n)
        : hbmix (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Note: this is a "choice" target group (similar to obj{}).
    //
    class LIBBUILD2_BIN_SYMEXPORT bmi: public target
    {
    public:
      bmi (context& c, dir_path d, dir_path o, string n)
        : target (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Note: this is a "choice" target group (similar to bmi{} and obj{}).
    //
    class LIBBUILD2_BIN_SYMEXPORT hbmi: public target
    {
    public:
      hbmi (context& c, dir_path d, dir_path o, string n)
        : target (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Common base for lib{} and libul{} groups.
    //
    // Use mtime_target as a base for the "trust me it exists" functionality
    // which we use, for example, to have installed lib{} prerequisites that
    // are matched by the fallback file rule.
    //
    class LIBBUILD2_BIN_SYMEXPORT libx: public mtime_target
    {
    public:
      libx (context& c, dir_path d, dir_path o, string n)
        : mtime_target (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // The libue{} target, libul{} group and libua{} and libus{} members
    // (utility library).
    //
    // Utility libraries are static libraries that differ based on the kind of
    // object files they contains. Note that the libul{} group is more like
    // obj{} rather than lib{} in that one does not build the group directly
    // rather picking a suitable member.
    //
    // libul{} is a "library utility library" in that the choice of members is
    // libua{} or libus{}, even when linking an executable (normally a unit
    // test).
    //
    // Note that there is no "general utility library" with all three types of
    // members (that would cause member uplink ambiguity). If you need to
    // build both a library from libua{}/libus{} and an executable from
    // libue{} then you will need to arrange this explicitly, for example:
    //
    // exe{foo}: libue{foo}
    // lib{foo}: libul{foo}
    //
    // {libue libul}{foo}: cxx{*}
    //
    // Common base of all libuX{} static libraries.
    //
    class LIBBUILD2_BIN_SYMEXPORT libux: public file
    {
    public:
      libux (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT libue: public libux
    {
    public:
      libue (context& c, dir_path d, dir_path o, string n)
        : libux (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT libua: public libux
    {
    public:
      libua (context& c, dir_path d, dir_path o, string n)
        : libux (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT libus: public libux
    {
    public:
      libus (context& c, dir_path d, dir_path o, string n)
        : libux (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Note: this is a "choice" target group.
    //
    // @@ Ideally this shouldn't derive from mtime_target (via libx). Maybe
    //    get rid of libx?
    //
    class LIBBUILD2_BIN_SYMEXPORT libul: public libx
    {
    public:
      libul (context& c, dir_path d, dir_path o, string n)
        : libx (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // The lib{} target group.
    //
    class LIBBUILD2_BIN_SYMEXPORT liba: public file
    {
    public:
      liba (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    class LIBBUILD2_BIN_SYMEXPORT libs: public file
    {
    public:
      libs (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Standard layout type compatible with group_view's const target*[2].
    //
    struct lib_members
    {
      const liba* a = nullptr;
      const libs* s = nullptr;
    };

    class LIBBUILD2_BIN_SYMEXPORT lib: public libx, public lib_members
    {
    public:
      lib (context& c, dir_path d, dir_path o, string n)
        : libx (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

      virtual group_view
      group_members (action) const override;

      // Match options for the install operation on the liba{}/libs{} and
      // libua{}/libus{} target types (note: not lib{}/libul{} nor libue{}).
      //
      // If only install_runtime option is specified, then only install the
      // runtime files omitting everything buildtime (headers, pkg-config
      // files, shared library version-related symlinks, etc).
      //
      // Note that it's either runtime-only or runtime and buildtime (i.e.,
      // everything), so match with install_all instead of install_buildtime
      // (the latter is only useful in the rule implementations).
      //
      static constexpr uint64_t option_install_runtime   = 0x01;
      static constexpr uint64_t option_install_buildtime = 0x02;
      static constexpr uint64_t option_install_all = match_extra::all_options;

    public:
      static const target_type static_type;
    };

    // Windows import library.
    //
    class LIBBUILD2_BIN_SYMEXPORT libi: public file
    {
    public:
      libi (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };

    // Windows module definition (.def).
    //
    class LIBBUILD2_BIN_SYMEXPORT def: public file
    {
    public:
      def (context& c, dir_path d, dir_path o, string n)
        : file (c, move (d), move (o), move (n))
      {
        dynamic_type = &static_type;
      }

    public:
      static const target_type static_type;
    };
  }
}

#endif // LIBBUILD2_BIN_TARGET_HXX