Skip to content

Commit

Permalink
Rename environment variables controlling the Makefile
Browse files Browse the repository at this point in the history
Prefix also `ARCH` and `PASS` with `DEVICE_` to communicate that they
refer to the architecture and password of the device under test.

Prefix all the variables with `AXIS_` to make it less likely that they
will collide with variables used differently way by other programs.
This specific prefix is chosen to align with acap-native-sdk-examples
where `AXIS_DEVICE_IP` was recently adopted as the only placeholder
name for the IP address or domain name of a camera.
  • Loading branch information
apljungquist committed Jun 17, 2024
1 parent c468ce9 commit 57a0b02
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- name: Run checks
run: |
make --always-make check_all
PACKAGE=licensekey_handler make build
PACKAGE=embedded_web_page make build
AXIS_PACKAGE=licensekey_handler make build
AXIS_PACKAGE=embedded_web_page make build
68 changes: 34 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# Name of package containing the app to be built.
# Rust does not enforce that the path to the package matches the package name, but
# this makefile does to keep things simple.
PACKAGE ?= hello_world
AXIS_PACKAGE ?= hello_world

# The architecture that will be assumed when interacting with the device.
ARCH ?= aarch64
AXIS_DEVICE_ARCH ?= aarch64

# The IP address of the device to interact with.
DEVICE_IP ?= 192.168.0.90
AXIS_DEVICE_IP ?= 192.168.0.90

# The password to use when interacting with the device.
PASS ?= pass
AXIS_DEVICE_PASS ?= pass

# Other
# -----
Expand All @@ -36,44 +36,44 @@ FORCE:;
.PHONY: FORCE

DOCKER_RUN = docker run \
--volume ${CURDIR}/target/$(ARCH)/$(PACKAGE)/:/opt/app \
--volume ${CURDIR}/target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/:/opt/app \
--user $(shell id -u):$(shell id -g) \
axisecp/acap-native-sdk:1.12-$(ARCH)-ubuntu22.04
axisecp/acap-native-sdk:1.12-$(AXIS_DEVICE_ARCH)-ubuntu22.04

## Verbs
## =====

help:
@mkhelp print_docs $(firstword $(MAKEFILE_LIST)) help

