From b1c0227d5456aaf2a8b84834e076256ed14b816f Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 10 Jul 2017 11:48:05 +0200 Subject: [PATCH 1/3] introduce LTC_CFLAGS and LTC_LDFLAGS --- makefile | 18 +++++++++--------- makefile.shared | 12 ++++++------ makefile_include.mk | 45 ++++++++++++++++++++++++--------------------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/makefile b/makefile index 7bd3453..827722b 100644 --- a/makefile +++ b/makefile @@ -39,19 +39,19 @@ include makefile_include.mk ifeq ($(COVERAGE),1) all_test: LIB_PRE = -Wl,--whole-archive all_test: LIB_POST = -Wl,--no-whole-archive -CFLAGS += -fprofile-arcs -ftest-coverage +LTC_CFLAGS += -fprofile-arcs -ftest-coverage EXTRALIBS += -lgcov endif #AES comes in two flavours... enc+dec and enc src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c - ${silent} ${CC} ${CFLAGS} -DENCRYPT_ONLY -c $< -o $@ + ${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@ .c.o: ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} ${CC} ${CFLAGS} -c $< -o $@ + ${silent} ${CC} ${LTC_CFLAGS} -c $< -o $@ $(LIBNAME): $(OBJECTS) ifneq ($V,1) @@ -67,13 +67,13 @@ timing: $(LIBNAME) $(TIMINGS) ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} $(CC) $(LDFLAGS) $(TIMINGS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING) + ${silent} $(CC) $(LTC_LDFLAGS) $(TIMINGS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING) test: $(LIBNAME) $(TOBJECTS) ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} $(CC) $(LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST) + ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST) # build the demos from a template define DEMO_template @@ -81,7 +81,7 @@ $(1): demos/$(1).o $$(LIBNAME) ifneq ($V,1) @echo " * $${CC} $$@" endif - $${silent} $$(CC) $$(CFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) + $${silent} $$(CC) $$(LTC_CFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) @@ -97,10 +97,10 @@ install_bins: .common_install_bins uninstall: .common_uninstall profile: - CFLAGS="$(CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" + LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" ./timing rm -f timing `find . -type f | grep [.][ao] | xargs` - CFLAGS="$(CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" + LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" # target that pre-processes all coverage data lcov-single-create: @@ -128,7 +128,7 @@ lcov-single: #make the code coverage of the library -coverage: CFLAGS += -fprofile-arcs -ftest-coverage +coverage: LTC_CFLAGS += -fprofile-arcs -ftest-coverage coverage: EXTRALIBS += -lgcov coverage: LIB_PRE = -Wl,--whole-archive coverage: LIB_POST = -Wl,--no-whole-archive diff --git a/makefile.shared b/makefile.shared index 529ec65..95829af 100644 --- a/makefile.shared +++ b/makefile.shared @@ -38,15 +38,15 @@ include makefile_include.mk #ciphers come in two flavours... enc+dec and enc src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c - $(LTCOMPILE) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o + $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o .c.o: - $(LTCOMPILE) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -c $< + $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $< LOBJECTS = $(OBJECTS:.o=.lo) $(LIBNAME): $(OBJECTS) - $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) + $(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) install: .common_install sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtomcrypt.pc.in > libtomcrypt.pc @@ -59,10 +59,10 @@ uninstall: .common_uninstall rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc test: $(LIBNAME) $(TOBJECTS) - $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) + $(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) timing: $(TIMINGS) $(LIBNAME) - $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS) + $(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS) # build the demos from a template define DEMO_template @@ -70,7 +70,7 @@ $(1): demos/$(1).o $$(LIBNAME) ifneq ($V,1) @echo " * $${CC} $$@" endif - $$(LT) --mode=link --tag=CC $$(CC) $$(CFLAGS) $$(CPPFLAGS) $$(LDFLAGS) $$^ $$(EXTRALIBS) -o $(1) + $$(LT) --mode=link --tag=CC $$(CC) $$(LTC_CFLAGS) $$(CPPFLAGS) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1) endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) diff --git a/makefile_include.mk b/makefile_include.mk index a7ec042..3cf9069 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -52,44 +52,44 @@ endif # by giving them as a parameter to make: # make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ... # -CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE +LTC_CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE ifdef OLD_GCC -CFLAGS += -W +LTC_CFLAGS += -W # older GCCs can't handle the "rotate with immediate" ROLc/RORc/etc macros # define this to help -CFLAGS += -DLTC_NO_ROLC +LTC_CFLAGS += -DLTC_NO_ROLC else -CFLAGS += -Wextra +LTC_CFLAGS += -Wextra # additional warnings -CFLAGS += -Wsystem-headers -Wbad-function-cast -Wcast-align -CFLAGS += -Wstrict-prototypes -Wpointer-arith -CFLAGS += -Wdeclaration-after-statement +LTC_CFLAGS += -Wsystem-headers -Wbad-function-cast -Wcast-align +LTC_CFLAGS += -Wstrict-prototypes -Wpointer-arith +LTC_CFLAGS += -Wdeclaration-after-statement endif -CFLAGS += -Wno-type-limits +LTC_CFLAGS += -Wno-type-limits ifdef LTC_DEBUG # compile for DEBUGGING (required for ccmalloc checking!!!) -CFLAGS += -g3 -DLTC_NO_ASM +LTC_CFLAGS += -g3 -DLTC_NO_ASM ifneq (,$(strip $(LTC_DEBUG))) -CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG) +LTC_CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG) else -CFLAGS += -DLTC_TEST_DBG +LTC_CFLAGS += -DLTC_TEST_DBG endif else ifdef LTC_SMALL # optimize for SIZE -CFLAGS += -Os -DLTC_SMALL_CODE +LTC_CFLAGS += -Os -DLTC_SMALL_CODE else ifndef IGNORE_SPEED # optimize for SPEED -CFLAGS += -O3 -funroll-loops +LTC_CFLAGS += -O3 -funroll-loops # add -fomit-frame-pointer. hinders debugging! -CFLAGS += -fomit-frame-pointer +LTC_CFLAGS += -fomit-frame-pointer endif endif # COMPILE_SMALL @@ -97,23 +97,26 @@ endif # COMPILE_DEBUG ifneq ($(findstring clang,$(CC)),) -CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header +LTC_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header endif ifeq ($(PLATFORM), Darwin) -CFLAGS += -Wno-nullability-completeness +LTC_CFLAGS += -Wno-nullability-completeness endif GIT_VERSION := $(shell [ -e .git ] && { printf git- ; git describe --tags --always --dirty ; } || echo $(VERSION)) ifneq ($(GIT_VERSION),) -CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" +LTC_CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" endif +LTC_CFLAGS := $(LTC_CFLAGS) $(CFLAGS) -ifneq ($(findstring -DLTC_PTHREAD,$(CFLAGS)),) -LDFLAGS += -pthread +ifneq ($(findstring -DLTC_PTHREAD,$(LTC_CFLAGS)),) +LTC_LDFLAGS += -pthread endif +LTC_LDFLAGS := $(LTC_LDFLAGS) $(LDFLAGS) + #List of demo objects DSOURCES = $(wildcard demos/*.c) DOBJECTS = $(DSOURCES:.c=.o) @@ -340,8 +343,8 @@ src/hashes/sha2/sha512_224.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_22 src/hashes/sha2/sha512_256.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_256.c src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c -$(DOBJECTS): CFLAGS += -Itests -$(TOBJECTS): CFLAGS += -Itests +$(DOBJECTS): LTC_CFLAGS += -Itests +$(TOBJECTS): LTC_CFLAGS += -Itests #This rule makes the libtomcrypt library. library: $(LIBNAME) From a949ef5a894cd026df0c95e474496d97d30fb0d6 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 11 Jul 2017 15:37:31 +0200 Subject: [PATCH 2/3] append instead of prepend CFLAGS for the other makefiles --- makefile.mingw | 2 +- makefile.msvc | 2 +- makefile.unix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/makefile.mingw b/makefile.mingw index 0213358..4e0d1ce 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -25,7 +25,7 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath EXTRALIBS = -L../libtommath -ltommath #Compilation flags -LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itests -DLTC_SOURCE +LTC_CFLAGS = -Isrc/headers -Itests -DLTC_SOURCE $(CFLAGS) LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS) VERSION=1.18.0-rc1 diff --git a/makefile.msvc b/makefile.msvc index be1988a..de7e899 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -20,7 +20,7 @@ CFLAGS = /Ox /DUSE_LTM /DLTM_DESC /I../libtommath EXTRALIBS = ../libtommath/tommath.lib #Compilation flags -LTC_CFLAGS = $(CFLAGS) /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3 +LTC_CFLAGS = /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3 $(CFLAGS) LTC_LDFLAGS = advapi32.lib $(EXTRALIBS) VERSION=1.18.0-rc1 diff --git a/makefile.unix b/makefile.unix index 39722e8..8c437ad 100644 --- a/makefile.unix +++ b/makefile.unix @@ -37,7 +37,7 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath EXTRALIBS = ../libtommath/libtommath.a #Compilation flags -LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itests -DLTC_SOURCE +LTC_CFLAGS = -Isrc/headers -Itests -DLTC_SOURCE $(CFLAGS) LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS) VERSION=1.18.0-rc1 From a2f48578e9d070ea6b5f8788d1835a1800902c85 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 12 Jul 2017 22:48:46 +0200 Subject: [PATCH 3/3] also pre-pend -Itests --- makefile_include.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makefile_include.mk b/makefile_include.mk index 3cf9069..0f1baa7 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -343,8 +343,8 @@ src/hashes/sha2/sha512_224.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_22 src/hashes/sha2/sha512_256.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_256.c src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c -$(DOBJECTS): LTC_CFLAGS += -Itests -$(TOBJECTS): LTC_CFLAGS += -Itests +$(DOBJECTS): LTC_CFLAGS := -Itests $(LTC_CFLAGS) +$(TOBJECTS): LTC_CFLAGS := -Itests $(LTC_CFLAGS) #This rule makes the libtomcrypt library. library: $(LIBNAME)