Browse Source

allow environment variables to set/extend CC, CXX, CFLAGS and LDFLAGS

Moritz Warning 10 years ago
parent
commit
235d4aba9a
3 changed files with 21 additions and 18 deletions
  1. 8 7
      make-freebsd.mk
  2. 8 7
      make-linux.mk
  3. 5 4
      make-mac.mk

+ 8 - 7
make-freebsd.mk

@@ -1,5 +1,5 @@
-CC=cc
-CXX=c++
+CC?=cc
+CXX?=c++
 
 
 INCLUDES=
 INCLUDES=
 DEFS=
 DEFS=
@@ -16,19 +16,20 @@ endif
 # "make debug" is a shortcut for this
 # "make debug" is a shortcut for this
 ifeq ($(ZT_DEBUG),1)
 ifeq ($(ZT_DEBUG),1)
 	DEFS+=-DZT_TRACE 
 	DEFS+=-DZT_TRACE 
-	CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS)
-	LDFLAGS=
+	CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
+	LDFLAGS+=
 	STRIP=echo
 	STRIP=echo
 	# The following line enables optimization for the crypto code, since
 	# The following line enables optimization for the crypto code, since
 	# C25519 in particular is almost UNUSABLE in heavy testing without it.
 	# 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 = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
 else
 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 -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS)
+	LDFLAGS+=-pie -Wl,-z,relro,-z,now
 	STRIP=strip --strip-all
 	STRIP=strip --strip-all
 endif
 endif
 
 
-CXXFLAGS=$(CFLAGS) -fno-rtti
+CXXFLAGS+=$(CFLAGS) -fno-rtti
 
 
 all:	one
 all:	one
 
 

+ 8 - 7
make-linux.mk

@@ -18,9 +18,8 @@
 #
 #
 
 
 # Automagically pick clang or gcc, with preference for clang
 # Automagically pick clang or gcc, with preference for clang
-CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
-CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
-
+CC?=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
+CXX?=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
 INCLUDES=
 INCLUDES=
 DEFS=
 DEFS=
 LIBS=
 LIBS=
@@ -43,16 +42,18 @@ endif
 # "make debug" is a shortcut for this
 # "make debug" is a shortcut for this
 ifeq ($(ZT_DEBUG),1)
 ifeq ($(ZT_DEBUG),1)
 	DEFS+=-DZT_TRACE 
 	DEFS+=-DZT_TRACE 
-	CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS)
-	CXXFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS)
+	CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
+	CXXFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
 	LDFLAGS=
 	LDFLAGS=
 	STRIP=echo
 	STRIP=echo
 	# The following line enables optimization for the crypto code, since
 	# The following line enables optimization for the crypto code, since
 	# C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
 	# C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
 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 = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
 else
 else
-	CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS)
-	CXXFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
+	CFLAGS?=-O3 -fstack-protector
+	CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
+	CXXFLAGS?=-O3 -fstack-protector
+	CXXFLAGS+=-Wall -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
 	LDFLAGS=-pie -Wl,-z,relro,-z,now
 	LDFLAGS=-pie -Wl,-z,relro,-z,now
 	STRIP=strip --strip-all
 	STRIP=strip --strip-all
 endif
 endif

+ 5 - 4
make-mac.mk

@@ -1,5 +1,5 @@
-CC=clang
-CXX=clang++
+CC?=clang
+CXX?=clang++
 
 
 INCLUDES=-I/usr/local/include
 INCLUDES=-I/usr/local/include
 DEFS=
 DEFS=
@@ -38,13 +38,14 @@ endif
 # Debug mode -- dump trace output, build binary with -g
 # Debug mode -- dump trace output, build binary with -g
 ifeq ($(ZT_DEBUG),1)
 ifeq ($(ZT_DEBUG),1)
 	DEFS+=-DZT_TRACE 
 	DEFS+=-DZT_TRACE 
-	CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS)
+	CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
 	STRIP=echo
 	STRIP=echo
 	# The following line enables optimization for the crypto code, since
 	# The following line enables optimization for the crypto code, since
 	# C25519 in particular is almost UNUSABLE in heavy testing without it.
 	# 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 = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
 else
 else
-	CFLAGS=$(ARCH_FLAGS) -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.7 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
+	CFLAGS?=-O3 -fstack-protector
+	CFLAGS+=$(ARCH_FLAGS) -Wall -flto -fPIE -fvectorize -pthread -mmacosx-version-min=10.7 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
 	STRIP=strip
 	STRIP=strip
 endif
 endif