summaryrefslogtreecommitdiffstats
path: root/genprotsym.txr
blob: 3ba70b3aac102624b5b382451e14aab9a0972f82 (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
@(bind pp-sym-of-file @(hash :equal-based))
@(bind pp-syms-of-sym @(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 [pp-sym-of-file `@file.c`] ppsym))
@(end)
@(next :list (glob "*.c"))
@(bind pp-stack nil)
@(collect)
@file
@  (next file)
@  (do (whenlet ((pp [pp-sym-of-file file]))
         (set pp-stack (list pp))))
@  (collect :vars ((sym nil)))
@    (cases)
val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@\
           @(do (set [pp-syms-of-sym sym] pp-stack))@(end)
@    (or)
#if @ppsym
@      (do (push ppsym pp-stack))
@    (or)
#endif
@      (do (pop pp-stack))
@    (end)
@  (end)
@  (flatten sym)
@(end)
@(next "lib.c")
@(collect)
@copyright
@(until)

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

@{copyright "\n"}

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

@  (repeat :vars (gpp))
@    (repeat)
extern val @(rep)@gsym, @(last)@gsym;@(end)
@    (first)
@(if gpp `#if @{gpp " && "}\n`)extern val @(rep)@gsym, @(last)@gsym;@(end)
@    (end)
@    (if gpp "#endif")
@  (end)

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