-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGNUmakefile
108 lines (96 loc) · 3.44 KB
/
GNUmakefile
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
# shared flags for the ocaml compiler:
$(eval OFLAGS := -absname -unboxed-types -safe-string -verbose \
-w +1..999-57-42-4-38 -warn-error +a-26-27-4-33 )
# shared flags for c compilation (through the ocaml compiler):
$(eval CFLAGS := -ccopt -fPIE -compact )
# dependencies for the ofetch cli utility:
ifeq "$(shell ocamlfind query tls 2>&- || true)" ""
$(eval OFETCH_WRAP_FILE := ofetch_unix)
$(eval OFETCH_WRAP_DEPS := ./ofetch_unix.mli)
$(eval OCOM := ocamlopt.opt unix.cmxa bigarray.cmxa )
else
# build with TLS support:
$(eval OFETCH_WRAP_FILE := ofetch_tls_wrap)
$(eval OFETCH_WRAP_DEPS := ./ofetch_unix.mli ./ofetch_unix.ml ./ofetch_tls.mli ./ofetch_tls.ml)
$(eval OCOM := ocamlfind opt -package nocrypto.unix -package tls -linkpkg)
endif
cli: builddir lib ofetch_cli.ml
@ cd _build/ && \
set -x && \
cp $(OFETCH_WRAP_FILE).ml ofetch_wrap.ml && \
cp $(OFETCH_WRAP_FILE).mli ofetch_wrap.mli && \
$(OCOM) $(OFLAGS) $(CFLAGS) \
ofetch.cmx \
$(OFETCH_WRAP_DEPS) ./ofetch_wrap.mli ./ofetch_wrap.ml \
./ofetch_cli.ml -o ./ofetch && \
{ { set +x ; } 2> /dev/null ; } && \
strip ./ofetch && \
cd ../ && ls -lh ./_build/ofetch
builddir: *.ml
@ mkdir -p _build/ && \
cp ./*.ml ./*.mli _build/
lib: builddir ofetch.ml ofetch.mli
@ cd _build/ && \
ocamlopt.opt $(OFLAGS) $(CFLAGS) \
-c -linkall \
bigarray.cmxa ./ofetch.mli ./ofetch.ml
test: builddir lib ofetch.ml tests.ml
cd _build/ && \
cp ../tests.ml . && \
ocamlfind opt $(OFLAGS) $(CFLAGS) \
-package alcotest -package qcheck -linkpkg \
bigarray.cmxa ./ofetch.cmx ./tests.ml -o ./tests && \
./tests && echo "tests ran, all good"
install: cli
cd _build && cp ofetch $(PREFIX)/bin/ofetch
debug: builddir ofetch.ml
cd _build/ && \
ocamlc.byte $(OFLAGS) \
-g -bin-annot \
unix.cma bigarray.cma ./ofetch.ml ./ofetch_cli.ml \
-o ./ofetch.bc && \
ocamldebug ./ofetch.bc
define compare_wget
#
@ # first argument: testcase name
@ # second argument: url to fetch
@ echo "===== comparing against wget:" "$1" "$2"
$(eval OFETCH:= "test.$1.ofetch")
$(eval WGET := "test.$1.wget")
@ cd _build/ && \
rm -f $(OFETCH) $(WGET) && \
set -x && \
time wget --max-redirect=0 --content-on-error --no-hsts --tries 1 -O $(WGET) "$2" ; \
time ./ofetch -v $(OFETCH) "$2" ; \
{ { set +x ; } 2> /dev/null ; } && \
{ \
{ sha1sum "$(OFETCH)" > "$(OFETCH).sha1" && \
sha1sum "$(WGET)" > "$(WGET).sha1" && \
diff -y --suppress-common-lines "$(OFETCH).sha1" "$(WGET).sha1" || true\
; } && \
{ cmp -b $(OFETCH) $(WGET) || \
{ diff -y --suppress-common-lines $(OFETCH) $(WGET) \
| head -10 ; exit 1 ; } ; \
} ; \
} && \
echo ============
endef
network-test: cli ./_build/ofetch
@ # Chunked:
$(call compare_wget,lists-ocaml-org,"http://lists.ocaml.org/listinfo/platform/")
@ # Content-Length:
$(call compare_wget,robur,"http://robur.io/")
$(call compare_wget,opam-frontpage,"http://opam.ocaml.org/")
$(call compare_wget,hbsd-ftp,"http://ftp.hardenedbsd.org/")
$(call compare_wget,mccs,"http://www.i3s.unice.fr/~cpjm/misc/mccs-1.1-srcs.tgz")
@ # this one reports Accept-Ranges: bytes:
$(call compare_wget,debian-sha256,"http://ftp.nl.debian.org/debian/dists/stretch/main/installer-armhf/current/images/SHA256SUMS")
@ # TLS
$(call compare_wget,mirage-io,"https://mirage.io/")
@ # misc
clean:
@ rm -fr ./_build/
# commented out: example of using temporary directories for downloads:
# $(eval TESTDIR := $(shell mktemp -d))
#@ rm -f "$(TESTDIR)/hbsd.ftp" ; \
#@ rmdir "$(TESTDIR)"