-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathregenerate.sh
executable file
·43 lines (35 loc) · 1.37 KB
/
regenerate.sh
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
#!/bin/sh
[[ $(c2nim -v) == "0.9.18" ]] || echo "Different c2nim used, check the code"
mkdir -p gen
cp bearssl/csources/inc/*.h gen
cp bearssl/csources/tools/brssl.h gen
# c2nim gets confused by #ifdef inside struct's
unifdef -m -UBR_DOXYGEN_IGNORE gen/*.h
# TODO: several things broken in c2nim 0.9.18
# https://github.com/nim-lang/c2nim/issues/239
# https://github.com/nim-lang/c2nim/issues/240
# https://github.com/nim-lang/c2nim/issues/241
# https://github.com/nim-lang/c2nim/issues/242
c2nim --header --importc --nep1 --prefix:br_ --prefix:BR_ --skipinclude --cdecl --skipcomments gen/*.h
rm gen/*.h
# Fix cosmetic and ease-of-use issues
sed -i \
-e "s/int16T/int16/g" \
-e "s/int32T/int32/g" \
-e "s/int64T/int64/g" \
-e "s/cuchar/byte/g" \
-e "s/cdecl/importcFunc/g" \
-e "s/csize_t/uint/g" \
gen/*.nim
# The functions taking a "Context" don't allow `nil` being passed to them - use
# `var` instead - ditto for "output" parameters like length
sed -i \
-e 's/ctx: ptr \(.*\)Context/ctx: var \1Context/g' \
-e 's/ctx: ptr \(.*\)Keys/ctx: var \1Keys/g' \
-e 's/hc: ptr \(.*\)Context/hc: var \1Context/g' \
-e 's/sc: ptr \(.*\)Context/sc: var \1Context/g' \
-e 's/cc: ptr \(.*\)Context/cc: var \1Context/g' \
-e 's/kc: ptr \(.*\)Context/kc: var \1Context/g' \
-e 's/xwc: ptr \(.*\)Context/xwc: var \1Context/g' \
-e 's/len: ptr uint/len: var uint/g' \
gen/*.nim