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?
Why are you not using the environment variables for OS, and just dot referencing the basename of the filename?
# Get the host OS $env:OS # Results <# Windows_NT #> # Get the target 5th in the folder and only show the basename ((Get-ChildItem -Path 'D:Temp')).BaseName # Results <# IEDriverServer_Win32_3.150.1 #>
Answered by postanote on December 26, 2020
8 Asked on December 31, 2020 by vegard-larsen
0 Asked on December 31, 2020 by anita
1 Asked on December 31, 2020 by james-mctiernan
1 Asked on December 30, 2020 by alex-bertens
0 Asked on December 30, 2020 by bowi
3 Asked on December 30, 2020
0 Asked on December 30, 2020 by ludwikde
1 Asked on December 30, 2020 by candle
1 Asked on December 30, 2020 by malan88
0 Asked on December 30, 2020 by suneeth
1 Asked on December 30, 2020 by billc
1 Asked on December 29, 2020 by mygz
2 Asked on December 29, 2020 by mikael
1 Asked on December 29, 2020 by some-user
1 Asked on December 29, 2020 by vlad-novakovsky
15 Asked on December 29, 2020 by peterjclaw
Get help from others!