Index: boinc/lib/Makefile.am
===================================================================
--- boinc.orig/lib/Makefile.am
+++ boinc/lib/Makefile.am
@@ -184,6 +184,10 @@ lib_LTLIBRARIES = libboinc.la
 libboinc_la_SOURCES = $(generic_sources) $(mac_sources) $(win_sources)
 libboinc_la_CFLAGS = $(AM_CFLAGS) $(PICFLAGS) $(PTHREAD_CFLAGS)
 libboinc_la_CXXFLAGS = $(AM_CXXFLAGS) $(PICFLAGS) $(PTHREAD_CFLAGS)
+libboinc_la_AR = gcc-ar
+libboinc_la_RANLIB = gcc-ranlib
+libboinc_a_AR = gcc-ar
+libboinc_a_RANLIB = gcc-ranlib
 libboinc_la_LDFLAGS = -version-number $(LIBBOINC_VERSION)
 if OS_FREEBSD
 libboinc_la_LDFLAGS += -lexecinfo
@@ -196,6 +200,10 @@ lib_LTLIBRARIES += libboinc_crypt.la
 libboinc_crypt_la_SOURCES = crypt.cpp
 libboinc_crypt_la_CFLAGS = $(AM_CFLAGS) $(PICFLAGS) $(PTHREAD_CFLAGS) $(SSL_CFLAGS)
 libboinc_crypt_la_CXXFLAGS = $(AM_CXXFLAGS) $(PICFLAGS) $(PTHREAD_CFLAGS) $(SSL_CXXFLAGS)
+libboinc_crypt_la_AR = gcc-ar
+libboinc_crypt_la_RANLIB = gcc-ranlib
+libboinc_crypt_a_AR = gcc-ar
+libboinc_crypt_a_RANLIB = gcc-ranlib
 libboinc_crypt_la_LDFLAGS = -version-number $(LIBBOINC_VERSION) $(SSL_LIBS) $(RSA_LIBS)
 libboinc_crypt_la_LIBADD = $(LIBBOINC)
 endif
@@ -206,6 +214,10 @@ lib_LTLIBRARIES += libboinc_fcgi.la
 libboinc_fcgi_la_SOURCES = $(libfcgi_sources) $(mac_sources) $(win_sources)
 libboinc_fcgi_la_CFLAGS = -D_USING_FCGI_ $(AM_CFLAGS) $(PICFLAGS) $(PTHREAD_CFLAGS)
 libboinc_fcgi_la_CXXFLAGS = -D_USING_FCGI_ $(AM_CXXFLAGS) $(PICFLAGS) $(PTHREAD_CFLAGS)
+libboinc_fcgi_la_AR = gcc-ar
+libboinc_fcgi_la_RANLIB = gcc-ranlib
+libboinc_fcgi_a_AR = gcc-ar
+libboinc_fcgi_a_RANLIB = gcc-ranlib
 libboinc_fcgi_la_LDFLAGS = -version-number $(LIBBOINC_VERSION)
 libboinc_fcgi_la_LIBADD =
 endif
@@ -269,7 +281,7 @@ msg_test_CXXFLAGS = $(PTHREAD_CFLAGS)
 msg_test_LDADD = $(LIBBOINC)
 crypt_prog_SOURCES = crypt_prog.cpp
 crypt_prog_CXXFLAGS = $(PTHREAD_CFLAGS) $(SSL_CXXFLAGS)
-crypt_prog_LDADD = $(LIBBOINC_CRYPT_STATIC) $(LIBBOINC) $(SSL_LIBS)
+crypt_prog_LDADD = $(LIBBOINC_CRYPT) $(LIBBOINC) $(SSL_LIBS)
 parse_test_SOURCES = parse_test.cpp
 parse_test_CXXFLAGS = $(PTHREAD_CFLAGS)
 parse_test_LDADD = $(LIBBOINC)
Index: boinc/samples/condor/Makefile
===================================================================
--- boinc.orig/samples/condor/Makefile
+++ boinc/samples/condor/Makefile
@@ -41,6 +41,8 @@ else
   CURL_EXTRA_LDFLAGS ?= -lz -ldl
 endif
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = boinc_gahp
 
 all: $(PROGS)
