@(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 #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)