Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 682
JFFIGK Avatar asked Jan 03 '23 01:01

JFFIGK


2 Answers

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.

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.

Note that using Shell := <default shell executable> appears to be ignored by the Windows port of make you link to.


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.

  • and/or: Use PowerShell Core and invoke your commands as follows:

    pwsh -noprofile -command <your command> 
    
    • In a cross-platform solution that uses WSL on Windows, you can simplify invocations by declaring SHELL := pwsh -NoProfile at the top of the MakeFile, after which you can invoke PowerShell (Core) commands directly.
like image 59
mklement0 Avatar answered Jan 05 '23 15:01

mklement0


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
like image 32
JFFIGK Avatar answered Jan 05 '23 15:01

JFFIGK