3
3
from fnmatch import fnmatch
4
4
from glob import glob
5
5
from logging import debug , info , error
6
- from os import path , environ
6
+ from os import path
7
7
import contextlib
8
8
import distutils .spawn
9
9
import os
@@ -450,12 +450,14 @@ def make(name, target=None, **makevars):
450
450
execute ('make' , * args )
451
451
452
452
453
- def require_header (header , symbol = False , value = False ):
453
+ def require_header (header , lang , msg = '' , symbol = False , value = False ):
454
454
debug ('require_header "%s"' , header )
455
- cmd = environ ['CC' ].split () + ['-fsyntax-only' , '-x' , 'c' , '-' ]
456
- proc = subprocess .Popen (cmd , stdin = subprocess .PIPE , env = environ )
457
455
458
- stdin_line = '#include ' + header
456
+ cmd = {'c' :'{cc}' , 'c++' :'{cxx}' }[lang ]
457
+ cmd = fill_in (cmd ).split () + ['-fsyntax-only' , '-x' , lang , '-' ]
458
+ proc = subprocess .Popen (cmd , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
459
+
460
+ stdin_line = '#include <' + header + '>'
459
461
if symbol :
460
462
if value :
461
463
stdin_line += """\n #if %s != %s
@@ -466,11 +468,16 @@ def require_header(header, symbol = False, value = False):
466
468
#error
467
469
#endif """ % (symbol )
468
470
469
- proc .communicate (stdin_line )
471
+ ( result_stdout , result_stderr ) = proc .communicate (stdin_line )
470
472
proc .wait ()
471
473
472
- if proc .returncode != 0 :
473
- panic ('require_header "%s" failed' , header )
474
+ cmd = ' ' .join (cmd )
475
+
476
+ if proc .returncode == 0 :
477
+ debug ('output from "%s":\n %s' , cmd , result_stdout )
478
+ else :
479
+ debug ('error output from "%s":\n %s' , cmd , result_stderr )
480
+ panic ('require_header failed: %s' , msg )
474
481
475
482
476
483
__all__ = ['setvar' , 'panic' , 'cmpver' , 'find_executable' , 'chmod' , 'execute' ,
0 commit comments