I'm trying to create a Makefile that will work on both windows and unix-based operating systems. (For reference, the windows version of make it should work with can be found here). As part of the Makefile, I need to be able to split a path (contained in an environment variable) to get just the filename (with extension). I use the command "basename" for non-windows OS's, and am currently trying to use the Powershell command "Split-Path" to get the file name from the path on Windows. Running this command in the command line or in a make recipe gives the desired output. However, I can't get it to work so that I can capture the results of the Powershell command within the Makefile to a variable. My current setup in the Makefile to detect the operating system and get the file from the path can be seen below:
ifeq ($(OS),Windows_NT)
# Windows
# The following line doesn't capture the output as expected
FILENAME_I_WANT:=$(powershell -noprofile Split-Path $(PATH_ENVIRONMENT_VARIABLE) -leaf)
else
# Unix based OS
FILENAME_I_WANT:=$(shell basename $(PATH_ENVIRONMENT_VARIABLE))
endif
Does anyone see anything I'm doing wrong, or have any suggestions for how to fix this?
Thanks!