From d146102c2c24004055d863b807896a135a72e21f Mon Sep 17 00:00:00 2001 From: Alex Young Date: Wed, 26 Feb 2014 15:56:41 +0000 Subject: [PATCH] Cherry-pick extra toolchain Makefile options --- Makefile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Makefile b/Makefile index aafcecd..92b7111 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,28 @@ ifdef DEBUG else CFLAGS_EXTRA=-O2 endif +CFLAGS_EXTRA += -fPIC --std=gnu99 +LDFLAGS_EXTRA += -Wl,--relax,--gc-sections + +TOOLCHAIN := $(shell $(CC) --version|awk '/Debian/ {print "debian";exit;}') +# +# This bit adds extra flags depending of the distro, and the +# architecture. To make sure debian packages have the right +# set of 'native' flags on them +# +ifeq ($(TOOLCHAIN),debian) +DEBARCH := $(shell dpkg-architecture -qDEB_BUILD_ARCH) +ifeq ($(DEBARCH),$(filter $(DEBARCH),amd64 i386)) +CFLAGS_EXTRA += -march=native +endif +ifeq ($(DEBARCH),armhf) +CFLAGS_EXTRA += -march=armv7-a -mtune=cortex-a8 -mfpu=neon +endif +LDFLAGS_EXTRA += -L$(LIB) -Wl,-rpath,${shell readlink -f ${LIB}} +else +LDFLAGS_EXTRA += -L$(LIB) -Wl,-rpath-link,$(LIB) +endif + # The -Wunreachable-code warning is only implemented in clang, but it # doesn't break anything for gcc to see it. @@ -23,6 +45,7 @@ WARNINGS=-Wall \ CCFLAGS=-D_GNU_SOURCE=1 $(WARNINGS) $(CFLAGS_EXTRA) $(CFLAGS) LLDFLAGS=-lrt -lev $(LDFLAGS_EXTRA) $(LDFLAGS) + CC?=gcc LIBS=-lpthread @@ -31,6 +54,7 @@ COMPILE=$(CC) $(INC) -c $(CCFLAGS) SAVEDEP=$(CC) $(INC) -MM $(CCFLAGS) LINK=$(CC) $(LLDFLAGS) -Isrc $(LIBS) +LIB=build/ EXISTING_OBJS := $(wildcard build/*.o) -include $(EXISTING_OBJS:.o=.d)