win32: search for a mingw compiler under several names
authorH. Peter Anvin <hpa@zytor.com>
Thu, 17 Jul 2008 00:01:33 +0000 (17:01 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 17 Jul 2008 00:01:33 +0000 (17:01 -0700)
Search for the MinGW compiler under several names, since different
distros like to install it under different names.  What's wrong with a
simple mingw- prefix??

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
win32/Makefile
win32/find-mingw.sh [new file with mode: 0755]

index fe94d1e..9ea9643 100644 (file)
 
 OSTYPE   = $(shell uname -msr)
 ifeq ($(findstring CYGWIN,$(OSTYPE)),CYGWIN)
-WINCC       = gcc
-WINAR      = ar
-WINRANLIB   = ranlib
-WINCFLAGS   = -mno-cygwin -W -Wall -Os -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
-WINPIC     =
-WINLDFLAGS  = -mno-cygwin -Os -s
+## Compiling on Cygwin
+WINPREFIX  :=
+WINCFLAGS  := -mno-cygwin -W -Wall -Os -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
+WINLDFLAGS := -mno-cygwin -Os -s
 else
+## Compiling on some variant of MinGW
 ifeq ($(findstring MINGW32,$(OSTYPE)),MINGW32)
-WINCC       = gcc
-WINAR      = ar
-WINRANLIB   = ranlib
+WINPREFIX  :=
 else
-WINCC       = i386-mingw32-gcc
-WINAR      = i386-mingw32-ar
-WINRANLIB   = i386-mingw32-ranlib
+WINPREFIX  := $(shell find-mingw.sh gcc)
 endif
-
-WINCFLAGS   = -W -Wall -Wno-sign-compare -Os -fomit-frame-pointer \
-       -D_FILE_OFFSET_BITS=64
-WINPIC      =
-WINLDFLAGS  = -Os -s
+WINCFLAGS  := -W -Wall -Wno-sign-compare -Os -fomit-frame-pointer \
+             -D_FILE_OFFSET_BITS=64
+WINLDFLAGS := -Os -s
 endif
 WINCFLAGS += -I. -I.. -I../libfat -I../libinstaller
 
+WINCC      := $(WINPREFIX)gcc
+WINAR     := $(WINPREFIX)ar
+WINRANLIB  := $(WINPREFIX)ranlib
+
 WINCC_IS_GOOD := $(shell $(WINCC) $(WINCFLAGS) $(WINLDFLAGS) -o hello.exe hello.c >/dev/null 2>&1 ; echo $$?)
 
 .SUFFIXES: .c .o .i .s .S
diff --git a/win32/find-mingw.sh b/win32/find-mingw.sh
new file mode 100755 (executable)
index 0000000..59c5d31
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+cc="$1"
+
+for prefix in \
+    mingw- \
+    i386-mingw32- \
+    i486-mingw32- \
+    i586-mingw32- \
+    i686-mingw32- \
+    i386-mingw32msvc- \
+    i486-mingw32msvc- \
+    i586-mingw32msvc- \
+    i686-mingw32msvc-; do
+    if "${prefix}${cc}" -v > /dev/null 2>&1; then
+       echo "$prefix"
+       exit 0
+    fi
+done
+
+# No prefix, no idea what to do now...
+echo missing-
+exit 1