@@ -10,6 +10,7 @@ import shutil
10
10
import string
11
11
12
12
CC = os .environ .get ('CC' , 'cc' )
13
+ CXX = os .environ .get ('CXX' , 'c++' )
13
14
14
15
root_dir = os .path .dirname (__file__ )
15
16
sys .path .insert (0 , os .path .join (root_dir , 'tools' , 'gyp' , 'pylib' ))
@@ -315,6 +316,52 @@ def pkg_config(pkg):
315
316
return (libs , cflags )
316
317
317
318
319
+ def try_check_compiler (cc , lang ):
320
+ try :
321
+ proc = subprocess .Popen (shlex .split (cc ) + ['-E' , '-P' , '-x' , lang , '-' ],
322
+ stdin = subprocess .PIPE , stdout = subprocess .PIPE )
323
+ except OSError :
324
+ return (False , False , '' , '' )
325
+
326
+ proc .stdin .write ('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
327
+ '__clang_major__ __clang_minor__ __clang_patchlevel__' )
328
+
329
+ values = (proc .communicate ()[0 ].split () + ['0' ] * 7 )[0 :7 ]
330
+ is_clang = values [0 ] == '1'
331
+ gcc_version = '%s.%s.%s' % tuple (values [1 :1 + 3 ])
332
+ clang_version = '%s.%s.%s' % tuple (values [4 :4 + 3 ])
333
+
334
+ return (True , is_clang , clang_version , gcc_version )
335
+
336
+
337
+ # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
338
+ # the version check more by accident than anything else but a more rigorous
339
+ # check involves checking the build number against a whitelist. I'm not
340
+ # quite prepared to go that far yet.
341
+ def check_compiler ():
342
+ if sys .platform == 'win32' :
343
+ return
344
+
345
+ def warn (msg ):
346
+ prefix = '\033 [1m\033 [91mWARNING\033 [0m' if os .isatty (1 ) else 'WARNING'
347
+ print ('%s: %s' % (prefix , msg ))
348
+
349
+ ok , is_clang , clang_version , gcc_version = try_check_compiler (CXX , 'c++' )
350
+ if not ok :
351
+ warn ('failed to autodetect C++ compiler version (CXX=%s)' % CXX )
352
+ elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0' :
353
+ warn ('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX )
354
+
355
+ ok , is_clang , clang_version , gcc_version = try_check_compiler (CC , 'c' )
356
+ if not ok :
357
+ warn ('failed to autodetect C compiler version (CC=%s)' % CC )
358
+ elif not is_clang and gcc_version < '4.2.0' :
359
+ # clang 3.2 is a little white lie because any clang version will probably
360
+ # do for the C bits. However, we might as well encourage people to upgrade
361
+ # to a version that is not completely ancient.
362
+ warn ('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC )
363
+
364
+
318
365
def cc_macros ():
319
366
"""Checks predefined macros using the CC command."""
320
367
@@ -882,6 +929,9 @@ def configure_intl(o):
882
929
pprint .pformat (icu_config , indent = 2 ) + '\n ' )
883
930
return # end of configure_intl
884
931
932
+ # Print a warning when the compiler is too old.
933
+ check_compiler ()
934
+
885
935
# determine the "flavor" (operating system) we're building for,
886
936
# leveraging gyp's GetFlavor function
887
937
flavor_params = {}
0 commit comments