Commit 1687b152490ad414fce2d2806cdb5798299dee4f

Steffen Jaeckel 2019-09-06T16:10:44

allow the user to override {C,L,LD}FLAGS

diff --git a/etc/makefile b/etc/makefile
index ce9cf06..bad1741 100644
--- a/etc/makefile
+++ b/etc/makefile
@@ -1,4 +1,5 @@
-CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
+LTM_CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
+LTM_CFLAGS += $(CFLAGS)
 
 # default lib name (requires install with root)
 # LIBNAME=-ltommath
@@ -8,31 +9,31 @@ LIBNAME=../libtommath.a
 
 #provable primes
 pprime: pprime.o
-	$(CC) $(CFLAGS) pprime.o $(LIBNAME) -o pprime
+	$(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
 
 # portable [well requires clock()] tuning app
 tune: tune.o
-	$(CC) $(CFLAGS) tune.o $(LIBNAME) -o tune
+	$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
 	./tune_it.sh
 
 test_standalone: tune.o
 	# The benchmark program works as a testtool, too
-	$(CC) $(CFLAGS) tune.o $(LIBNAME) -o test
+	$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o test
 
 # spits out mersenne primes
 mersenne: mersenne.o
-	$(CC) $(CFLAGS) mersenne.o $(LIBNAME) -o mersenne
+	$(CC) $(LTM_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
 
 # finds DR safe primes for the given config
 drprime: drprime.o
-	$(CC) $(CFLAGS) drprime.o $(LIBNAME) -o drprime
+	$(CC) $(LTM_CFLAGS) drprime.o $(LIBNAME) -o drprime
 
 # finds 2k safe primes for the given config
 2kprime: 2kprime.o
-	$(CC) $(CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
+	$(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
 
 mont: mont.o
-	$(CC) $(CFLAGS) mont.o $(LIBNAME) -o mont
+	$(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
 
 
 clean:
diff --git a/makefile b/makefile
index 8de82d1..89d2b3b 100644
--- a/makefile
+++ b/makefile
@@ -21,7 +21,7 @@ include makefile_include.mk
 ifneq ($V,1)
 	@echo "   * ${CC} $@"
 endif
-	${silent} ${CC} -c ${CFLAGS} $< -o $@
+	${silent} ${CC} -c ${LTM_CFLAGS} $< -o $@
 
 LCOV_ARGS=--directory .
 
@@ -77,11 +77,11 @@ profiled:
 #make a single object profiled library
 profiled_single:
 	perl gen.pl
-	$(CC) $(CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
-	$(CC) $(CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
+	$(CC) $(LTM_CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
+	$(CC) $(LTM_CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
 	./timing
 	rm -f *.o timing
-	$(CC) $(CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
+	$(CC) $(LTM_CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
 	$(AR) $(ARFLAGS) $(LIBNAME) mpi.o
 	ranlib $(LIBNAME)
 
@@ -96,17 +96,17 @@ uninstall:
 	rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
 
 test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
-	$(CC) $(CFLAGS) $^ $(LFLAGS) -o test
+	$(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o test
 
 .PHONY: mtest
 mtest:
-	cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LFLAGS) -o mtest
+	cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LFLAGS) -o mtest
 
 timing: $(LIBNAME) demo/timing.c
-	$(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o timing
+	$(CC) $(LTM_CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LTM_LFLAGS) -o timing
 
 tune: $(LIBNAME)
-	$(MAKE) -C etc tune
+	$(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)"
 	$(MAKE)
 
 # You have to create a file .coveralls.yml with the content "repo_token: <the token>"
diff --git a/makefile.shared b/makefile.shared
index e6bb1ef..f77b5e5 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -58,12 +58,12 @@ bn_s_mp_sqr.o bn_s_mp_sqr_fast.o bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_s
 objs: $(OBJECTS)
 
 .c.o: $(HEADERS)
-	$(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
+	$(LTCOMPILE) $(LTM_CFLAGS) $(LTM_LDFLAGS) -o $@ -c $<
 
 LOBJECTS = $(OBJECTS:.o=.lo)
 
 $(LIBNAME):  $(OBJECTS)
-	$(LTLINK) $(LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LIBTOOLFLAGS)
+	$(LTLINK) $(LTM_LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LTM_LIBTOOLFLAGS)
 
 install: $(LIBNAME)
 	install -d $(DESTDIR)$(LIBPATH)
@@ -80,17 +80,17 @@ uninstall:
 	rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
 
 test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
-	$(LTLINK) $(LDFLAGS) $^ -o test
+	$(LTLINK) $(LTM_LDFLAGS) $^ -o test
 
 .PHONY: mtest
 mtest:
-	cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LDFLAGS) -o mtest
+	cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LDFLAGS) -o mtest
 
 timing: $(LIBNAME) demo/timing.c
-	$(LTLINK) $(CFLAGS) $(LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
+	$(LTLINK) $(LTM_CFLAGS) $(LTM_LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
 
 tune: $(LIBNAME)
-	$(LTCOMPILE) $(CFLAGS) -c etc/tune.c -o etc/tune.o
-	$(LTLINK) $(LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
+	$(LTCOMPILE) $(LTM_CFLAGS) -c etc/tune.c -o etc/tune.o
+	$(LTLINK) $(LTM_LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
 	cd etc/; /bin/sh tune_it.sh; cd ..
 	$(MAKE) -f makefile.shared
diff --git a/makefile_include.mk b/makefile_include.mk
index 9303ffc..a766343 100644
--- a/makefile_include.mk
+++ b/makefile_include.mk
@@ -47,60 +47,67 @@ else
 endif
 endif
 
-CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
+LTM_CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
 
 ifdef SANITIZER
-CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero
+LTM_CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero
 endif
 
 ifndef NO_ADDTL_WARNINGS
 # additional warnings
-CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
-CFLAGS += -Wstrict-prototypes -Wpointer-arith
+LTM_CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
+LTM_CFLAGS += -Wstrict-prototypes -Wpointer-arith
 endif
 
 ifdef CONV_WARNINGS
-CFLAGS += -std=c89 -Wconversion -Wsign-conversion
+LTM_CFLAGS += -std=c89 -Wconversion -Wsign-conversion
 ifeq ($(CONV_WARNINGS), strict)
-CFLAGS += -DMP_USE_ENUMS -Wc++-compat
+LTM_CFLAGS += -DMP_USE_ENUMS -Wc++-compat
 endif
 else
-CFLAGS += -Wsystem-headers
+LTM_CFLAGS += -Wsystem-headers
 endif
 
 ifdef COMPILE_DEBUG
 #debug
-CFLAGS += -g3
+LTM_CFLAGS += -g3
 endif
 
 ifdef COMPILE_SIZE
 #for size
-CFLAGS += -Os
+LTM_CFLAGS += -Os
 else
 
 ifndef IGNORE_SPEED
 #for speed
-CFLAGS += -O3 -funroll-loops
+LTM_CFLAGS += -O3 -funroll-loops
 
 #x86 optimizations [should be valid for any GCC install though]
-CFLAGS  += -fomit-frame-pointer
+LTM_CFLAGS  += -fomit-frame-pointer
 endif
 
 endif # COMPILE_SIZE
 
 ifneq ($(findstring clang,$(CC)),)
-CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
+LTM_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
 endif
 ifneq ($(findstring mingw,$(CC)),)
-CFLAGS += -Wno-shadow
+LTM_CFLAGS += -Wno-shadow
 endif
 ifeq ($(PLATFORM), Darwin)
-CFLAGS += -Wno-nullability-completeness
+LTM_CFLAGS += -Wno-nullability-completeness
 endif
 ifeq ($(PLATFORM), CYGWIN)
 LIBTOOLFLAGS += -no-undefined
 endif
 
+# add in the standard FLAGS
+LTM_CFLAGS += $(CFLAGS)
+LTM_LFLAGS += $(LFLAGS)
+LTM_LDFLAGS += $(LDFLAGS)
+LTM_LIBTOOLFLAGS += $(LIBTOOLFLAGS)
+
+
 ifeq ($(PLATFORM),FreeBSD)
   _ARCH := $(shell sysctl -b hw.machine_arch)
 else
@@ -119,7 +126,7 @@ endif
 HEADERS_PUB=tommath.h
 HEADERS=tommath_private.h tommath_class.h tommath_superclass.h $(HEADERS_PUB)
 
-test_standalone: CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0
+test_standalone: LTM_CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0
 
 #LIBPATH  The directory for libtommath to be installed to.
 #INCPATH  The directory to install the header files for libtommath.
@@ -132,9 +139,9 @@ DATAPATH ?= $(PREFIX)/share/doc/libtommath/pdf
 
 #make the code coverage of the library
 #
-coverage: CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
-coverage: LFLAGS += -lgcov
-coverage: LDFLAGS += -lgcov
+coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
+coverage: LTM_LFLAGS += -lgcov
+coverage: LTM_LDFLAGS += -lgcov
 
 coverage: $(COVERAGE)
 	$(COVERAGE_APP)