This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Makefile
141 lines (117 loc) · 3.97 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
130
131
132
133
134
135
136
137
138
139
140
141
PROJDIR := $(shell readlink -f ..)
TOP_DIR := .
CUR_DIR := $(shell pwd)
PREFIX := /usr/local
ifeq ($(shell test -e /etc/debian_version && echo -n yes),yes)
DEBIANOS = true
else
DEBIANOS = false
endif
$(info DEBIANOS is: $(DEBIANOS))
TARGET_DIR := target
BIN_NAME := attestation-agent
SOURCE_ARCH := $(shell uname -m)
ARCH ?= $(shell uname -m)
DEBUG ?=
LIBC ?= gnu
KBC ?=
ttrpc ?=
grpc ?=
DESTDIR ?= $(PREFIX)/bin
RUSTFLAGS_ARGS ?=
features ?=
OPENSSL ?=
ifeq ($(SOURCE_ARCH), ppc64le)
ARCH=powerpc64le
endif
ifeq ($(ARCH), $(filter $(ARCH), s390x powerpc64le))
OPENSSL=1
endif
ifdef KBC
features += $(KBC)
else
features += sample_kbc
endif
ifeq ($(ttrpc), true)
features += ttrpc
else
features += grpc
endif
ifeq ($(LIBC), musl)
ifeq ($(ARCH), $(filter $(ARCH), s390x powerpc64le))
$(error ERROR: Attestation agent does not support building with the musl libc target for s390x and ppc64le architectures!)
endif
MUSL_ADD := $(shell rustup target add ${ARCH}-unknown-linux-musl)
ifeq ($(DEBIANOS), true)
MUSL_INSTALL := $(shell sudo apt-get install -y musl-tools)
endif
endif
ifneq ($(SOURCE_ARCH), $(ARCH))
# SOURCE_ARCH and target architecture(ARCH) are different on ppc64le
ifeq ($(SOURCE_ARCH), ppc64le)
$(info INFO: Ignore cross-compiling when SOURCE_ARCH is ppc64le)
else ifeq ($(DEBIANOS), true)
GCC_COMPILER_PACKAGE_FOR_TARGET_ARCH := gcc-$(ARCH)-linux-$(LIBC)
GCC_COMPILER_FOR_TARGET_ARCH := $(ARCH)-linux-$(LIBC)-gcc
RUSTC_TARGET_FOR_TARGET_ARCH := $(ARCH)-unknown-linux-$(LIBC)
GCC_FOR_TARGET_ARCH_INSTALL := $(shell sudo apt-get install -y ${GCC_COMPILER_PACKAGE_FOR_TARGET_ARCH})
RUST_TARGET_FOR_TARGET_ARCH_INSTALL := $(shell rustup target add ${RUSTC_TARGET_FOR_TARGET_ARCH})
RUSTFLAGS_ARGS += -C linker=$(GCC_COMPILER_FOR_TARGET_ARCH)
else
$(error ERROR: Cross-compiling is only tested on Debian-like OSes)
endif
endif
ifeq ($(SOURCE_ARCH), $(filter $(SOURCE_ARCH), s390x ppc64le))
ifeq ($(DEBIANOS), true)
PROTOC_BINARY_INSTALL := $(shell sudo apt-get install -y protobuf-compiler)
endif
endif
LIBC_FLAG := --target $(ARCH)-unknown-linux-$(LIBC)
TARGET_DIR := $(TARGET_DIR)/$(ARCH)-unknown-linux-$(LIBC)
ifdef DEBUG
release :=
TARGET_DIR := $(TARGET_DIR)/debug
else
release := --release
TARGET_DIR := $(TARGET_DIR)/release
endif
ifeq ($(KBC), eaa_kbc)
ifeq ($(LIBC), musl)
$(error ERROR: EAA KBC does not support MUSL build!)
endif
ifeq ($(ARCH), $(filter $(ARCH), s390x powerpc64le))
$(error ERROR: EAA KBC does not support s390x and ppc64le architectures!)
endif
RATS_TLS := $(shell ls /usr/local/lib/rats-tls/ 2> /dev/null)
ifeq ($(RATS_TLS),)
RATS_TLS_DOWNLOAD := $(shell cd .. && rm -rf inclavare-containers && git clone https://github.com/alibaba/inclavare-containers)
RATS_TLS_INSTALL := $(shell cd ../inclavare-containers/rats-tls && cmake -DBUILD_SAMPLES=on -H. -Bbuild && make -C build install >&2)
endif
RUSTFLAGS_ARGS += -C link-args=-Wl,-rpath,/usr/local/lib/rats-tls
endif
ifeq ($(KBC), offline_sev_kbc)
ifeq ($(ARCH), $(filter $(ARCH), s390x powerpc64le))
$(error ERROR: Offline SEV KBC does not support s390x and ppc64le architectures!)
endif
endif
ifneq ($(RUSTFLAGS_ARGS),)
RUST_FLAGS := RUSTFLAGS="$(RUSTFLAGS_ARGS)"
endif
ifdef OPENSSL
features := $(features),openssl
else
features := $(features),rust-crypto
endif
build:
cd app && $(RUST_FLAGS) cargo build $(release) --no-default-features --features "$(features)" $(LIBC_FLAG)
TARGET := $(TARGET_DIR)/$(BIN_NAME)
install:
install -D -m0755 $(TARGET) $(DESTDIR)
uninstall:
rm -f $(DESTDIR)/$(BIN_NAME)
clean:
cargo clean
help:
@echo "==========================Help========================================="
@echo "build: make [DEBUG=1] [LIBC=(musl)] [ARCH=(x86_64/s390x/ppc64le)] [KBC=xxx_kbc] [OPENSSL=1]"
@echo "install: make install [DESTDIR=/path/to/target] [LIBC=(musl)]"