From 1f8090cda17785c300aa11e834ad7744cf4b9e80 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 30 Apr 2017 20:45:23 -0700 Subject: [PATCH] Makefile: set $(AR) more reliably when building with MinGW --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ce8c530..69b1de5 100644 --- a/Makefile +++ b/Makefile @@ -40,11 +40,6 @@ HARD_LINKS := 1 # Compiling for Windows with MinGW? ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),) - ifeq ($(AR),ar) - ifneq ($(findstring -mingw,$(CC)),) - AR := $(patsubst %-gcc,%-ar,$(CC)) - endif - endif STATIC_LIB_SUFFIX := .lib SHARED_LIB_SUFFIX := .dll SHARED_LIB_CFLAGS := @@ -52,6 +47,15 @@ ifneq ($(findstring -mingw,$(shell $(CC) -dumpmachine 2>/dev/null)),) PROG_CFLAGS := -static -municode HARD_LINKS := override CFLAGS := $(CFLAGS) $(call cc-option,-Wno-pedantic-ms-format) + + # If AR was not already overridden, then derive it from $(CC). + # Note that CC may take different forms, e.g. "cc", "gcc", + # "x86_64-w64-mingw32-gcc", or "x86_64-w64-mingw32-gcc-6.3.1". + # On Windows it may also have a .exe extension. + ifeq ($(AR),ar) + AR := $(shell echo $(CC) | \ + sed -E 's/g?cc(-?[0-9]+(\.[0-9]+)*)?(\.exe)?$$/ar\3/') + endif endif ##############################################################################