From a2ff468955f202dfa301cb5cf19c2027aa8c8fcc Mon Sep 17 00:00:00 2001 From: leffmann Date: Mon, 18 Jan 2016 19:14:54 +0100 Subject: [PATCH 1/2] Verify prerequisites --- common.py | 27 +++++++++++++++++++++++++-- toolchain-m68k | 8 ++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/common.py b/common.py index ba8b005..1f94a57 100644 --- a/common.py +++ b/common.py @@ -3,7 +3,7 @@ from fnmatch import fnmatch from glob import glob from logging import debug, info, error -from os import path +from os import path, environ import contextlib import distutils.spawn import os @@ -450,8 +450,31 @@ def make(name, target=None, **makevars): execute('make', *args) +def require_header(header, symbol = False, value = False): + debug('require_header "%s"', header) + cmd = environ['CC'].split() + ['-fsyntax-only', '-x', 'c', '-'] + proc = subprocess.Popen(cmd, stdin = subprocess.PIPE, env = environ) + + stdin_line = '#include ' + header + if symbol: + if value: + stdin_line += """\n#if %s != %s + #error + #endif """ % (symbol, value) + else: + stdin_line += """\n#ifndef %s + #error + #endif """ % (symbol) + + proc.communicate(stdin_line) + proc.wait() + + if proc.returncode != 0: + panic('require_header "%s" failed', header) + + __all__ = ['setvar', 'panic', 'cmpver', 'find_executable', 'chmod', 'execute', 'rmtree', 'mkdir', 'copy', 'copytree', 'unarc', 'fetch', 'cwd', 'symlink', 'remove', 'move', 'find', 'textfile', 'env', 'path', 'add_site_dir', 'python_setup', 'recipe', 'unpack', 'patch', - 'configure', 'make'] + 'configure', 'make', 'require_header'] diff --git a/toolchain-m68k b/toolchain-m68k index b302587..1d57fe3 100755 --- a/toolchain-m68k +++ b/toolchain-m68k @@ -241,6 +241,14 @@ def build(): path.join('{host}', 'bin'), environ['PATH']]) + """ + When we have a working compiler in our path, we can also check if the + required headers/libraries are present. + """ + + require_header('') + require_header('', symbol = 'NCURSES_VERSION_MAJOR', value = 5) + unpack('{m4}') configure('{m4}', '--prefix={host}') make('{m4}') From 99adc64850f9994ff57f25610b52ba0a5a947469 Mon Sep 17 00:00:00 2001 From: leffmann Date: Mon, 18 Jan 2016 22:35:50 +0100 Subject: [PATCH 2/2] Support both C and C++ headers --- common.py | 23 +++++++++++++++-------- toolchain-m68k | 5 +++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/common.py b/common.py index 1f94a57..d04c6be 100644 --- a/common.py +++ b/common.py @@ -3,7 +3,7 @@ from fnmatch import fnmatch from glob import glob from logging import debug, info, error -from os import path, environ +from os import path import contextlib import distutils.spawn import os @@ -450,12 +450,14 @@ def make(name, target=None, **makevars): execute('make', *args) -def require_header(header, symbol = False, value = False): +def require_header(header, lang, msg = '', symbol = False, value = False): debug('require_header "%s"', header) - cmd = environ['CC'].split() + ['-fsyntax-only', '-x', 'c', '-'] - proc = subprocess.Popen(cmd, stdin = subprocess.PIPE, env = environ) - stdin_line = '#include ' + header + cmd = {'c':'{cc}', 'c++':'{cxx}'}[lang] + cmd = fill_in(cmd).split() + ['-fsyntax-only', '-x', lang, '-'] + proc = subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) + + stdin_line = '#include <' + header + '>' if symbol: if value: stdin_line += """\n#if %s != %s @@ -466,11 +468,16 @@ def require_header(header, symbol = False, value = False): #error #endif """ % (symbol) - proc.communicate(stdin_line) + (result_stdout, result_stderr) = proc.communicate(stdin_line) proc.wait() - if proc.returncode != 0: - panic('require_header "%s" failed', header) + cmd = ' '.join(cmd) + + if proc.returncode == 0: + debug('output from "%s":\n%s', cmd, result_stdout) + else: + debug('error output from "%s":\n%s', cmd, result_stderr) + panic('require_header failed: %s', msg) __all__ = ['setvar', 'panic', 'cmpver', 'find_executable', 'chmod', 'execute', diff --git a/toolchain-m68k b/toolchain-m68k index 1d57fe3..75718ff 100755 --- a/toolchain-m68k +++ b/toolchain-m68k @@ -241,13 +241,14 @@ def build(): path.join('{host}', 'bin'), environ['PATH']]) + setvar(cc = environ['CC'], cxx = environ['CXX']) + """ When we have a working compiler in our path, we can also check if the required headers/libraries are present. """ - require_header('') - require_header('', symbol = 'NCURSES_VERSION_MAJOR', value = 5) + require_header('ncurses.h', 'c', 'libncurses-dev 5.x missing', 'NCURSES_VERSION_MAJOR', 5) unpack('{m4}') configure('{m4}', '--prefix={host}')