From b1c0227d5456aaf2a8b84834e076256ed14b816f Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 10 Jul 2017 11:48:05 +0200 Subject: [PATCH] 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 7bd34532..827722ba 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 529ec653..95829af5 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 a7ec0426..3cf90698 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)