From 5505161d8bc58964fab46be33c456ae753e9280e Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Thu, 22 Jan 2015 22:24:39 +0100 Subject: [PATCH] allow environment variables to set/extend CC, CXX, CFLAGS and LDFLAGS --- make-freebsd.mk | 18 ++++++++++-------- make-linux.mk | 18 ++++++++++-------- make-mac.mk | 14 ++++++++------ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/make-freebsd.mk b/make-freebsd.mk index 2eea8eafb..b50efa813 100644 --- a/make-freebsd.mk +++ b/make-freebsd.mk @@ -1,5 +1,5 @@ -CC=cc -CXX=c++ +CC?=cc +CXX?=c++ INCLUDES= DEFS= @@ -21,19 +21,21 @@ endif # "make debug" is a shortcut for this ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) - LDFLAGS= + CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) + LDFLAGS+= STRIP=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) - LDFLAGS=-pie -Wl,-z,relro,-z,now + CFLAGS?=-O3 -fstack-protector + CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS+=-pie -Wl,-z,relro,-z,now STRIP=strip --strip-all endif -CXXFLAGS=$(CFLAGS) -fno-rtti +CXXFLAGS?=-fno-rtti +CXXFLAGS=$(CFLAGS) all: one diff --git a/make-linux.mk b/make-linux.mk index e0951711a..9719f36a2 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -1,6 +1,6 @@ # Pick clang or gcc, with preference for clang -CC=$(shell which clang gcc cc 2>/dev/null | head -n 1) -CXX=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1) +CC?=$(shell which clang gcc cc 2>/dev/null | head -n 1) +CXX?=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1) INCLUDES= DEFS= @@ -22,15 +22,16 @@ endif # "make debug" is a shortcut for this ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) - LDFLAGS= + CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) + LDFLAGS+= STRIP=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) - LDFLAGS=-pie -Wl,-z,relro,-z,now + CFLAGS?=-O3 -fstack-protector + CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS+=-pie -Wl,-z,relro,-z,now STRIP=strip --strip-all endif @@ -39,7 +40,8 @@ endif #LDFLAGS= #STRIP=echo -CXXFLAGS=$(CFLAGS) -fno-rtti +CXXFLAGS?=-fno-rtti +CXXFLAGS+=$(CFLAGS) all: one diff --git a/make-mac.mk b/make-mac.mk index 854990bb9..c9e05c5a4 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -1,5 +1,5 @@ -CC=clang -CXX=clang++ +CC?=clang +CXX?=clang++ INCLUDES= DEFS= @@ -27,17 +27,19 @@ endif ifeq ($(ZT_DEBUG),1) # DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) + CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) STRIP=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS?=-O2 CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) else - CFLAGS=-arch i386 -arch x86_64 -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) + CFLAGS?=-O3 -fstack-protector + CFLAGS+=-arch i386 -arch x86_64 -Wall -flto -fPIE -fvectorize -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) STRIP=strip endif -CXXFLAGS=$(CFLAGS) -fno-rtti +CXXFLAGS?=-fno-rtti +CXXFLAGS=$(CFLAGS) all: one