How to execute powershell/cmd commands using gnuwin32 Makefiles?
Clash Royale CLAN TAG#URR8PPP
How to execute powershell/cmd commands using gnuwin32 Makefiles?
I try to use commands like curl, rm, start in makefiles in Windows using the following makefile processor: http://gnuwin32.sourceforge.net/packages/make.htm
It does not seem to be possible, rather it seems like I am very limited with the commands. Which ways are there to extend my set of commands?
I would appreciate any help. Thanks
thanks for information - I appreciate it!
– JFFIGK
Aug 6 at 6:57
2 Answers
2
If you're content with a Windows-only solution, you can make do with invoking powershell.exe
directly from your Makefile
, as in your answer.
powershell.exe
Makefile
However, I strongly suggest avoiding Unix-like PowerShell aliases such as curl
for Invoke-WebRequest
and rm
for Remove-Item
, because while their purpose is similar in the abstract, their syntax is generally very different. Just use PowerShell's native command names to avoid ambiguity.
curl
Invoke-WebRequest
rm
Remove-Item
Note that using Shell := <default shell executable>
appears to be ignored by the Windows port of make
you link to.
Shell := <default shell executable>
make
If you want cross-platform compatibility:
either: Use WSL, which offers you a choice of Linux distros in which both make
and the standard Unix utilities are natively available - you then need neither cmd.exe
nor PowerShell.
make
cmd.exe
and/or: Use PowerShell Core and invoke your commands as follows:
pwsh -noprofile -command <your command>
SHELL := pwsh -NoProfile
MakeFile
Thanks for the further suggestions, maybe I will go with Powershell Core, because of the subjectively more intuitive command structure and because a Linux dependency (even if it is only WSL) would definitively not be appropriate at the current use case. I removed the command.
– JFFIGK
Aug 6 at 7:09
You can use the power of powershell by prefixing the corresponding commands with powershell.
Example:
.PHONY: psStuff
psStuff:
powershell <your command>
powershell curl google.de
powershell rm -r folder
powershell start yourwebsite.de
I don't use Windows much but does it work to set the
SHELL
variable to powershell
(perhaps with an appropriate path?)– MadScientist
Aug 5 at 19:16
SHELL
powershell
@MadScientist: Good suggestion, but it seems that
SHELL
is ignored altogether in this Windows port of make
.– mklement0
Aug 6 at 1:37
SHELL
make
actually, I was looking for a Windows only solution, more specifically I only wanted to break out of the limited and (undocumented?) capabilities of wingnu32. So this was a solution to that :)
– JFFIGK
Aug 6 at 7:09
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
That's a very old version of GNU make. You can build the latest version from source very easily for yourself, or you can get a newer version pre-built from Eli Zaretskii's ezwinports project: sourceforge.net/projects/ezwinports/files/?source=navbar
– MadScientist
Aug 5 at 19:15