-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
118 lines (90 loc) · 4.18 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
BUILDDIR=_build
VPATH=$(BUILDDIR)
OCAMLDIR=$(shell ocamlopt -where)
$(shell mkdir -p $(BUILDDIR) $(BUILDDIR)/stub $(BUILDDIR)/lib $(BUILDDIR)/stub_generator $(BUILDDIR)/echo_client $(BUILDDIR)/generated)
PACKAGES=ipaddr,rresult,tls,ctypes.stubs,ctypes.foreign,nocrypto.unix,memcpy,hex
CTYPES=$(shell ocamlfind query ctypes)
OCAMLDEP=ocamldep
MALLOC_GENERATOR = $(BUILDDIR)/lib_malloc/gen.native
# The files used to build the stub generator.
BINDING_FILES = $(BUILDDIR)/lib/nqsb.cmx \
$(BUILDDIR)/lib/nqsb_x509.cmx \
$(BUILDDIR)/lib/nqsb_peer.cmx \
$(BUILDDIR)/lib/nqsb_unix.cmx \
$(BUILDDIR)/lib/nqsb_ciphers.cmx \
$(BUILDDIR)/lib/nqsb_config.cmx
GENERATOR_FILES= $(BINDING_FILES) \
$(BUILDDIR)/lib/bindings.cmx \
$(BUILDDIR)/stub_generator/generate.cmx
# The files from which we'll build a shared library.
MALLOC_LIB=$(BUILDDIR)/lib/malloc.cmx
MALLOC_FILES=$(BUILDDIR)/generated/malloc_generated.cmx \
$(BUILDDIR)/lib_malloc/malloc_binding.cmx \
$(BUILDDIR)/generated/malloc_stubs.o
LIBFILES=$(BUILDDIR)/lib/nqsb.cmx \
$(BUILDDIR)/lib/nqsb_x509.cmx \
$(BUILDDIR)/lib/nqsb_peer.cmx \
$(BUILDDIR)/lib/nqsb_unix.cmx \
$(BUILDDIR)/lib/nqsb_ciphers.cmx \
$(BUILDDIR)/lib/nqsb_config.cmx \
$(BUILDDIR)/lib/bindings.cmx \
$(BUILDDIR)/generated/tls_bindings.cmx \
$(BUILDDIR)/lib/apply_bindings.cmx \
$(BUILDDIR)/generated/tls.o
CAML_INIT=$(BUILDDIR)/stub/init.o
# The files that we'll generate
GENERATED=$(BUILDDIR)/generated/tls.h \
$(BUILDDIR)/generated/tls.c \
$(BUILDDIR)/generated/tls_bindings.ml
MALLOC_GENERATED=$(BUILDDIR)/malloc/malloc.c \
$(BUILDDIR)/malloc/malloc.ml
OSTYPE:=$(shell ocamlfind ocamlc -config | awk '/^os_type:/ {print $$2}')
SYSTEM:=$(shell ocamlfind ocamlc -config | awk '/^system:/ {print $$2}')
EXTDLL:=$(shell ocamlfind ocamlc -config | awk '/^ext_dll:/ {print $$2}')
CC:= $(shell ocamlfind ocamlc -config | awk '/^bytecomp_c_compiler/ {for(i=2;i<=NF;i++) printf "%s " ,$$i}')
ifeq ($(OSTYPE),$(filter $(OSTYPE),Win32 Cygwin))
EXTEXE=.exe
else
EXTEXE=
endif
GENERATOR=$(BUILDDIR)/generate$(EXTEXE)
all: malloc sharedlib
sharedlib: $(BUILDDIR)/libtls$(EXTDLL)
malloc: $(MALLOC_LIB)
ifeq ($(OSTYPE),$(filter $(OSTYPE),Win32 Cygwin))
$(BUILDDIR)/libtls$(EXTDLL): $(CAML_INIT) $(MALLOC_FILES) $(MALLOC_LIB) $(LIBFILES)
ocamlfind opt -o $@ -linkpkg -output-obj -verbose -package $(PACKAGES) $^
else ifeq ($(SYSTEM),$(filter $(SYSTEM),macosx))
$(BUILDDIR)/libtls$(EXTDLL): $(CAML_INIT) $(MALLOC_FILES) $(MALLOC_LIB) $(LIBFILES)
ocamlfind opt -o $@ -linkpkg -runtime-variant _pic -verbose -ccopt -dynamiclib -package $(PACKAGES) $^
else
$(BUILDDIR)/libtls$(EXTDLL): $(CAML_INIT) $(MALLOC_FILES) $(MALLOC_LIB) $(LIBFILES)
ocamlfind opt -o $@ -linkpkg -output-obj -runtime-variant _pic -verbose -package $(PACKAGES) $^
endif
stubs: $(GENERATED)
$(MALLOC_LIB): $(MALLOC_GENERATED) $(MALLOC_FILES)
ocamlfind ocamlopt -c -g -annot -bin-annot -ccopt -I -ccopt $(CTYPES) -package bytes,ctypes.foreign,ctypes.stubs -I $(BUILDDIR)/generated -I $(BUILDDIR)/lib_malloc -o $(MALLOC_LIB) lib_malloc/malloc.ml
$(BUILDDIR)/lib/nqsb_config.cmx : $(BUILDDIR)/lib/nqsb_config.cmi
$(BUILDDIR)/lib/nqsb_unix.cmx : $(BUILDDIR)/lib/nqsb_unix.cmi
$(BUILDDIR)/lib/nqsb_ciphers.cmx : $(BUILDDIR)/lib/nqsb_ciphers.cmi
$(BUILDDIR)/lib/nqsb_peer.cmx : $(BUILDDIR)/lib/nqsb_peer.cmi
$(BUILDDIR)/lib/nqsb.cmx : $(BUILDDIR)/lib/nqsb.cmi
$(BUILDDIR)/stub/%.o:
ocamlc -g -c stub/init.c
mv init.o $@
$(MALLOC_GENERATED): $(MALLOC_GENERATOR)
$(MALLOC_GENERATOR) $(BUILDDIR)/generated
$(GENERATED): $(GENERATOR)
$(GENERATOR) $(BUILDDIR)/generated
$(BUILDDIR)/%.o: %.c
$(CC) -c -o $@ -fPIC -I $(shell ocamlfind query ctypes) -I $(OCAMLDIR) -I $(OCAMLDIR)/../ctypes $<
$(BUILDDIR)/%.cmx: %.ml
ocamlfind opt -c -o $@ -I $(BUILDDIR)/generated -I $(BUILDDIR)/lib -package $(PACKAGES) $<
$(BUILDDIR)/%.cmi: %.mli
ocamlfind c -c -o $@ -I $(BUILDDIR)/generated -I $(BUILDDIR)/lib -package $(PACKAGES) $<
$(GENERATOR): $(MALLOC_FILES) $(MALLOC_LIB) $(GENERATOR_FILES)
ocamlfind opt -o $@ -linkpkg -package $(PACKAGES) $^
$(MALLOC_GENERATOR):
ocamlbuild -pkgs ctypes,ctypes.stubs -I lib_malloc gen.native
clean:
rm -rf $(BUILDDIR)