Skip to content

Commit 99adc64

Browse files
author
leffmann
committed
Support both C and C++ headers
1 parent a2ff468 commit 99adc64

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

common.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fnmatch import fnmatch
44
from glob import glob
55
from logging import debug, info, error
6-
from os import path, environ
6+
from os import path
77
import contextlib
88
import distutils.spawn
99
import os
@@ -450,12 +450,14 @@ def make(name, target=None, **makevars):
450450
execute('make', *args)
451451

452452

453-
def require_header(header, symbol = False, value = False):
453+
def require_header(header, lang, msg = '', symbol = False, value = False):
454454
debug('require_header "%s"', header)
455-
cmd = environ['CC'].split() + ['-fsyntax-only', '-x', 'c', '-']
456-
proc = subprocess.Popen(cmd, stdin = subprocess.PIPE, env = environ)
457455

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 + '>'
459461
if symbol:
460462
if value:
461463
stdin_line += """\n#if %s != %s
@@ -466,11 +468,16 @@ def require_header(header, symbol = False, value = False):
466468
#error
467469
#endif """ % (symbol)
468470

469-
proc.communicate(stdin_line)
471+
(result_stdout, result_stderr) = proc.communicate(stdin_line)
470472
proc.wait()
471473

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)
474481

475482

476483
__all__ = ['setvar', 'panic', 'cmpver', 'find_executable', 'chmod', 'execute',

toolchain-m68k

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,14 @@ def build():
241241
path.join('{host}', 'bin'),
242242
environ['PATH']])
243243

244+
setvar(cc = environ['CC'], cxx = environ['CXX'])
245+
244246
"""
245247
When we have a working compiler in our path, we can also check if the
246248
required headers/libraries are present.
247249
"""
248250

249-
require_header('<python2.7/python.h>')
250-
require_header('<ncurses.h>', symbol = 'NCURSES_VERSION_MAJOR', value = 5)
251+
require_header('ncurses.h', 'c', 'libncurses-dev 5.x missing', 'NCURSES_VERSION_MAJOR', 5)
251252

252253
unpack('{m4}')
253254
configure('{m4}', '--prefix={host}')

0 commit comments

Comments
 (0)