scons: Check for "make" when using LTO with gcc.

gcc uses "make" to parallelize LTO. If we're using gcc and make isn't
found, we have to use single threaded LTO instead. A warning will let
the user know what's happening and that they might want to correct the
situation.

Technically gcc can use the MAKE environment variable to override the
program it uses, although I assume it still has to be "make" compatible.
Given the fairly low likelihood that someone will need that override and
the fact that scons won't pipe that variable through unless we plumb it
up, we'll just ignore that for now.

Change-Id: I891b213ece2a75bd8a915ee91f4130458dab397b
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41773
Reviewed-by: Earl Ou <shunhsingou@google.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/SConstruct b/SConstruct
index cc3af90..19a5da9 100755
--- a/SConstruct
+++ b/SConstruct
@@ -360,14 +360,24 @@
     # Add the appropriate Link-Time Optimization (LTO) flags
     # unless LTO is explicitly turned off.
     if not GetOption('no_lto'):
+        # g++ uses "make" to parallelize LTO. The program can be overriden with
+        # the environment variable "MAKE", but we currently make no attempt to
+        # plumb that variable through.
+        parallelism = ''
+        if main.Detect('make'):
+            parallelism = '=%d' % GetOption('num_jobs')
+        else:
+            warning('"make" not found, link time optimization will be '
+                    'single threaded.')
+
         # Pass the LTO flag when compiling to produce GIMPLE
         # output, we merely create the flags here and only append
         # them later
-        main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
+        main['LTO_CCFLAGS'] = ['-flto%s' % parallelism]
 
         # Use the same amount of jobs for LTO as we are running
         # scons with
-        main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
+        main['LTO_LDFLAGS'] = ['-flto%s' % parallelism]
 
     main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc',
                                   '-fno-builtin-realloc', '-fno-builtin-free'])