| 1 |
""" The ffi for rpython |
| 2 |
""" |
| 3 |
|
| 4 |
from rpython.rtyper.lltypesystem import rffi, lltype |
| 5 |
from rpython.rtyper.tool import rffi_platform |
| 6 |
from rpython.translator.tool.cbuild import ExternalCompilationInfo |
| 7 |
|
| 8 |
def try_cflags(): |
| 9 |
yield ExternalCompilationInfo(includes=['curses.h', 'term.h']) |
| 10 |
yield ExternalCompilationInfo(includes=['curses.h', 'term.h'], |
| 11 |
include_dirs=['/usr/include/ncurses']) |
| 12 |
yield ExternalCompilationInfo(includes=['curses.h', 'term.h'], |
| 13 |
include_dirs=['/usr/include/ncursesw']) |
| 14 |
yield ExternalCompilationInfo(includes=['ncurses/curses.h', |
| 15 |
'ncurses/term.h']) |
| 16 |
|
| 17 |
def try_ldflags(): |
| 18 |
yield ExternalCompilationInfo(libraries=['curses', 'tinfo']) |
| 19 |
yield ExternalCompilationInfo(libraries=['curses']) |
| 20 |
yield ExternalCompilationInfo(libraries=['ncurses', 'tinfo']) |
| 21 |
yield ExternalCompilationInfo(libraries=['ncurses']) |
| 22 |
yield ExternalCompilationInfo(libraries=['ncurses'], |
| 23 |
library_dirs=['/usr/lib64']) |
| 24 |
yield ExternalCompilationInfo(libraries=['ncursesw'], |
| 25 |
library_dirs=['/usr/lib64']) |
| 26 |
|
| 27 |
def try_tools(): |
| 28 |
try: |
| 29 |
yield ExternalCompilationInfo.from_config_tool("ncursesw6-config") |
| 30 |
except Exception: |
| 31 |
pass |
| 32 |
try: |
| 33 |
yield ExternalCompilationInfo.from_config_tool("ncurses5-config") |
| 34 |
except Exception: |
| 35 |
pass |
| 36 |
try: |
| 37 |
yield ExternalCompilationInfo.from_pkg_config("ncursesw") |
| 38 |
except Exception: |
| 39 |
pass |
| 40 |
try: |
| 41 |
yield ExternalCompilationInfo.from_pkg_config("ncursesw") |
| 42 |
except Exception: |
| 43 |
pass |
| 44 |
|
| 45 |
def try_eci(): |
| 46 |
for eci in try_tools(): |
| 47 |
yield eci.merge(ExternalCompilationInfo(includes=['curses.h', |
| 48 |
'term.h'])) |
| 49 |
for eci1 in try_cflags(): |
| 50 |
for eci2 in try_ldflags(): |
| 51 |
yield eci1.merge(eci2) |
| 52 |
|
| 53 |
def guess_eci(): |
| 54 |
for eci in try_eci(): |
| 55 |
class CConfig: |
| 56 |
_compilation_info_ = eci |
| 57 |
HAS = rffi_platform.Has("setupterm") |
| 58 |
if rffi_platform.configure(CConfig)['HAS']: |
| 59 |
return eci |
| 60 |
raise ImportError("failed to guess where ncurses is installed. " |
| 61 |
"You might need to install libncurses5-dev or similar.") |
| 62 |
|
| 63 |
eci = guess_eci() |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
include_lines = '\n'.join(['#include <%s>' % _incl for _incl in eci.includes]) |
| 73 |
eci = eci.copy_without('includes') |
| 74 |
|
| 75 |
|
| 76 |
eci = eci.merge(ExternalCompilationInfo( |
| 77 |
post_include_bits=[ |
| 78 |
"RPY_EXTERN int rpy_curses_setupterm(char *, int, int *);\n" |
| 79 |
"RPY_EXTERN char *rpy_curses_tigetstr(char *);\n" |
| 80 |
"RPY_EXTERN char *rpy_curses_tparm(char *, int, int, int, int," |
| 81 |
" int, int, int, int, int);" |
| 82 |
], |
| 83 |
separate_module_sources=[""" |
| 84 |
|
| 85 |
%(include_lines)s |
| 86 |
|
| 87 |
RPY_EXTERN |
| 88 |
int rpy_curses_setupterm(char *t, int fd, int *errret) { |
| 89 |
return setupterm(t, fd, errret); |
| 90 |
} |
| 91 |
|
| 92 |
RPY_EXTERN |
| 93 |
char *rpy_curses_tigetstr(char *capname) |
| 94 |
{ |
| 95 |
char *res = tigetstr(capname); |
| 96 |
if (res == (char *)-1) |
| 97 |
res = NULL; |
| 98 |
return res; |
| 99 |
} |
| 100 |
|
| 101 |
RPY_EXTERN |
| 102 |
char *rpy_curses_tparm(char *str, int x0, int x1, int x2, int x3, |
| 103 |
int x4, int x5, int x6, int x7, int x8) |
| 104 |
{ |
| 105 |
return tparm(str, x0, x1, x2, x3, x4, x5, x6, x7, x8); |
| 106 |
} |
| 107 |
|
| 108 |
""" % globals()])) |
| 109 |
|
| 110 |
|
| 111 |
setupterm = rffi.llexternal( |
| 112 |
"rpy_curses_setupterm", [rffi.CCHARP, rffi.INT_real, rffi.INT_realP], |
| 113 |
rffi.INT, compilation_info=eci) |
| 114 |
|
| 115 |
rpy_curses_tigetstr = rffi.llexternal( |
| 116 |
"rpy_curses_tigetstr", [rffi.CCHARP], rffi.CCHARP, |
| 117 |
compilation_info=eci) |
| 118 |
|
| 119 |
rpy_curses_tparm = rffi.llexternal( |
| 120 |
"rpy_curses_tparm", [rffi.CCHARP, rffi.INT, rffi.INT, rffi.INT, rffi.INT, |
| 121 |
rffi.INT, rffi.INT, rffi.INT, rffi.INT, rffi.INT], |
| 122 |
rffi.CCHARP, |
| 123 |
compilation_info=eci) |