Makefile: Support features

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
diff --git a/Makefile b/Makefile
index 53aace9..263bfbf 100644
--- a/Makefile
+++ b/Makefile
@@ -17,8 +17,20 @@
 	@echo
 	@echo "Run 'make setup' to setup Rust to build libtock-rs."
 	@echo "Run 'make <board>' to build libtock-rs for that board"
+	@echo "    Set the FEATURES flag to enable features"
 	@echo "Run 'make test' to test any local changes you have made"
 
+check_defined = \
+    $(strip $(foreach 1,$1, \
+        $(call __check_defined,$1,$(strip $(value 2)))))
+__check_defined = \
+    $(if $(value $1),, \
+      $(error Undefined $1$(if $2, $2)))
+
+ifdef FEATURES
+	features=--features=$(FEATURES)
+endif
+
 .PHONY: setup
 setup:
 	rustup target add thumbv7em-none-eabi
@@ -42,23 +54,23 @@
 
 .PHONY: hail
 hail:
-	PLATFORM=hail cargo build --release --target=thumbv7em-none-eabi --examples
+	PLATFORM=hail cargo build --release --target=thumbv7em-none-eabi --examples $(features)
 
 .PHONY: nrf52840
 nrf52840:
-	PLATFORM=nrf52840 cargo build --release --target=thumbv7em-none-eabi --examples
+	PLATFORM=nrf52840 cargo build --release --target=thumbv7em-none-eabi --examples $(features)
 
 .PHONY: opentitan
 opentitan:
-	PLATFORM=opentitan cargo build --release --target=riscv32imc-unknown-none-elf --examples
+	PLATFORM=opentitan cargo build --release --target=riscv32imc-unknown-none-elf --examples $(features)
 
 .PHONY: hifive1
 hifive1:
-	PLATFORM=hifive1 cargo build --release --target=riscv32imac-unknown-none-elf --examples
+	PLATFORM=hifive1 cargo build --release --target=riscv32imac-unknown-none-elf --examples $(features)
 
 .PHONY: nrf52
 nrf52:
-	PLATFORM=nrf52 cargo build --release --target=thumbv7em-none-eabi --examples
+	PLATFORM=nrf52 cargo build --release --target=thumbv7em-none-eabi --examples $(features)
 
 .PHONY: clean
 clean:
diff --git a/README.md b/README.md
index ab141cb..f5d2888 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,10 @@
     PLATFORM=opentitan cargo rriscv32imc blink # For an OpenTitan board
     ```
 
+    ```bash
+    make opentitan FEATURES=alloc # Builds all examples for the OpenTitan platform, with alloc feature enabled
+    ```
+
     For an unknown platform, you may have to create your own memory layout definition. Place the layout definition file at `boards/layout_<platform>.ld` and do not forget to enhance the `tockloader_flags` dispatching section in `flash.sh`. You are welcome to create a PR, s.t. the number of supported platforms grows.
 
 ## Using libtock-rs