summaryrefslogtreecommitdiffstats
path: root/genprotsym.txr
blob: b343ce04b05a4a708bd84f4c0a93816efdd39a4b (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
@(bind prepro-sym @(hash :equal-based))
@(bind file-of @(hash :equal-based))
@(next "Makefile")
@(repeat)
@  (cases)
OBJS-$(have_@sym) += @file.o
@    (bind ppsym @(upcase-str `HAVE_@sym`))
@  (or)
OBJS-$(@sym) += @file.o
@    (bind ppsym @(upcase-str `CONFIG_@sym`))
@  (end)
@  (do (set [prepro-sym `@file.c`] ppsym))
@(end)
@(next :list (glob "*.c"))
@(collect)
@file
@  (next file)
@  (collect :vars ((sym nil)))
val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(do (set [file-of sym] file))@(end)
@  (end)
@  (flatten sym)
@(end)
@(next "lib.c")
@(collect)
@copyright
@(until)

@(end)
@(flatten sym)
@(bind pp-groups @[group-by [chain file-of prepro-sym] sym])
@(bind gsym @[mapcar (opip sort (tuples 5)) (hash-values pp-groups)])
@(bind gpp @(hash-keys pp-groups))
@(output "protsym.c")
/* This file is generated by genprotsym.txr */

@{copyright "\n"}

#include <stddef.h>
#include "config.h"
#include "lib.h"

@  (repeat :vars (gpp))
@    (if gpp `#if @gpp`)
@    (repeat)
extern val @(rep)@gsym, @(last)@gsym;@(end)
@    (end)
@    (if gpp "#endif")
@  (end)

val *protected_sym[] = {
@  (repeat :vars (gpp))
@    (if gpp `#if @gpp`)
@    (repeat)
  @(rep)&@gsym, @(last)&@gsym,@(end)
@    (end)
@    (if gpp "#endif")
@  (end)
  convert(val *, 0)
};
@(end)