I think this is an easy cut-in. Something like below, which looks for the 'lean' MAKECMDGOALS and adds the appropriate flags.
Below are the results I am seeing on OS X 10.9, but there's nothing surprising about the results. cryptest.exe does not really have an opportunity to discard anything because it tries to exercise everything :) And libcryptopp.{so|dylib} can't really discard much of anything because it may be needed.
However, when we compile and link a smaller program like:
int main( int, char** ) {
Integer j("100000000000000000000000000000000");
j %= 1999;
cout << "j: " << j << endl;
return 0;
}
Then we get a significant savings:
Lean:
$ ls -l integer.exe
-rwx------ 1 jwalton staff 162012 Jan 4 13:00 integer.exe
Normal:
$ ls -l integer.exe
-rwx------ 1 jwalton staff 2636952 Jan 4 13:02 integer.exe
*****
Lean:
$ ls -l cryptest.exe libcryptopp.dylib
-rwx------ 1 jwalton staff 9023592 Jan 4 12:51 cryptest.exe
-rwx------ 1 jwalton staff 4828076 Jan 4 12:51 libcryptopp.dylib
Normal:
$ ls -l cryptest.exe libcryptopp.dylib
-rwx------ 1 jwalton staff 9580856 Jan 4 12:45 cryptest.exe
-rwx------ 1 jwalton staff 4832404 Jan 4 12:46 libcryptopp.dylib
*****
$ cat git.diff
diff --git a/GNUmakefile b/GNUmakefile
index bf2fa54..af2b557 100755
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -155,6 +155,25 @@ endif
+# Remove dead code for lean target
+ifeq ($(findstring lean,$(MAKECMDGOALS)),lean)
+ ifeq ($(findstring -ffunction-sections,$(CXXFLAGS)),)
+ CXXFLAGS += -ffunction-sections
+ endif # CXXFLAGS
+ ifeq ($(findstring -fdata-sections,$(CXXFLAGS)),)
+ CXXFLAGS += -fdata-sections
+ endif # CXXFLAGS
+ ifneq ($(IS_DARWIN),0)
+ ifeq ($(findstring -Wl,-dead_strip,$(LDFLAGS)),)
+ LDFLAGS += -Wl,-dead_strip
+ endif
+ else # BSD, Linux and Unix
+ ifeq ($(findstring -Wl,--gc-sections,$(LDFLAGS)),)
+ LDFLAGS += -Wl,--gc-sections
+ endif
+ endif
+endif #
+
@@ -336,6 +355,9 @@ deps GNUmakefile.deps:
.PHONY: asan ubsan align aligned
asan ubsan align aligned: libcryptopp.a cryptest.exe
+.PHONY: lean
+lean: libcryptopp.a cryptest.exe
+