5

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

JFFIGK
  • 632
  • 1
  • 7
  • 24
  • 1
    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: https://sourceforge.net/projects/ezwinports/files/?source=navbar – MadScientist Aug 05 '18 at 19:15
  • thanks for information - I appreciate it! – JFFIGK Aug 06 '18 at 06:57

2 Answers2

7

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.
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    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 06 '18 at 07:09
  • A late warning from someone who was bitten by Powershell: there is no real "compatibility". Powershell fails e.g. to correctly parse a command line to `gcc` when you try to give a `-DTMSTMP=1553521024.52` and leaves you with the completely unintelligible error `.52 file not found`. I quit the idea of using Powershell entirely for such purposes, its just too different from a Unix shell to make compatibility a valuable target. – Vroomfondel Sep 23 '20 at 08:31
  • 2
    @Vroomfondel, yes, that behavior - a [known bug](https://github.com/PowerShell/PowerShell/issues/6291) - is unfortunate; the workaround is to quote the argument (`'-DTMSTMP=1553521024.52'`). There's another pitfall: arguments with embedded double quotes aren't passed correctly - see [this answer](https://stackoverflow.com/a/59036879/45375). On balance, PowerShell is vastly superior to other shells, but I agree that such bugs need to be fixed sooner rather than later. – mklement0 Sep 23 '20 at 13:57
4

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
JFFIGK
  • 632
  • 1
  • 7
  • 24
  • I don't use Windows much but does it work to set the `SHELL` variable to `powershell` (perhaps with an appropriate path?) – MadScientist Aug 05 '18 at 19:16
  • 1
    @MadScientist: Good suggestion, but it seems that `SHELL` is ignored altogether in this Windows port of `make`. – mklement0 Aug 06 '18 at 01:37
  • 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 06 '18 at 07:09