|
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 |
| 6 | +from os import path, environ |
7 | 7 | import contextlib
|
8 | 8 | import distutils.spawn
|
9 | 9 | import os
|
@@ -450,8 +450,31 @@ def make(name, target=None, **makevars):
|
450 | 450 | execute('make', *args)
|
451 | 451 |
|
452 | 452 |
|
| 453 | +def require_header(header, symbol = False, value = False): |
| 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 | + |
| 458 | + stdin_line = '#include ' + header |
| 459 | + if symbol: |
| 460 | + if value: |
| 461 | + stdin_line += """\n#if %s != %s |
| 462 | + #error |
| 463 | + #endif """ % (symbol, value) |
| 464 | + else: |
| 465 | + stdin_line += """\n#ifndef %s |
| 466 | + #error |
| 467 | + #endif """ % (symbol) |
| 468 | + |
| 469 | + proc.communicate(stdin_line) |
| 470 | + proc.wait() |
| 471 | + |
| 472 | + if proc.returncode != 0: |
| 473 | + panic('require_header "%s" failed', header) |
| 474 | + |
| 475 | + |
453 | 476 | __all__ = ['setvar', 'panic', 'cmpver', 'find_executable', 'chmod', 'execute',
|
454 | 477 | 'rmtree', 'mkdir', 'copy', 'copytree', 'unarc', 'fetch', 'cwd',
|
455 | 478 | 'symlink', 'remove', 'move', 'find', 'textfile', 'env', 'path',
|
456 | 479 | 'add_site_dir', 'python_setup', 'recipe', 'unpack', 'patch',
|
457 |
| - 'configure', 'make'] |
| 480 | + 'configure', 'make', 'require_header'] |
0 commit comments