/
Makefile
34 lines (27 loc) · 1.16 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
RPI_BOX=<SET_YOUR_RPI_HOST_ADDRESS>
CONTAINER_NAME=rust-arm-builder
# check if rust builder is running
RUNNING = $(shell docker ps --format '{{.Names}}' | grep -w $(CONTAINER_NAME) -m1)
# build the rust image with cross compile dependencies and runs a container in background
start-env:
ifneq ($(RUNNING), $(CONTAINER_NAME))
docker build -t rust-arm-builder .
docker run --name $(CONTAINER_NAME) --volume $(PWD):/usr/src/app --detach $(CONTAINER_NAME)
endif
# stops the docker container
stop-env:
ifeq ($(RUNNING), $(CONTAINER_NAME))
docker stop $(CONTAINER_NAME) && docker rm $(CONTAINER_NAME)
endif
# setting linker in .cargo/config doesn't seem to work
build: start-env
docker exec -it $(CONTAINER_NAME) /bin/bash -c \
"RUSTFLAGS='-C linker=arm-linux-gnueabihf-gcc' cargo build --target armv7-unknown-linux-gnueabihf --release"
clean:
rm -rf target
# copy the built binary to the target machine
copy-bin: build
scp ./target/armv7-unknown-linux-gnueabihf/release/blink $(RPI_BOX):
scp ./target/armv7-unknown-linux-gnueabihf/release/switch $(RPI_BOX):
scp ./target/armv7-unknown-linux-gnueabihf/release/rgb_led $(RPI_BOX):
.PHONY: start-env stop-env build clean copy-bin