Index: boinc/samples/multi_thread/Makefile
===================================================================
--- boinc.orig/samples/multi_thread/Makefile
+++ boinc/samples/multi_thread/Makefile
@@ -29,6 +29,8 @@ CXXFLAGS += -g \
     -L$(BOINC_LIB_DIR) \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = multi_thread
 
 all: $(PROGS)
Index: boinc/samples/sleeper/Makefile
===================================================================
--- boinc.orig/samples/sleeper/Makefile
+++ boinc/samples/sleeper/Makefile
@@ -30,6 +30,8 @@ CXXFLAGS += -g \
     -L$(BOINC_LIB_DIR) \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = sleeper
 
 all: $(PROGS)
Index: boinc/samples/vboxmonitor/Makefile
===================================================================
--- boinc.orig/samples/vboxmonitor/Makefile
+++ boinc/samples/vboxmonitor/Makefile
@@ -31,6 +31,8 @@ CXXFLAGS += -g \
     -L$(BOINC_LIB_DIR) \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = vboxmonitor
 
 all: $(PROGS)
Index: boinc/samples/vboxwrapper/Makefile
===================================================================
--- boinc.orig/samples/vboxwrapper/Makefile
+++ boinc/samples/vboxwrapper/Makefile
@@ -41,6 +41,8 @@ CXXFLAGS += -g \
     -L$(BOINC_LIB_DIR) \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = vboxwrapper$(VBOXWRAPPER_RELEASE_SUFFIX)
 
 HEADERS = vbox_common.h vboxjob.h vbox_vboxmanage.h vboxwrapper.h
Index: boinc/samples/worker/Makefile
===================================================================
--- boinc.orig/samples/worker/Makefile
+++ boinc/samples/worker/Makefile
@@ -21,7 +21,7 @@ distclean:
 	rm -f $(PROGS) $(addsuffix .exe, $(PROGS)) *.o
 
 worker$(WORKER_RELEASE_SUFFIX): worker.o
-	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o worker$(WORKER_RELEASE_SUFFIX) worker.o
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -static -o worker$(WORKER_RELEASE_SUFFIX) worker.o
 
 install: all
 
Index: boinc/samples/wrapper/Makefile
===================================================================
--- boinc.orig/samples/wrapper/Makefile
+++ boinc/samples/wrapper/Makefile
@@ -42,6 +42,8 @@ CXXFLAGS += -g -O0 \
     -L$(BOINC_ZIP_DIR) \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = wrapper$(WRAPPER_RELEASE_SUFFIX)
 
 all: $(PROGS)
Index: boinc/samples/wrappture/Makefile
===================================================================
--- boinc.orig/samples/wrappture/Makefile
+++ boinc/samples/wrappture/Makefile
@@ -35,6 +35,8 @@ CXXFLAGS += -g \
     -L$(VCPKG_DIR)/lib \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 PROGS = wrappture_example fermi
 
 all: $(PROGS)
Index: boinc/samples/example_app/Makefile
===================================================================
--- boinc.orig/samples/example_app/Makefile
+++ boinc/samples/example_app/Makefile
@@ -35,6 +35,8 @@ CXXFLAGS += -g \
     -L/usr/X11R6/lib \
     -L.
 
+LDFLAGS := -static $(LDFLAGS)
+
 # to get the graphics app to compile you may need to install some packages
 # e.g. ftgl-devel.x86_64
 #
@@ -117,7 +119,7 @@ uc2_graphics: uc2_graphics.o ttfont.o li
     $(LIBFTGL) $(LIBGL) $(LIBUI) -lm
 
 slide_show: slide_show.o $(MAKEFILE_STDLIB) $(BOINC_LIB_DIR)/libboinc.a $(BOINC_API_DIR)/libboinc_graphics2.a
-	$(CXX) $(CXXFLAGS) -o slide_show slide_show.o $(MAKEFILE_LDFLAGS) \
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -pthread -o slide_show slide_show.o $(MAKEFILE_LDFLAGS) \
 	$(MINGW_ZIP_FIX) \
 	$(BOINC_API_DIR)/libboinc_graphics2.a \
 	$(BOINC_API_DIR)/libboinc_api.a \
