-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.c
More file actions
69 lines (60 loc) · 1.64 KB
/
target.c
File metadata and controls
69 lines (60 loc) · 1.64 KB
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
// Copyright (C) 2026 p1k0chu
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "cbuild/link_target.h"
#include "target_private.h"
#include <err.h>
#include <stdarg.h>
#include <stdlib.h>
DEFINE_APPENDER_FUN(target, deps, cbuild_target_t *);
DEFINE_APPENDER_FUN(link_target, ldflags, const char *);
cbuild_link_target_t *
cbuild_link_target_create(enum cbuild_target_type type, const char *name, ...) {
switch (type) {
case CBUILD_TARGET_EXE:
case CBUILD_TARGET_SHAREDLIB:
case CBUILD_TARGET_STATICLIB:
break;
case CBUILD_TARGET_OBJECT:
case CBUILD_TARGET_CUSTOM:
default:
errx(1, "target type is invalid");
}
cbuild_link_target_t *p = calloc(1, sizeof(*p));
if (p == NULL)
err(1, "calloc");
p->base.outpath = name;
p->base.type = type;
va_list vlist;
va_start(vlist, name);
cbuild_target_t *o;
for (;;) {
o = va_arg(vlist, cbuild_target_t *);
if (o == NULL) {
va_end(vlist);
return p;
} else {
cbuild_target_append_deps((void *)p, &o, 1);
}
}
}
void cbuild_target_free(cbuild_target_t *p) {
switch (p->type) {
case CBUILD_TARGET_EXE:
case CBUILD_TARGET_SHAREDLIB:
case CBUILD_TARGET_STATICLIB:
cbuild_link_target_t *t = (void *)p;
free(t->ldflags.ptr);
break;
case CBUILD_TARGET_OBJECT:
cbuild_obj_t *o = (void *)p;
// is a malloc'ed pointer.
free((void *)o->base.outpath);
free(o->cflags.ptr);
break;
case CBUILD_TARGET_CUSTOM:
// nothing to free
break;
}
free(p->deps.ptr);
free(p);
}