From c2050705543a3d96884470d5117a2f0dfc62ee27 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sun, 25 Mar 2012 07:36:37 -0700 Subject: [PATCH] Fix makefile for better GCC version determination and optimization enabling on more platforms --- makefile | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/makefile b/makefile index d349974f..6ee1e4c4 100644 --- a/makefile +++ b/makefile @@ -64,7 +64,7 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin) OSTYPE = cygwin OSNAME = windows-build endif - GCC_VERSION = $(shell $(GCC) --version /dev/null | grep GCC | awk '{ print $$3 }') + GCC_VERSION = $(shell $(GCC) -v /dev/null 2>&1 | grep 'gcc version' | awk '{ print $$3 }') LTO_EXCLUDE_VERSIONS = PCAPLIB = pcap ifeq (agcc,$(findstring agcc,$(GCC))) # Android target build? @@ -80,6 +80,8 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin) ifeq (Darwin,$(OSTYPE)) OSNAME = OSX LIBEXT = dylib + GCC_OPTIMIZERS_CMD = $(GCC) -v --help 2>&1 + GCC_WARNINGS_CMD = $(GCC) -v --help 2>&1 else ifeq (Linux,$(OSTYPE)) LIBPATH := $(sort $(foreach lib,$(shell /sbin/ldconfig -p | grep ' => /' | sed 's/^.* => //'),$(dir $(lib)))) @@ -300,31 +302,34 @@ else LDFLAGS_O = GCC_MAJOR_VERSION = $(firstword $(subst ., ,$(GCC_VERSION))) ifneq (3,$(GCC_MAJOR_VERSION)) - GCC_OPTIMIZERS = $(shell $(GCC) --help=optimizers) + ifeq (,$(GCC_OPTIMIZERS_CMD)) + GCC_OPTIMIZERS_CMD = $(GCC) --help=optimizers + endif + GCC_OPTIMIZERS = $(shell $(GCC_OPTIMIZERS_CMD)) endif ifneq (,$(findstring $(GCC_VERSION),$(LTO_EXCLUDE_VERSIONS))) NO_LTO = 1 endif - ifneq (,$(findstring inline-functions,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -finline-functions,$(GCC_OPTIMIZERS))) CFLAGS_O += -finline-functions endif - ifneq (,$(findstring gcse-after-reload,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -fgcse-after-reload,$(GCC_OPTIMIZERS))) CFLAGS_O += -fgcse-after-reload endif - ifneq (,$(findstring predictive-commoning,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -fpredictive-commoning,$(GCC_OPTIMIZERS))) CFLAGS_O += -fpredictive-commoning endif - ifneq (,$(findstring ipa-cp-clone,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -fipa-cp-clone,$(GCC_OPTIMIZERS))) CFLAGS_O += -fipa-cp-clone endif - ifneq (,$(findstring unsafe-loop-optimizations,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -funsafe-loop-optimizations,$(GCC_OPTIMIZERS))) CFLAGS_O += -fno-unsafe-loop-optimizations endif - ifneq (,$(findstring strict-overflow,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -fstrict-overflow,$(GCC_OPTIMIZERS))) CFLAGS_O += -fno-strict-overflow endif ifeq (,$(NO_LTO)) - ifneq (,$(findstring lto,$(GCC_OPTIMIZERS))) + ifneq (,$(findstring -flto,$(GCC_OPTIMIZERS))) CFLAGS_O += -flto -fwhole-program LDFLAGS_O += -flto -fwhole-program endif @@ -332,7 +337,10 @@ else BUILD_FEATURES = - compiler optimizations and no debugging support endif ifneq (3,$(GCC_MAJOR_VERSION)) - ifneq (,$(findstring unused-result,$(shell $(GCC) --help=warnings))) + ifeq (,$(GCC_WARNINGS_CMD)) + GCC_WARNINGS_CMD = $(GCC) --help=warnings + endif + ifneq (,$(findstring -Wunused-result,$(shell $(GCC_WARNINGS_CMD)))) CFLAGS_O += -Wno-unused-result endif endif