From b3a3a5ca47c8b2548c5e79cfff39c63408857397 Mon Sep 17 00:00:00 2001 From: Antony Vennard Date: Thu, 27 Feb 2020 00:02:34 +0100 Subject: [PATCH] Implement code size count from makefile. This commit uses the portable POSIX solution for counting the size of the output library (.a), namely wc -c. The output is specifically produced in the successful "end of make" message. Alternatively, one can now explicitly "make codesize". We should specifically note that: code size will depend on target architecture (x86_64 has 8-byte pointers, for example) and does not account for the extraction of the various elf-objects. That is, this code currently gives an upper bound estimate of the size INCLUDING **ELF** metadata and symbols for each and every file in the archive. A release image would strip all this information. --- mk/conf.mk | 13 +++++++++++++ mk/rules.mk | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mk/conf.mk b/mk/conf.mk index c8bac05..5a75a48 100644 --- a/mk/conf.mk +++ b/mk/conf.mk @@ -34,9 +34,18 @@ ifeq ("$(STORE)", "file") CONFIG_DEFINES += -DE4_STORE_FILE endif +# tools for specific workflows (so their location can be custom) +CLANGTIDY ?= clang-tidy + +codesize: lib + @$(eval CODESIZE=`wc -c < "$(LIB)"`) + @echo "Code size in current configuration:" + @echo "$(CODESIZE)" + .PHONY postbuild_config_echo: $(info Build Successful) + @$(eval CODESIZE=`wc -c < "$(LIB)"`) @echo "" @echo "=================================================================================" @echo "" @@ -53,5 +62,9 @@ ifeq ("$(CONF)", "all") @echo "" @echo "Shared Library: $(LIBSO)" endif + @echo "" + @echo "*** Code Size (static lib) in bytes: $(CODESIZE) ***" @echo "" @echo "=================================================================================" + + diff --git a/mk/rules.mk b/mk/rules.mk index 0acd8e0..891f918 100644 --- a/mk/rules.mk +++ b/mk/rules.mk @@ -47,7 +47,7 @@ format: clang-format -i src/*.c src/crypto/*.c include/e4/*.h include/e4/crypto/*.h include/e4/internal/*.h tidy: setup $(BUILDDIR)/include/e4config/e4_config.h - clang-tidy -checks="-*,clang-analyzer-core.*" $(SRCS) -- $(CFLAGS) $(INCLUDES) $(CONFIG_DEFINES) + $(CLANGTIDY) -checks="-*,clang-analyzer-core.*" $(SRCS) -- $(CFLAGS) $(INCLUDES) $(CONFIG_DEFINES) checksec: checksec --format=cli --file=build/all/lib/libe4.so.1.0.0