Search code examples
windowsbashmakefilegnu-makemsys2

How to force make to use bash as a shell on Windows/MSYS2


I'm trying to recompile an application already having a windows port (so it's supposed to work)

Of course, you still need to run ./configure so you need MSYS or MSYS2.

The configure part worked well. Now when I run make -n (so it shows which rules are executed) I get:

$ make -n
if test ! -f config.h; then \
  rm -f stamp-h1; \
  make stamp-h1; \
else :; fi
! was unexpected
make: *** [config.h] Error 255

! was unexpected is the approximate translation of a french message (so it may be slightly different) but reminded me very much of the cryptic Windows batch file messages. So I suppose that make runs its command lines using windows native shell (which isn't an issue for most simple commands, but not when it relies on a bash-like shell), assumption which was confirmed by using make debug mode:

$ make -d
GNU Make 3.82
Built for i686-pc-mingw32
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
<I'll spare you that boring part then:>
Invoking recipe from Makefile:164 to update target `config.h'.
Creating temporary batch file C:\msys64\tmp\make11752-1.bat
Batch file contents:
        @echo off
        if test ! -f config.h; then   rm -f stamp-h1;   make stamp-h1; else :; fi

From the make documentation, make takes the SHELL env. variable into account.

SHELL is set to a unix-style path, but I've tried to change it with $ export SHELL="C:/msys64/usr/bin/bash.exe" to reflect native windows path (make may not be MSYS2 aware) but to no avail)

So how to tell make to use bash shell instead of the Windows shell ?


Solution

  • Built for i686-pc-mingw32

    That line means you are using the wrong version of GNU Make. You are using one that is built for the MinGW runtime instead of one built for the MSYS2 runtime (a fork of Cygwin).

    Make sure you run pacman -S make to install the proper version of GNU Make, and then run which make and make sure it returns /usr/bin/make. The new make should identify itself as something like "Built for x86_64-pc-msys".