summaryrefslogtreecommitdiff
path: root/Makefile
blob: 0199d87c6ca0a2ead2e2df1ebfe28c1f6a117897 (plain)
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
ifeq ($(shell uname),Darwin)
    LDFLAGS := -Wl,-dead_strip -framework Security -framework Foundation
else
    LDFLAGS := -Wl,--gc-sections -lpthread -ldl
endif

CARGO ?= cargo
CARGOFLAGS += --locked

CFLAGS := -Werror -Wall -Wextra -Wpedantic -g -I src/
PROFILE := release
CRYPTO_PROVIDER := aws-lc-rs
DESTDIR=/usr/local

ifeq ($(PROFILE), debug)
	CFLAGS += -fsanitize=address -fsanitize=undefined
	LDFLAGS += -fsanitize=address -fsanitize=undefined
endif

ifeq ($(PROFILE), release)
	CFLAGS += -O3
	CARGOFLAGS += --release
endif

ifneq (,$(TARGET))
	PROFILE := $(TARGET)/$(PROFILE)
	CARGOFLAGS += --target $(TARGET)
endif

ifeq ($(CRYPTO_PROVIDER), aws-lc-rs)
	CFLAGS += -D DEFINE_AWS_LC_RS
	CARGOFLAGS += --no-default-features --features aws-lc-rs
else ifeq ($(CRYPTO_PROVIDER), ring)
	CFLAGS += -D DEFINE_RING
	CARGOFLAGS += --no-default-features --features ring
endif

all: target/client target/server

test: all
	${CARGO} test ${CARGOFLAGS}

integration: all
	${CARGO} test ${CARGOFLAGS} -- --ignored

connect-test: target/client
	RUSTLS_PLATFORM_VERIFIER=1 target/client example.com 443 /

target:
	mkdir -p $@

src/rustls.h: src/*.rs cbindgen.toml
	cbindgen > $@

target/$(PROFILE)/librustls_ffi.a: src/*.rs Cargo.toml
	RUSTFLAGS="-C metadata=rustls-ffi" ${CARGO} build $(CARGOFLAGS)

target/%.o: tests/%.c tests/common.h | target
	$(CC) -o $@ -c $< $(CFLAGS)

target/client: target/client.o target/common.o target/$(PROFILE)/librustls_ffi.a
	$(CC) -o $@ $^ $(LDFLAGS)

target/server: target/server.o target/common.o target/$(PROFILE)/librustls_ffi.a
	$(CC) -o $@ $^ $(LDFLAGS)

install: target/$(PROFILE)/librustls_ffi.a
	mkdir -p $(DESTDIR)/lib
	install target/$(PROFILE)/librustls_ffi.a $(DESTDIR)/lib/librustls.a
	mkdir -p $(DESTDIR)/include
	install src/rustls.h $(DESTDIR)/include/

clean:
	rm -rf target

format:
	find src tests \
		-name '*.[c|h]' \
		! -wholename 'src/rustls.h' | \
			xargs clang-format -i
	sed -i -e 's/ffi_panic_boundary! {/if true {/g' src/*.rs
	cargo fmt
	sed -i -e 's/if true {/ffi_panic_boundary! {/g' src/*.rs

format-check:
	find src tests \
		-name '*.[c|h]' \
		! -wholename 'src/rustls.h' | \
			xargs clang-format --dry-run -Werror -i
	sed -i -e 's/ffi_panic_boundary! {/if true {/g' src/*.rs
	cargo fmt --check
	sed -i -e 's/if true {/ffi_panic_boundary! {/g' src/*.rs

.PHONY: all clean test integration format format-check