-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
129 lines (105 loc) · 4.25 KB
/
Makefile
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
all: test
# Boilerplate
# -----------
include Makefile.include
FST_FILES=$(wildcard src/*.fst) $(wildcard src/*.fsti)
ifndef NODEPEND
ifndef MAKE_RESTARTS
.depend: .FORCE
@mkdir -p obj
@$(FSTAR) --dep full $(FST_FILES) > $@
.PHONY: .FORCE
.FORCE:
endif
endif
include .depend
.PHONY: clean
clean:
rm -rf obj dist .depend *.exe
# Verification
# ------------
hints obj:
mkdir $@
%.checked: | hints obj
$(FSTAR) --hint_dir hints $(notdir $*) && touch -c $@
%.krml:
$(FSTAR) --codegen krml \
--extract_module $(basename $(notdir $(subst .checked,,$<))) \
$(notdir $(subst .checked,,$<))
# Karamel
# -------
KRML=$(KRML_HOME)/krml
# Making sure that the extern symbols generated in MerkleTree_EverCrypt
# correspond to the ones found in libevercrypt.so
VALE_FLAGS= \
-library 'Vale.Stdcalls.*' \
-no-prefix 'Vale.Stdcalls.*' \
-static-header 'Vale.Inline.*' \
-library 'Vale.Inline.X64.Fadd_inline' \
-library 'Vale.Inline.X64.Fmul_inline' \
-library 'Vale.Inline.X64.Fswap_inline' \
-library 'Vale.Inline.X64.Fsqr_inline' \
-no-prefix 'Vale.Inline.X64.Fadd_inline' \
-no-prefix 'Vale.Inline.X64.Fmul_inline' \
-no-prefix 'Vale.Inline.X64.Fswap_inline' \
-no-prefix 'Vale.Inline.X64.Fsqr_inline' \
# The usual bug with prims.krml
dist/Makefile.basic: $(filter-out %prims.krml,$(ALL_KRML_FILES))
$(KRML) $(KOPTS) $^ -tmpdir dist -skip-compilation \
-minimal \
-add-include '"hacl_krmlrenamings.h"' \
-add-include '"krml/internal/target.h"' \
-add-include '"krml/internal/types.h"' \
-add-include '"krml/lowstar_endianness.h"' \
-add-include '<stdint.h>' \
-add-include '<stdbool.h>' \
-add-include '<string.h>' \
-fparentheses \
-funroll-loops 16 \
-o libmerkletree.a \
$(VALE_FLAGS) \
-no-prefix 'MerkleTree' \
-no-prefix 'MerkleTree.EverCrypt' \
-bundle EverCrypt.Hash,EverCrypt,EverCrypt.*,Meta.*,Hacl.*,Vale.*,Spec.*,Lib.*[rename=EverCrypt_Hash] \
-library EverCrypt.AutoConfig2 \
-bundle 'MerkleTree+MerkleTree.Init+MerkleTree.EverCrypt+MerkleTree.Low+MerkleTree.Low.Serialization+MerkleTree.Low.Hashfunctions=MerkleTree.*[rename=MerkleTree]' \
-bundle LowStar.* \
-bundle Prims,C.Failure,C,C.String,C.Loops,Spec.Loops,C.Endianness,FStar.*[rename=Merkle_Krmllib] \
-library 'Meta.*,Hacl.*,Vale.*,Spec.*,Lib.*' \
-ccopts '-DLib_IntVector_Intrinsics_vec256=void*,-DLib_IntVector_Intrinsics_vec128=void*'
dist/hacl_krmlrenamings.h: $(HACL_HOME)/dist/gcc-compatible/clients/krmlrenamings.h
cp $< $@
# A note on the options above. Merkle Tree does something illegal: it attempts
# to refer to an API of EverCrypt that is not exported in the generated .so. In
# other words: the symbols from EverCrypt.Hash (which Merkle Tree refers to) are
# NOT exported in libevercrypt.so (on the basis that everyone should go through
# the "streaming" API, not the unsafe block-based API).
#
# The recommended way to do separate compilation is to not re-extract EverCrypt,
# use -library EverCrypt, and link Merkle Tree against libevercrypt.so. But
# because of the above, this doesn't work! Linking fails, because EverCrypt.Hash
# is "private" (i.e. is hidden in EverCrypt_Hash.c with no header, and all
# functions marked as static in C).
#
# So, we violate our guidelines here, and we re-extract just EverCrypt.Hash,
# leaving the rest of EverCrypt as an abstract library. This means that there
# are now two copies of EverCrypt.Hash: one in Merkle Tree, located in
# EverCrypt_Hash, compiled as part of this Makefile, and another one, in
# libevercrypt.so, which is not exported and not visible externally.
#
# This is all pretty unfortunate, and fragile, so sadly I no longer recommended
# this project as the poster child of how to use EverCrypt from a client's
# perspective. Should anyone be interested in a reference Makefile, please use
# commit 19b1307e as a reference.
dist/libmerkletree.a: dist/Makefile.basic dist/hacl_krmlrenamings.h
$(MAKE) -C dist -f Makefile.basic
# Tests
# -----
.PHONY: test
test: test.exe
./$<
CFLAGS+=-Idist -Itests -I$(KRML_HOME)/include -I$(KRML_HOME)/krmllib/dist/minimal
$(HACL_HOME)/dist/gcc-compatible/libevercrypt.a:
$(error Please run make in $(dir $@))
test.exe: tests/merkle_tree_test.c dist/libmerkletree.a $(HACL_HOME)/dist/gcc-compatible/libevercrypt.a
$(CC) $(CFLAGS) -Idist -Itests $^ -o $@