## Build <PACKAGE> for all architectures
build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
## Build <AXIS_PACKAGE> for all architectures
build: target/aarch64/$(AXIS_PACKAGE)/_envoy target/armv7hf/$(AXIS_PACKAGE)/_envoy
mkdir -p target/acap
cp $(patsubst %/_envoy,%/*.eap,$^) target/acap



## Install <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Install <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
install:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) install" \
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) install" \
| grep -v '^to start your application type$$' \
| grep -v '^ eap-install.sh start$$'

## Remove <PACKAGE> from <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Remove <AXIS_PACKAGE> from <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
remove:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) remove"
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) remove"

## Start <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Start <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
start:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) start" \
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) start" \
| grep -v '^to stop your application type$$' \
| grep -v '^ eap-install.sh stop$$'

## Stop <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Stop <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
stop:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) stop"
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) stop"

## Build and run <PACKAGE> directly on <DEVICE_IP> assuming architecture <ARCH>
## Build and run <AXIS_PACKAGE> directly on <AXIS_DEVICE_IP> assuming architecture <AXIS_DEVICE_ARCH>
##
## Forwards the following environment variables to the remote process:
##
Expand All @@ -85,10 +85,10 @@ stop:
## * The app is installed on the device.
## * The app is stopped.
## * The device has SSH enabled the ssh user root configured.
run: target/$(ARCH)/$(PACKAGE)/$(PACKAGE)
scp $< root@$(DEVICE_IP):/usr/local/packages/$(PACKAGE)/$(PACKAGE)
ssh root@$(DEVICE_IP) \
"cd /usr/local/packages/$(PACKAGE) && su - acap-$(PACKAGE) -s /bin/sh --preserve-environment -c '$(if $(RUST_LOG_STYLE),RUST_LOG_STYLE=$(RUST_LOG_STYLE) )$(if $(RUST_LOG),RUST_LOG=$(RUST_LOG) )./$(PACKAGE)'"
run: target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/$(AXIS_PACKAGE)
scp $< root@$(AXIS_DEVICE_IP):/usr/local/packages/$(AXIS_PACKAGE)/$(AXIS_PACKAGE)
ssh root@$(AXIS_DEVICE_IP) \
"cd /usr/local/packages/$(AXIS_PACKAGE) && su - acap-$(AXIS_PACKAGE) -s /bin/sh --preserve-environment -c '$(if $(RUST_LOG_STYLE),RUST_LOG_STYLE=$(RUST_LOG_STYLE) )$(if $(RUST_LOG),RUST_LOG=$(RUST_LOG) )./$(AXIS_PACKAGE)'"

## Install development dependencies
sync_env:
Expand All @@ -103,7 +103,7 @@ check_all: check_build check_docs check_format check_lint check_tests check_gene
.PHONY: check_all

## Check that all crates can be built
check_build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
check_build: target/aarch64/$(AXIS_PACKAGE)/_envoy target/armv7hf/$(AXIS_PACKAGE)/_envoy
cargo build \
--exclude licensekey \
--exclude licensekey-sys \
Expand Down Expand Up @@ -198,30 +198,30 @@ crates/%-sys/src/bindings.rs: FORCE
# * `.DELETE_ON_ERROR` does not work for directories, and
# * the name of the `.eap` file is annoying to predict.
# When building for all targets using a single image we cannot rely on wildcard matching.
target/aarch64/$(PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa53-crypto-poky-linux
target/armv7hf/$(PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa9hf-neon-poky-linux-gnueabi
target/%/$(PACKAGE)/_envoy: ARCH=$*
target/%/$(PACKAGE)/_envoy: target/%/$(PACKAGE)/$(PACKAGE) target/%/$(PACKAGE)/manifest.json target/%/$(PACKAGE)/LICENSE
target/aarch64/$(AXIS_PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa53-crypto-poky-linux
target/armv7hf/$(AXIS_PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa9hf-neon-poky-linux-gnueabi
target/%/$(AXIS_PACKAGE)/_envoy: AXIS_DEVICE_ARCH=$*
target/%/$(AXIS_PACKAGE)/_envoy: target/%/$(AXIS_PACKAGE)/$(AXIS_PACKAGE) target/%/$(AXIS_PACKAGE)/manifest.json target/%/$(AXIS_PACKAGE)/LICENSE
ifeq (0, $(shell test -e /.dockerenv; echo $$?))
. /opt/axis/acapsdk/$(ENVIRONMENT_SETUP) && cd $(@D) && acap-build --build no-build .
else
$(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && acap-build --build no-build ."
endif
touch $@

target/%/$(PACKAGE)/manifest.json: apps/$(PACKAGE)/manifest.json
target/%/$(AXIS_PACKAGE)/manifest.json: apps/$(AXIS_PACKAGE)/manifest.json
mkdir -p $(dir $@)
cp $< $@

target/%/$(PACKAGE)/LICENSE: apps/$(PACKAGE)/LICENSE
target/%/$(AXIS_PACKAGE)/LICENSE: apps/$(AXIS_PACKAGE)/LICENSE
mkdir -p $(dir $@)
cp $< $@

# The target triple and the name of the docker image do not match, so
# at some point we need to map one to the other. It might as well be here.
target/aarch64/$(PACKAGE)/_envoy: target/aarch64-unknown-linux-gnu/release/$(PACKAGE)
target/armv7hf/$(PACKAGE)/_envoy: target/thumbv7neon-unknown-linux-gnueabihf/release/$(PACKAGE)
target/%/$(PACKAGE)/_envoy: apps/$(PACKAGE)/manifest.json apps/$(PACKAGE)/LICENSE $(wildcard apps/$(PACKAGE)/otherfiles/*)
target/aarch64/$(AXIS_PACKAGE)/_envoy: target/aarch64-unknown-linux-gnu/release/$(AXIS_PACKAGE)
target/armv7hf/$(AXIS_PACKAGE)/_envoy: target/thumbv7neon-unknown-linux-gnueabihf/release/$(AXIS_PACKAGE)
target/%/$(AXIS_PACKAGE)/_envoy: apps/$(AXIS_PACKAGE)/manifest.json apps/$(AXIS_PACKAGE)/LICENSE $(wildcard apps/$(AXIS_PACKAGE)/otherfiles/*)
# Make sure we don't include any obsolete files in the `.eap`
if [ -d $(@D) ]; then rm -r $(@D); fi
mkdir -p $(@D)
Expand All @@ -230,10 +230,10 @@ target/%/$(PACKAGE)/_envoy: apps/$(PACKAGE)/manifest.json apps/$(PACKAGE)/LICENS
touch $@

# Always rebuild the executable because configuring accurate cache invalidation is annoying.
target/%/release/$(PACKAGE): FORCE
target/%/release/$(AXIS_PACKAGE): FORCE
ifeq (0, $(shell test -e /.dockerenv; echo $$?))
cargo -v build --release --target $* --package $(PACKAGE)
cargo -v build --release --target $* --package $(AXIS_PACKAGE)
else
cross -v build --release --target $* --package $(PACKAGE)
cross -v build --release --target $* --package $(AXIS_PACKAGE)
endif
touch $@ # This is a hack to make the `_envoy` target above always build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ docker run \
--volume $(pwd):$(pwd) \
--workdir $(pwd) \
acap-rs \
make build PACKAGE=hello_world
make build AXIS_PACKAGE=hello_world
```

This works with any of the [example applications](#example-applications).
Expand Down

0 comments on commit 57a0b02

Please sign in to comment.