To answer your question regarding spaces in file / directory names, most Makefile functions do not handle spaces in a file name, and most of them do not even respect the way \ escaping spaces.
A few variables, such as $@ , $< , $% and the wildcard function, seem to handle the escape sequence \ as space correctly, but most other variables and makefile functions, such as firstword , etc. cannot handle spaces.
Say, if you find a valid directory in a wildcard, it would be impossible to distinguish 2 valid directories in the list from one directory with spaces in the path.
If you use Make files, I would suggest avoiding as many spaces as possible.
But there are always workarounds;) Assuming you are in a * nix environment with the find and sort commands available, this seems to work.
BASE_DIR_NAME := . MATLAB_DIR := $(subst $(NULL) ,\ ,$(shell find $(BASE_DIR_PATH) -mindepth 1 -maxdepth 1 -name 'MATLAB_*.app' -type d -print | sort | head -1)) default: @echo MATLAB_DIR="$(MATLAB_DIR)" ls -l $(MATLAB_DIR) .PHONY: default
This is the directory structure and exit from the Makefile:
$ ls -l total 16 -rw-r
source share