forked from hacl-star/hacl-star
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.tmpl
187 lines (145 loc) · 6.26 KB
/
Makefile.tmpl
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# This is the universal Makefile that will build any distribution of EverCrypt.
# - It is copied from hacl-star/providers/dist/Makefile
# - It relies on the KaRaMeL-generated Makefile.basic and Makefile.include
#
# This Makefile may (conservatively) link in some Vale assemblies that may end
# up un-needed in the final shared object.
#
# Additionally, this Makefile works out of the box on Linux, OSX and
# Cygwin/MinGW.
#
# The Makefile produces:
# - libevercrypt.so, a shared object where unused symbols have been removed
# - libevercrypt.a
# By default, this Makefile relies on the local checkout of krmllib
KRML_HOME ?= ../karamel
ifeq (,$(wildcard $(KRML_HOME)/include/krmllib.h))
$(error Incorrect KRML_HOME)
endif
-include Makefile.config
UNAME ?= $(shell uname)
MARCH ?= $(shell uname -m | sed 's/amd64/x86_64/')
ifeq ($(UNAME),Darwin)
VARIANT = -darwin
SO = so
else ifeq ($(UNAME),Linux)
CFLAGS += -fPIC
VARIANT = -linux
SO = so
else ifeq ($(OS),Windows_NT)
CFLAGS += -fno-asynchronous-unwind-tables
CC = $(MARCH)-w64-mingw32-gcc
AR = $(MARCH)-w64-mingw32-ar
VARIANT = -mingw
SO = dll
LDFLAGS = -Wl,--out-implib,libevercrypt.dll.a
else ifeq ($(UNAME),FreeBSD)
CFLAGS += -fPIC
VARIANT = -linux
SO = so
endif
OBJS += $(patsubst %.S,%.o,$(wildcard *-$(MARCH)$(VARIANT).S))
include Makefile.basic
CFLAGS += -Wno-parentheses -Wno-deprecated-declarations -Wno-\#warnings -Wno-error=cpp -Wno-cpp -g -std=gnu11 -O3
Hacl_Poly1305_128.o Hacl_Streaming_Poly1305_128.o Hacl_Chacha20_Vec128.o Hacl_Chacha20Poly1305_128.o Hacl_Hash_Blake2s_128.o Hacl_HMAC_Blake2s_128.o Hacl_HKDF_Blake2s_128.o Hacl_Streaming_Blake2s_128.o Hacl_SHA2_Vec128.o: CFLAGS += $(CFLAGS_128)
Hacl_Poly1305_256.o Hacl_Streaming_Poly1305_256.o Hacl_Chacha20_Vec256.o Hacl_Chacha20Poly1305_256.o Hacl_Hash_Blake2b_256.o Hacl_HMAC_Blake2b_256.o Hacl_HKDF_Blake2b_256.o Hacl_Streaming_Blake2b_256.o Hacl_SHA2_Vec256.o: CFLAGS += $(CFLAGS_256)
all: libevercrypt.$(SO)
# This one and the one below are for people who run "make" without running
# configure. It's not perfect but perhaps a tiny bit better than nothing.
Makefile.config:
./configure
# If the configure script has not run, create an empty config.h
config.h:
touch $@
libevercrypt.$(SO): config.h $(OBJS)
$(CC) $(CFLAGS) -shared -o $@ $(filter-out %.h,$^) $(LDFLAGS)
# 4. Compilation of OCaml bindings; conditional on the presence of the lib_gen
# folder, possibly disabled by configure.
ifeq (,$(DISABLE_OCAML_BINDINGS))
ifneq (,$(wildcard lib_gen))
.PRECIOUS: %.cmx
OCAMLOPT=ocamlfind opt -package ctypes,ctypes.stubs -linkpkg -I lib
OCAMLDEP=ocamlfind dep -I lib -slash
OCAMLC=ocamlfind c -g -package ctypes,ctypes.stubs -linkpkg -I lib
CFLAGS += -I "$(shell ocamlfind query ctypes)" -I "$(shell ocamlfind c -where)"
# Don't include bindings for files that cannot be compiled.
BLACKLIST_ML=$(patsubst %.c,%,$(BLACKLIST))
ALL_OCAML=$(filter-out $(BLACKLIST_ML),$(patsubst lib_gen/%_gen.ml,%,$(wildcard lib_gen/*_gen.ml)))
# Just names.
ALL_BINDINGS=$(patsubst %,lib/%_bindings.cmx,$(ALL_OCAML))
ALL_GENERATORS=$(patsubst %,lib_gen/%_gen.exe, $(ALL_OCAML))
ALL_ML_STUBS=$(patsubst %,lib/%_stubs.cmx,$(ALL_OCAML))
ALL_C_STUBS=$(patsubst %,lib/%_c_stubs.o,$(ALL_OCAML))
include .depend.ocaml
include ctypes.depend
lib_gen/Lib_RandomBuffer_System_gen.cmx: lib/Lib_RandomBuffer_System_bindings.cmx
lib_gen/Lib_RandomBuffer_System_gen.exe: lib/Lib_RandomBuffer_System_bindings.cmx lib_gen/Lib_RandomBuffer_System_gen.cmx
.depend.ocaml:
$(OCAMLDEP) $(wildcard lib/*.ml) $(wildcard lib_gen/*.ml) > $@
# Note: for some reason, this minimal Makefile doesn't apply the shortest stem
# rule.
#
# %.exe:
# echo long stem
#
# %_foo.exe: %.b
# cat $<
#
# %.b:
# echo $@ > $@
#
# Which really puzzles me (e.g. make foo_foo.exe always echoes "long stem"),
# even though the shortest stem rule should apply. However, we can cancel a
# previous pattern rule, thanks to
# https://www.gnu.org/software/make/manual/html_node/Canceling-Rules.html
%.exe:
all: ocamlevercrypt.cmxa
lib_gen/%_gen.exe: libevercrypt.a
$(OCAMLOPT) $(filter-out %.a,$^) libevercrypt.a -o $@
%.cmx: %.ml
$(OCAMLOPT) -c $^ -o $@
%.cmo: %.ml
$(OCAMLC) -c $^ -o $@
.PRECIOUS: lib/%_stubs.ml
lib/%_stubs.ml: lib/%_c_stubs.c
ifeq ($(shell uname -s),Darwin)
DY=DYLD_LIBRARY_
else ifeq ($(OS),Windows_NT)
DY=
else
DY=LD_LIBRARY_
endif
lib/%_stubs.ml lib/%_c_stubs.c: lib_gen/%_gen.exe
$<
# Compiling these files raises the pointer sign warning because the Ctypes declaration for bytes expects a char*, not a uint8_t*
# Can be remove once ctypes is upgraded to 0.17
lib/%_c_stubs.o: CFLAGS += -Wno-pointer-sign
BLACKLIST_CMX = $(patsubst %,lib/%_stubs.cmx,$(BLACKLIST_ML))
BLACKLIST_CMX += $(patsubst %,lib/%_bindings.cmx,$(BLACKLIST_ML))
CTYPES_CMX = $(filter-out $(BLACKLIST_CMX),$(CTYPES_DEPS))
CTYPES_CMX += lib/Lib_RandomBuffer_System_stubs.cmx lib/Lib_RandomBuffer_System_bindings.cmx
CTYPES_ML = $(patsubst %.cmx,%.ml,$(CTYPES_CMX))
CTYPES_CMI = $(patsubst %.cmx,%.cmi,$(CTYPES_CMX))
CTYPES_CMO = $(patsubst %.cmx,%.cmo,$(CTYPES_CMX))
ocamlevercrypt.cma: $(ALL_BINDINGS) $(CTYPES_CMO) $(ALL_C_STUBS) $(CTYPES_CMX) libevercrypt.$(SO)
ocamlmklib -o ocamlevercrypt $(CTYPES_CMO) -L. -levercrypt
ocamlevercrypt.cmxa: $(ALL_BINDINGS) $(ALL_ML_STUBS) $(ALL_C_STUBS) libevercrypt.$(SO)
ocamlmklib -o ocamlevercrypt $(CTYPES_CMX) -L. -levercrypt
STUBLIBS_PATH=$(OPAM_SWITCH_PREFIX)/lib/stublibs
dllocamlevercrypt.$(SO): ocamlevercrypt.cmxa ocamlevercrypt.cma
ocamlmklib -o ocamlevercrypt $(ALL_C_STUBS) -L. -L$(STUBLIBS_PATH) -levercrypt
install-hacl-star-raw: dllocamlevercrypt.$(SO)
ocamlfind remove hacl-star-raw || true
ocamlfind install $(OCAMLFIND_OPTS) hacl-star-raw META
ocamlfind install $(OCAMLFIND_OPTS) -add hacl-star-raw $(CTYPES_ML)
ocamlfind install $(OCAMLFIND_OPTS) -add hacl-star-raw $(CTYPES_CMX)
ocamlfind install $(OCAMLFIND_OPTS) -add hacl-star-raw $(CTYPES_CMO)
ocamlfind install $(OCAMLFIND_OPTS) -add hacl-star-raw $(CTYPES_CMI)
ocamlfind install $(OCAMLFIND_OPTS) -add hacl-star-raw \
libevercrypt.a libevercrypt.$(SO) ocamlevercrypt.cma ocamlevercrypt.cmxa ocamlevercrypt.a \
libocamlevercrypt.a dllocamlevercrypt.$(SO) config.h
.PHONY: install-ocaml
install-ocaml: install-hacl-star-raw
cd ../../bindings/ocaml && dune build && dune install
endif
endif