Reputation: 590
Two question here concerning Makefile
s and storing persistent variables. I have a script that I am using to perform a build for a binary that will be deployed for a system containing two MCUs. The binary from one MCU will be fed into the binary of the other MCU for in application updates initiated by the second MCU.
Multiple developers are working on this project and building the binary for the MCU that will be inserted into the main binary is not necessary for all invloved. Also, the presence and location of the build too required for the secondary binary may vary. As such, I need to be able to find the build tool for that secondary binary if it is available. The way I do that is to run a search at the beginning of the Makefile
to find the exe and then write that location to a file to allow it to persist across multiple build attempts.
First question: is there a better way to persist that path to the build tool than writing to a file without going in and manipulating the PATH
externally (this is will be an automated build, so ...)?
Second question: I am using the following (not in a recipe) to write the value to the build tool
$(shell echo ${IAR_EXE} > iar-path)
and it is taking a long time. What might I be doing incorrectly or could I do to improve the efficiency of this call?
Edit for @kebs:
To provide context, the above is in the preamble of the make file (i.e. before recipes). Not sure if this adds anything, but here is the entire preamble:
STM32_DIR:=../../Project-STM32
LX_PROJECT:=$(STM32_DIR)/Projects/Lx/Application/Project_file/Lx.ewp
GX_PROJECT:=$(STM32_DIR)/Projects/Gx/EWARM/Gx.ewp
IAR_EXISTS=FALSE
# Check to see if the path for the IAR build tool exists...
ifeq ("$(wildcard iar-path)", "")
$(info IAR path not available, searching now...)
IAR_EXE:="$(shell find /cygdrive/c/ -name IarBuild.exe -print -quit 2>&1 | grep -v "Permission denied")"
ifneq ($(IAR_EXE),"")
# Path exists - push it to a file that might be _more_ persistent
$(info Pushing path into local file...)
$(shell echo ${IAR_EXE} > iar-path)
IAR_EXISTS:=TRUE
endif
else
# Path exists - grab it from the file
$(info IAR Path file exists...)
IAR_EXE:="$(shell cat iar-path)"
ifneq ($(IAR_EXE),"")
IAR_EXISTS=TRUE
endif
endif
Upvotes: 0
Views: 821
Reputation: 29230
I do not know a better way for persistence than files. The long time you observe is due to find
, not to echo
. If you want to optimize this try maybe, if it makes sense, to restrict the search space to just the directories where what you are looking for can possibly be, instead of the full /cygdrive/c/
.
Minor remarks:
You can remove most of the "
, they are useless (and could also become a problem if you forget them in only one side of a comparison): for make they are just another character in a text string. Example:
ifeq ($(wildcard iar-path),)
instead of:
ifeq ("$(wildcard iar-path)", "")
and:
IAR_EXE := $(shell cat iar-path)
ifneq ($(IAR_EXE),)
IAR_EXISTS = TRUE
endif
instead of:
IAR_EXE:="$(shell cat iar-path)"
ifneq ($(IAR_EXE),"")
IAR_EXISTS=TRUE
endif
You can simplify a bit your search command with:
IAR_EXE := $(shell find /cygdrive/c/ -name IarBuild.exe 2> /dev/null)
and maybe (not sure) optimize it a bit with:
IAR_EXE := $(shell find /cygdrive/c/ -type f -name IarBuild.exe 2> /dev/null)
Upvotes: 1