From 2be00cdf66ab965bdb5edf5902b4ec8b83229704 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 14 Oct 2018 21:42:41 +0200 Subject: Compile and link 'libdome_key_event_source_simulator' Turn this into a build dependency with Make. Use Vladimir Matveev (https://stackoverflow.com/users/788207/vladimir-matveev) and Shepmaster's (https://stackoverflow.com/users/155423/shepmaster) answer on Stack Overflow to sort out getting Cargo the search path for the static library: https://stackoverflow.com/questions/26246849/how-to-i-tell-rust-where-to-look-for-a-static-library/26254062#26254062 For some reason I wasn't able to get it to work by just putting the library into `./target/debug/deps/`. I had to explicitly tell Cargo to put that in the search path. Also, we need to use `std::env` instead of the `env!` macro to get the `PROFILE` environment variable, otherwise it won't be initialised at the right time, as described in the Rust docs: > Because these variables are not yet set when the build script is > compiled, the above example using env! won't work and instead you'll > need to retrieve the values when the build script is run (https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts) --- Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b4e76fa..67ae18e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,13 @@ SOURCE_FILES = $(shell find src -type f -name '*.rs') LIB := target/debug/libdome_key_map.a -$(LIB): $(SOURCE_FILES) +DKESS_LIB_DEBUG := ~/Library/Developer/Xcode/DerivedData/dome_key_event_source_simulator-*/Build/Products/Debug/libdome_key_event_source_simulator.a +DKESS_LOCAL_LIB_DEBUG := target/debug/deps/libdome_key_event_source_simulator.a + +.PHONY: build +build: $(LIB) + +$(LIB): $(SOURCE_FILES) $(DKESS_LOCAL_LIB_DEBUG) cargo build includer: clean $(LIB) @@ -14,3 +20,9 @@ moder: moder.c $(LIB) .PHONY: clean clean: rm -f includer moder + +$(DKESS_LIB_DEBUG): + $(MAKE) -C lib/dome_key_event_source_simulator $@ + +$(DKESS_LOCAL_LIB_DEBUG): $(DKESS_LIB_DEBUG) + cp -a $< $@ -- cgit v1.2.3