Index: boinc/api/Makefile.am
===================================================================
--- boinc.orig/api/Makefile.am
+++ boinc/api/Makefile.am
@@ -46,6 +46,10 @@ lib_LTLIBRARIES = libboinc_api.la
 libboinc_api_la_SOURCES = $(api_files)
 libboinc_api_la_LDFLAGS = -version-number $(LIBBOINC_VERSION) -lpthread
 libboinc_api_la_LIBADD = -L../lib/.libs $(LIBBOINC)
+libboinc_api_la_AR = gcc-ar
+libboinc_api_la_RANLIB = gcc-ranlib
+libboinc_api_a_AR = gcc-ar
+libboinc_api_a_RANLIB = gcc-ranlib
 
 if BUILD_GRAPHICS_API
 lib_LTLIBRARIES += libboinc_graphics2.la
@@ -54,6 +58,10 @@ libboinc_graphics2_la_SOURCES = $(graphi
 libboinc_graphics2_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/samples/image_libs
 libboinc_graphics2_la_LDFLAGS = -version-number $(LIBBOINC_VERSION) -ljpeg
 libboinc_graphics2_la_LIBADD = -L../lib/.libs $(APPLIBS)
+libboinc_graphics2_la_AR = gcc-ar
+libboinc_graphics2_la_RANLIB = gcc-ranlib
+libboinc_graphics2_a_AR = gcc-ar
+libboinc_graphics2_a_RANLIB = gcc-ranlib
 endif #BUILD_GRAPHICS_API
 
 lib_LTLIBRARIES += libboinc_opencl.la
Index: boinc/zip/Makefile.am
===================================================================
--- boinc.orig/zip/Makefile.am
+++ boinc/zip/Makefile.am
@@ -64,6 +64,10 @@ lib_LTLIBRARIES = libboinc_zip.la
 libboinc_zip_la_SOURCES = $(libboinc_zip_sources)
 libboinc_zip_la_LDFLAGS = -version-number $(LIBBOINC_VERSION)
 libboinc_zip_la_LIBADD = $(LIBBOINC)
+libboinc_zip_la_AR = gcc-ar
+libboinc_zip_la_RANLIB = gcc-ranlib
+libboinc_zip_a_AR = gcc-ar
+libboinc_zip_a_RANLIB = gcc-ranlib
 
 # Some OSs may not prefix libraries with lib.
 # For example OS2
Index: boinc/configure.ac
===================================================================
--- boinc.orig/configure.ac
+++ boinc/configure.ac
@@ -70,6 +70,12 @@ SAH_LINKS
 PKG_PROG_PKG_CONFIG
 PKG_INSTALLDIR
 
+dnl ------
+dnl  essential for LTO and static applications in apps and samples
+AC_PROG_RANLIB
+AM_PROG_AR
+dnl ------
+
 m4_divert_once([HELP_ENABLE],
   AS_HELP_STRING([BOINC Default enable values], [--enable-server --enable-client --enable-libraries --enable-manager: builds server, client, and libraries]))
 
Index: boinc-v2/samples/openclapp/Makefile
===================================================================
--- boinc-v2.orig/samples/openclapp/Makefile
+++ boinc-v2/samples/openclapp/Makefile
@@ -47,11 +47,11 @@
 install: openclapp
 
 openclapp: openclapp.o boinc_opencl.o libstdc++.a
-	$(CXX) $(CXXFLAGS) -o openclapp openclapp.o boinc_opencl.o \
-        libstdc++.a -lOpenCL -lboinc_api -lboinc -lpthread
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o openclapp openclapp.o boinc_opencl.o \
+        libstdc++.a -lOpenCL $(BOINC_API_DIR)/libboinc_api.a $(BOINC_LIB_DIR)/libboinc.a -lpthread
 
 openclapp.o: openclapp.cpp openclapp.hpp
-	$(CXX) $(CXXFLAGS) -c openclapp.cpp
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c openclapp.cpp
 
 boinc_opencl.o: $(BOINC_API_DIR)/boinc_opencl.cpp $(BOINC_API_DIR)/boinc_opencl.h
-	$(CXX) $(CXXFLAGS) -c $(BOINC_API_DIR)/boinc_opencl.cpp
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(BOINC_API_DIR)/boinc_opencl.cpp
