Fix makefile for better GCC version determination and optimization enabling on more platforms

This commit is contained in:
Mark Pizzolato 2012-03-25 07:36:37 -07:00
parent 6e813b8364
commit c205070554

View file

@ -64,7 +64,7 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
OSTYPE = cygwin OSTYPE = cygwin
OSNAME = windows-build OSNAME = windows-build
endif 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 = LTO_EXCLUDE_VERSIONS =
PCAPLIB = pcap PCAPLIB = pcap
ifeq (agcc,$(findstring agcc,$(GCC))) # Android target build? ifeq (agcc,$(findstring agcc,$(GCC))) # Android target build?
@ -80,6 +80,8 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
ifeq (Darwin,$(OSTYPE)) ifeq (Darwin,$(OSTYPE))
OSNAME = OSX OSNAME = OSX
LIBEXT = dylib LIBEXT = dylib
GCC_OPTIMIZERS_CMD = $(GCC) -v --help 2>&1
GCC_WARNINGS_CMD = $(GCC) -v --help 2>&1
else else
ifeq (Linux,$(OSTYPE)) ifeq (Linux,$(OSTYPE))
LIBPATH := $(sort $(foreach lib,$(shell /sbin/ldconfig -p | grep ' => /' | sed 's/^.* => //'),$(dir $(lib)))) LIBPATH := $(sort $(foreach lib,$(shell /sbin/ldconfig -p | grep ' => /' | sed 's/^.* => //'),$(dir $(lib))))
@ -300,31 +302,34 @@ else
LDFLAGS_O = LDFLAGS_O =
GCC_MAJOR_VERSION = $(firstword $(subst ., ,$(GCC_VERSION))) GCC_MAJOR_VERSION = $(firstword $(subst ., ,$(GCC_VERSION)))
ifneq (3,$(GCC_MAJOR_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 endif
ifneq (,$(findstring $(GCC_VERSION),$(LTO_EXCLUDE_VERSIONS))) ifneq (,$(findstring $(GCC_VERSION),$(LTO_EXCLUDE_VERSIONS)))
NO_LTO = 1 NO_LTO = 1
endif endif
ifneq (,$(findstring inline-functions,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -finline-functions,$(GCC_OPTIMIZERS)))
CFLAGS_O += -finline-functions CFLAGS_O += -finline-functions
endif endif
ifneq (,$(findstring gcse-after-reload,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -fgcse-after-reload,$(GCC_OPTIMIZERS)))
CFLAGS_O += -fgcse-after-reload CFLAGS_O += -fgcse-after-reload
endif endif
ifneq (,$(findstring predictive-commoning,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -fpredictive-commoning,$(GCC_OPTIMIZERS)))
CFLAGS_O += -fpredictive-commoning CFLAGS_O += -fpredictive-commoning
endif endif
ifneq (,$(findstring ipa-cp-clone,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -fipa-cp-clone,$(GCC_OPTIMIZERS)))
CFLAGS_O += -fipa-cp-clone CFLAGS_O += -fipa-cp-clone
endif endif
ifneq (,$(findstring unsafe-loop-optimizations,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -funsafe-loop-optimizations,$(GCC_OPTIMIZERS)))
CFLAGS_O += -fno-unsafe-loop-optimizations CFLAGS_O += -fno-unsafe-loop-optimizations
endif endif
ifneq (,$(findstring strict-overflow,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -fstrict-overflow,$(GCC_OPTIMIZERS)))
CFLAGS_O += -fno-strict-overflow CFLAGS_O += -fno-strict-overflow
endif endif
ifeq (,$(NO_LTO)) ifeq (,$(NO_LTO))
ifneq (,$(findstring lto,$(GCC_OPTIMIZERS))) ifneq (,$(findstring -flto,$(GCC_OPTIMIZERS)))
CFLAGS_O += -flto -fwhole-program CFLAGS_O += -flto -fwhole-program
LDFLAGS_O += -flto -fwhole-program LDFLAGS_O += -flto -fwhole-program
endif endif
@ -332,7 +337,10 @@ else
BUILD_FEATURES = - compiler optimizations and no debugging support BUILD_FEATURES = - compiler optimizations and no debugging support
endif endif
ifneq (3,$(GCC_MAJOR_VERSION)) 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 CFLAGS_O += -Wno-unused-result
endif endif
endif endif