Enable link time optimization

To enable link time optimization, several configures needs to be
changed:
1. Add -flto in Makefiles
2. Use C++17 to get inline constexpr
3. Use gcc-ar and gcc-ranlib to generate static library, otherwise it
   gets link errors.

Tested: Build OK and unit tests passes.

Change-Id: Ic58cbfb631c97f43c82d5669cbf6ac1ebc5e0ab9
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/Makefile.am b/Makefile.am
index fce04e0..0aadf6c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,7 +19,7 @@
 phosphor_timemanager_LDADD = libtimemanager.la
 
 generic_cxx_flags = $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
-                    $(SDBUSPLUS_CFLAGS)
+                    $(SDBUSPLUS_CFLAGS) -flto
 
 generic_ld_flags = $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
                    $(SDBUSPLUS_LIBS)
diff --git a/configure.ac b/configure.ac
index 2680788..7e7d28c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,6 +6,10 @@
 AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
 AM_SILENT_RULES([yes])
 
+# Use gcc-ar and gcc-ranlib for static libraries built with -flto
+AC_SUBST([AR], [${ac_tool_prefix}gcc-ar])
+AC_SUBST([RANLIB], [${ac_tool_prefix}gcc-ranlib])
+
 # Checks for programs
 AC_PROG_CXX
 AM_PROG_AR
@@ -53,7 +57,7 @@
 AS_IF([test "x$SDBUSPLUSPLUS" == "x"], AC_MSG_ERROR([Cannot find sdbus++]))
 
 # Checks for typedefs, structures, and compiler characteristics.
-AX_CXX_COMPILE_STDCXX_14([noext])
+AX_CXX_COMPILE_STDCXX_17([noext])
 AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
 
 # DBUS interface
diff --git a/test/Makefile.am b/test/Makefile.am
index 0c14421..a8cd3b7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -21,7 +21,7 @@
 
 test_CXXFLAGS = $(PTHREAD_CFLAGS) \
                 $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
-                $(SDBUSPLUS_CFLAGS)
+                $(SDBUSPLUS_CFLAGS) -flto
 
 test_LDFLAGS = $(GMOCK_LIBS) \
                $(GTEST_MAIN_LIBS) \