This commit is contained in:
Antoine Pitrou 2012-06-30 23:03:18 +02:00
commit 7f7902ce9c
15 changed files with 1876 additions and 9766 deletions

View file

@ -53,6 +53,10 @@ def get_platform ():
return 'win-ia64' return 'win-ia64'
return sys.platform return sys.platform
# Set for cross builds explicitly
if "_PYTHON_HOST_PLATFORM" in os.environ:
return os.environ["_PYTHON_HOST_PLATFORM"]
if os.name != "posix" or not hasattr(os, 'uname'): if os.name != "posix" or not hasattr(os, 'uname'):
# XXX what about the architecture? NT is Intel or Alpha, # XXX what about the architecture? NT is Intel or Alpha,
# Mac OS is M68k or PPC, etc. # Mac OS is M68k or PPC, etc.

View file

@ -138,6 +138,10 @@ if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower():
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower(): if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
_PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir)) _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
# set for cross builds
if "_PYTHON_PROJECT_BASE" in os.environ:
_PROJECT_BASE = _safe_realpath(os.environ["_PYTHON_PROJECT_BASE"])
def _is_python_source_dir(d): def _is_python_source_dir(d):
for fn in ("Setup.dist", "Setup.local"): for fn in ("Setup.dist", "Setup.local"):
if os.path.isfile(os.path.join(d, "Modules", fn)): if os.path.isfile(os.path.join(d, "Modules", fn)):
@ -673,6 +677,10 @@ def get_platform():
# Mac OS is M68k or PPC, etc. # Mac OS is M68k or PPC, etc.
return sys.platform return sys.platform
# Set for cross builds explicitly
if "_PYTHON_HOST_PLATFORM" in os.environ:
return os.environ["_PYTHON_HOST_PLATFORM"]
# Try to distinguish various flavours of Unix # Try to distinguish various flavours of Unix
osname, host, release, version, machine = os.uname() osname, host, release, version, machine = os.uname()

View file

@ -34,6 +34,7 @@ MAINCC= @MAINCC@
LINKCC= @LINKCC@ LINKCC= @LINKCC@
AR= @AR@ AR= @AR@
RANLIB= @RANLIB@ RANLIB= @RANLIB@
READELF= @READELF@
SOABI= @SOABI@ SOABI= @SOABI@
LDVERSION= @LDVERSION@ LDVERSION= @LDVERSION@
HGVERSION= @HGVERSION@ HGVERSION= @HGVERSION@
@ -193,6 +194,10 @@ LIBOBJS= @LIBOBJS@
PYTHON= python$(EXE) PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE) BUILDPYTHON= python$(BUILDEXE)
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
HOST_GNU_TYPE= @host@
# The task to run while instrument when building the profile-opt target # The task to run while instrument when building the profile-opt target
PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
#PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py #PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py
@ -445,6 +450,7 @@ build_all_generate_profile:
$(MAKE) all CFLAGS="$(CFLAGS) -fprofile-generate" LIBS="$(LIBS) -lgcov" $(MAKE) all CFLAGS="$(CFLAGS) -fprofile-generate" LIBS="$(LIBS) -lgcov"
run_profile_task: run_profile_task:
: # FIXME: can't run for a cross build
$(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK) $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK)
build_all_use_profile: build_all_use_profile:
@ -461,18 +467,17 @@ $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(BUILDPYTHON) $(SYSCONFIGDATA) platform: $(BUILDPYTHON) $(SYSCONFIGDATA)
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
# Generate the sysconfig build-time data # Generate the sysconfig build-time data
$(SYSCONFIGDATA): $(BUILDPYTHON) $(SYSCONFIGDATA): $(BUILDPYTHON)
$(RUNSHARED) ./$(BUILDPYTHON) -SE -m sysconfig --generate-posix-vars $(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars
# Build the shared modules # Build the shared modules
sharedmods: $(BUILDPYTHON) $(SYSCONFIGDATA) sharedmods: $(BUILDPYTHON) $(SYSCONFIGDATA)
@case $$MAKEFLAGS in \ case $$MAKEFLAGS in *s*) quiet=-q; esac; \
*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
esac
# Build static library # Build static library
# avoid long command lines, same as LIBRARY_OBJS # avoid long command lines, same as LIBRARY_OBJS
@ -1072,25 +1077,25 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
$(DESTDIR)$(LIBDEST)/distutils/tests ; \ $(DESTDIR)$(LIBDEST)/distutils/tests ; \
fi fi
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ $(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \ -d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST) $(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \ -d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \ -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST) $(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ $(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \ -d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \ -d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" $(PYTHON_FOR_BUILD) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
# Create the PLATDIR source directory, if one wasn't distributed.. # Create the PLATDIR source directory, if one wasn't distributed..
$(srcdir)/Lib/$(PLATDIR): $(srcdir)/Lib/$(PLATDIR):
@ -1184,7 +1189,7 @@ libainstall: all python-config
# Install the dynamically loadable modules # Install the dynamically loadable modules
# This goes into $(exec_prefix) # This goes into $(exec_prefix)
sharedinstall: sharedmods sharedinstall: sharedmods
$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \ $(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
--prefix=$(prefix) \ --prefix=$(prefix) \
--install-scripts=$(BINDIR) \ --install-scripts=$(BINDIR) \
--install-platlib=$(DESTSHARED) \ --install-platlib=$(DESTSHARED) \
@ -1256,7 +1261,7 @@ frameworkinstallextras:
# This installs a few of the useful scripts in Tools/scripts # This installs a few of the useful scripts in Tools/scripts
scriptsinstall: scriptsinstall:
SRCDIR=$(srcdir) $(RUNSHARED) \ SRCDIR=$(srcdir) $(RUNSHARED) \
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/setup.py install \ $(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \
--prefix=$(prefix) \ --prefix=$(prefix) \
--install-scripts=$(BINDIR) \ --install-scripts=$(BINDIR) \
--root=$(DESTDIR)/ --root=$(DESTDIR)/

View file

@ -42,6 +42,13 @@ Tools/Demos
* C frames that are garbage-collecting * C frames that are garbage-collecting
* C frames that are due to the invocation of a PyCFunction * C frames that are due to the invocation of a PyCFunction
Build
-----
- Issue #14330: For cross builds, don't use host python, use host search paths
for host compiler.
What's New in Python 3.3.0 Beta 1? What's New in Python 3.3.0 Beta 1?
================================== ==================================

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3203,7 +3203,8 @@ static PyObject *
dec_as_long(PyObject *dec, PyObject *context, int round) dec_as_long(PyObject *dec, PyObject *context, int round)
{ {
PyLongObject *pylong; PyLongObject *pylong;
size_t maxsize, n; digit *ob_digit;
size_t n;
Py_ssize_t i; Py_ssize_t i;
mpd_t *x; mpd_t *x;
mpd_context_t workctx; mpd_context_t workctx;
@ -3234,32 +3235,33 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
return NULL; return NULL;
} }
maxsize = mpd_sizeinbase(x, PyLong_BASE); status = 0;
if (maxsize > PY_SSIZE_T_MAX) { ob_digit = NULL;
mpd_del(x); #if PYLONG_BITS_IN_DIGIT == 30
n = mpd_qexport_u32(&ob_digit, 0, PyLong_BASE, x, &status);
#elif PYLONG_BITS_IN_DIGIT == 15
n = mpd_qexport_u16(&ob_digit, 0, PyLong_BASE, x, &status);
#else
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
#endif
if (n == SIZE_MAX) {
PyErr_NoMemory(); PyErr_NoMemory();
return NULL;
}
pylong = _PyLong_New(maxsize);
if (pylong == NULL) {
mpd_del(x); mpd_del(x);
return NULL; return NULL;
} }
status = 0; assert(n > 0);
#if PYLONG_BITS_IN_DIGIT == 30 pylong = _PyLong_New(n);
n = mpd_qexport_u32(pylong->ob_digit, maxsize, PyLong_BASE, x, &status); if (pylong == NULL) {
#elif PYLONG_BITS_IN_DIGIT == 15 mpd_free(ob_digit);
n = mpd_qexport_u16(pylong->ob_digit, maxsize, PyLong_BASE, x, &status);
#else
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
#endif
if (dec_addstatus(context, status)) {
Py_DECREF((PyObject *) pylong);
mpd_del(x); mpd_del(x);
return NULL; return NULL;
} }
memcpy(pylong->ob_digit, ob_digit, n * sizeof(digit));
mpd_free(ob_digit);
i = n; i = n;
while ((i > 0) && (pylong->ob_digit[i-1] == 0)) { while ((i > 0) && (pylong->ob_digit[i-1] == 0)) {
i--; i--;

View file

@ -583,8 +583,30 @@ _mpd_shortadd_b(mpd_uint_t *w, mpd_size_t m, mpd_uint_t v, mpd_uint_t b)
return carry; return carry;
} }
/* w := product of u (len n) and v (single word). Return carry. */
mpd_uint_t
_mpd_shortmul_c(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, mpd_uint_t v)
{
mpd_uint_t hi, lo;
mpd_uint_t carry = 0;
mpd_size_t i;
assert(n > 0);
for (i=0; i < n; i++) {
_mpd_mul_words(&hi, &lo, u[i], v);
lo = carry + lo;
if (lo < carry) hi++;
_mpd_div_words_r(&carry, &w[i], hi, lo);
}
return carry;
}
/* w := product of u (len n) and v (single word) */ /* w := product of u (len n) and v (single word) */
void mpd_uint_t
_mpd_shortmul_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, _mpd_shortmul_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
mpd_uint_t v, mpd_uint_t b) mpd_uint_t v, mpd_uint_t b)
{ {
@ -602,7 +624,8 @@ _mpd_shortmul_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
_mpd_div_words(&carry, &w[i], hi, lo, b); _mpd_div_words(&carry, &w[i], hi, lo, b);
} }
w[i] = carry;
return carry;
} }
/* /*

View file

@ -49,8 +49,10 @@ void _mpd_basemul(mpd_uint_t *w, const mpd_uint_t *u, const mpd_uint_t *v,
mpd_size_t m, mpd_size_t n); mpd_size_t m, mpd_size_t n);
void _mpd_shortmul(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, void _mpd_shortmul(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
mpd_uint_t v); mpd_uint_t v);
void _mpd_shortmul_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, mpd_uint_t _mpd_shortmul_c(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
mpd_uint_t v, mpd_uint_t b); mpd_uint_t v);
mpd_uint_t _mpd_shortmul_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
mpd_uint_t v, mpd_uint_t b);
mpd_uint_t _mpd_shortdiv(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, mpd_uint_t _mpd_shortdiv(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
mpd_uint_t v); mpd_uint_t v);
mpd_uint_t _mpd_shortdiv_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n, mpd_uint_t _mpd_shortdiv_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,

View file

@ -36,7 +36,6 @@
#include "bits.h" #include "bits.h"
#include "convolute.h" #include "convolute.h"
#include "crt.h" #include "crt.h"
#include "errno.h"
#include "memory.h" #include "memory.h"
#include "typearith.h" #include "typearith.h"
#include "umodarith.h" #include "umodarith.h"
@ -52,9 +51,6 @@
#endif #endif
#endif #endif
#if defined(__x86_64__) && defined(__GLIBC__) && !defined(__INTEL_COMPILER)
#define USE_80BIT_LONG_DOUBLE
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define ALWAYS_INLINE __forceinline #define ALWAYS_INLINE __forceinline
@ -7567,270 +7563,449 @@ finish:
/* Base conversions */ /* Base conversions */
/******************************************************************************/ /******************************************************************************/
/* /* Space needed to represent an integer mpd_t in base 'base'. */
* Returns the space needed to represent an integer mpd_t in base 'base'.
* The result is undefined for non-integers.
*
* Max space needed:
*
* base^n >= 10^(digits+exp)
* n >= log10(10^(digits+exp))/log10(base) = (digits+exp) / log10(base)
*/
size_t size_t
mpd_sizeinbase(mpd_t *a, uint32_t base) mpd_sizeinbase(const mpd_t *a, uint32_t base)
{ {
size_t x; double x;
size_t digits;
assert(mpd_isinteger(a)); assert(mpd_isinteger(a));
assert(base >= 2);
if (mpd_iszero(a)) { if (mpd_iszero(a)) {
return 1; return 1;
} }
x = a->digits+a->exp; digits = a->digits+a->exp;
assert(digits > 0);
#ifdef CONFIG_64 #ifdef CONFIG_64
#ifdef USE_80BIT_LONG_DOUBLE /* ceil(2711437152599294 / log10(2)) + 4 == 2**53 */
return (long double)x / log10(base) + 3; if (digits > 2711437152599294ULL) {
#else
/* x > floor(((1ULL<<53)-3) * log10(2)) */
if (x > 2711437152599294ULL) {
return SIZE_MAX; return SIZE_MAX;
} }
return (size_t)((double)x / log10(base) + 3);
#endif
#else /* CONFIG_32 */
{
double y = x / log10(base) + 3;
return (y > SIZE_MAX) ? SIZE_MAX : (size_t)y;
}
#endif #endif
x = (double)digits / log10(base);
return (x > SIZE_MAX-1) ? SIZE_MAX : (size_t)x + 1;
} }
/* /* Space needed to import a base 'base' integer of length 'srclen'. */
* Returns the space needed to import a base 'base' integer of length 'srclen'. static mpd_ssize_t
*/
static inline mpd_ssize_t
_mpd_importsize(size_t srclen, uint32_t base) _mpd_importsize(size_t srclen, uint32_t base)
{ {
#if SIZE_MAX == UINT64_MAX
#ifdef USE_80BIT_LONG_DOUBLE
long double x = (long double)srclen * (log10(base)/MPD_RDIGITS) + 3;
#else
double x; double x;
assert(srclen > 0);
assert(base >= 2);
#if SIZE_MAX == UINT64_MAX
if (srclen > (1ULL<<53)) { if (srclen > (1ULL<<53)) {
return MPD_SSIZE_MAX; return MPD_SSIZE_MAX;
} }
x = (double)srclen * (log10(base)/MPD_RDIGITS) + 3;
#endif
#else
double x = srclen * (log10(base)/MPD_RDIGITS) + 3;
#endif #endif
return (x > MPD_MAXIMPORT) ? MPD_SSIZE_MAX : (mpd_ssize_t)x;
x = (double)srclen * (log10(base)/MPD_RDIGITS);
return (x >= MPD_MAXIMPORT) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1;
} }
static uint8_t
mpd_resize_u16(uint16_t **w, size_t nmemb)
{
uint8_t err = 0;
*w = mpd_realloc(*w, nmemb, sizeof **w, &err);
return !err;
}
static inline size_t static uint8_t
_to_base_u16(uint16_t *w, size_t wlen, mpd_uint_t wbase, mpd_resize_u32(uint32_t **w, size_t nmemb)
mpd_uint_t *u, mpd_ssize_t ulen) {
uint8_t err = 0;
*w = mpd_realloc(*w, nmemb, sizeof **w, &err);
return !err;
}
static size_t
_baseconv_to_u16(uint16_t **w, size_t wlen, mpd_uint_t wbase,
mpd_uint_t *u, mpd_ssize_t ulen)
{ {
size_t n = 0; size_t n = 0;
assert(wlen > 0 && ulen > 0); assert(wlen > 0 && ulen > 0);
assert(wbase <= (1U<<16));
do { do {
w[n++] = (uint16_t)_mpd_shortdiv(u, u, ulen, wbase); if (n >= wlen) {
/* ulen will be at least 1. u[ulen-1] can only be zero if ulen == 1 */ if (!mpd_resize_u16(w, n+1)) {
return SIZE_MAX;
}
wlen = n+1;
}
(*w)[n++] = (uint16_t)_mpd_shortdiv(u, u, ulen, wbase);
/* ulen is at least 1. u[ulen-1] can only be zero if ulen == 1. */
ulen = _mpd_real_size(u, ulen); ulen = _mpd_real_size(u, ulen);
} while (u[ulen-1] != 0 && n < wlen); } while (u[ulen-1] != 0);
/* proper termination condition */
assert(u[ulen-1] == 0);
return n; return n;
} }
static inline void static size_t
_from_base_u16(mpd_uint_t *w, mpd_ssize_t wlen, _coeff_from_u16(mpd_t *w, mpd_ssize_t wlen,
const mpd_uint_t *u, size_t ulen, uint32_t ubase) const mpd_uint_t *u, size_t ulen, uint32_t ubase,
uint32_t *status)
{ {
mpd_ssize_t m = 1; mpd_ssize_t n = 0;
mpd_uint_t carry; mpd_uint_t carry;
assert(wlen > 0 && ulen > 0); assert(wlen > 0 && ulen > 0);
assert(ubase <= (1U<<16));
w[0] = u[--ulen]; w->data[n++] = u[--ulen];
while (--ulen != SIZE_MAX && m < wlen) { while (--ulen != SIZE_MAX) {
_mpd_shortmul(w, w, m, ubase); carry = _mpd_shortmul_c(w->data, w->data, n, ubase);
m = _mpd_real_size(w, m+1); if (carry) {
carry = _mpd_shortadd(w, m, u[ulen]); if (n >= wlen) {
if (carry) w[m++] = carry; if (!mpd_qresize(w, n+1, status)) {
return SIZE_MAX;
}
wlen = n+1;
}
w->data[n++] = carry;
}
carry = _mpd_shortadd(w->data, n, u[ulen]);
if (carry) {
if (n >= wlen) {
if (!mpd_qresize(w, n+1, status)) {
return SIZE_MAX;
}
wlen = n+1;
}
w->data[n++] = carry;
}
} }
/* proper termination condition */ return n;
assert(ulen == SIZE_MAX);
} }
/* target base wbase <= source base ubase */ /* target base wbase < source base ubase */
static inline size_t static size_t
_baseconv_to_smaller(uint32_t *w, size_t wlen, mpd_uint_t wbase, _baseconv_to_smaller(uint32_t **w, size_t wlen, uint32_t wbase,
mpd_uint_t *u, mpd_ssize_t ulen, mpd_uint_t ubase) mpd_uint_t *u, mpd_ssize_t ulen, mpd_uint_t ubase)
{ {
size_t n = 0; size_t n = 0;
assert(wlen > 0 && ulen > 0); assert(wlen > 0 && ulen > 0);
assert(wbase < ubase);
do { do {
w[n++] = (uint32_t)_mpd_shortdiv_b(u, u, ulen, wbase, ubase); if (n >= wlen) {
/* ulen will be at least 1. u[ulen-1] can only be zero if ulen == 1 */ if (!mpd_resize_u32(w, n+1)) {
return SIZE_MAX;
}
wlen = n+1;
}
(*w)[n++] = (uint32_t)_mpd_shortdiv_b(u, u, ulen, wbase, ubase);
/* ulen is at least 1. u[ulen-1] can only be zero if ulen == 1. */
ulen = _mpd_real_size(u, ulen); ulen = _mpd_real_size(u, ulen);
} while (u[ulen-1] != 0 && n < wlen); } while (u[ulen-1] != 0);
/* proper termination condition */
assert(u[ulen-1] == 0);
return n; return n;
} }
/* target base wbase >= source base ubase */ #ifdef CONFIG_32
static inline void /* target base 'wbase' == source base 'ubase' */
_baseconv_to_larger(mpd_uint_t *w, mpd_ssize_t wlen, mpd_uint_t wbase, static size_t
_copy_equal_base(uint32_t **w, size_t wlen,
const uint32_t *u, size_t ulen)
{
if (wlen < ulen) {
if (!mpd_resize_u32(w, ulen)) {
return SIZE_MAX;
}
}
memcpy(*w, u, ulen * (sizeof **w));
return ulen;
}
/* target base 'wbase' > source base 'ubase' */
static size_t
_baseconv_to_larger(uint32_t **w, size_t wlen, mpd_uint_t wbase,
const mpd_uint_t *u, size_t ulen, mpd_uint_t ubase) const mpd_uint_t *u, size_t ulen, mpd_uint_t ubase)
{ {
mpd_ssize_t m = 1; size_t n = 0;
mpd_uint_t carry; mpd_uint_t carry;
assert(wlen > 0 && ulen > 0); assert(wlen > 0 && ulen > 0);
assert(ubase < wbase);
w[0] = u[--ulen]; (*w)[n++] = u[--ulen];
while (--ulen != SIZE_MAX && m < wlen) { while (--ulen != SIZE_MAX) {
_mpd_shortmul_b(w, w, m, ubase, wbase); carry = _mpd_shortmul_b(*w, *w, n, ubase, wbase);
m = _mpd_real_size(w, m+1); if (carry) {
carry = _mpd_shortadd_b(w, m, u[ulen], wbase); if (n >= wlen) {
if (carry) w[m++] = carry; if (!mpd_resize_u32(w, n+1)) {
return SIZE_MAX;
}
wlen = n+1;
}
(*w)[n++] = carry;
}
carry = _mpd_shortadd_b(*w, n, u[ulen], wbase);
if (carry) {
if (n >= wlen) {
if (!mpd_resize_u32(w, n+1)) {
return SIZE_MAX;
}
wlen = n+1;
}
(*w)[n++] = carry;
}
} }
/* proper termination condition */ return n;
assert(ulen == SIZE_MAX);
} }
/* target base wbase < source base ubase */
/* static size_t
* Converts an integer mpd_t to a multiprecision integer with _coeff_from_larger_base(mpd_t *w, size_t wlen, mpd_uint_t wbase,
* base <= UINT16_MAX+1. The least significant word of the result mpd_uint_t *u, mpd_ssize_t ulen, mpd_uint_t ubase,
* is rdata[0]. uint32_t *status)
*/
size_t
mpd_qexport_u16(uint16_t *rdata, size_t rlen, uint32_t rbase,
const mpd_t *src, uint32_t *status)
{ {
mpd_t *tsrc; size_t n = 0;
size_t n;
assert(rbase <= (1U<<16)); assert(wlen > 0 && ulen > 0);
assert(rlen <= SIZE_MAX/(sizeof *rdata)); assert(wbase < ubase);
if (mpd_isspecial(src) || !_mpd_isint(src)) { do {
*status |= MPD_Invalid_operation; if (n >= wlen) {
return SIZE_MAX; if (!mpd_qresize(w, n+1, status)) {
} return SIZE_MAX;
}
memset(rdata, 0, rlen * (sizeof *rdata)); wlen = n+1;
if (mpd_iszero(src)) {
return 1;
}
if ((tsrc = mpd_qnew()) == NULL) {
*status |= MPD_Malloc_error;
return SIZE_MAX;
}
if (src->exp >= 0) {
if (!mpd_qshiftl(tsrc, src, src->exp, status)) {
mpd_del(tsrc);
return SIZE_MAX;
} }
} w->data[n++] = (uint32_t)_mpd_shortdiv_b(u, u, ulen, wbase, ubase);
else { /* ulen is at least 1. u[ulen-1] can only be zero if ulen == 1. */
if (mpd_qshiftr(tsrc, src, -src->exp, status) == MPD_UINT_MAX) { ulen = _mpd_real_size(u, ulen);
mpd_del(tsrc);
return SIZE_MAX; } while (u[ulen-1] != 0);
return n;
}
#endif
/* target base 'wbase' > source base 'ubase' */
static size_t
_coeff_from_smaller_base(mpd_t *w, mpd_ssize_t wlen, mpd_uint_t wbase,
const uint32_t *u, size_t ulen, mpd_uint_t ubase,
uint32_t *status)
{
mpd_ssize_t n = 0;
mpd_uint_t carry;
assert(wlen > 0 && ulen > 0);
assert(wbase > ubase);
w->data[n++] = u[--ulen];
while (--ulen != SIZE_MAX) {
carry = _mpd_shortmul_b(w->data, w->data, n, ubase, wbase);
if (carry) {
if (n >= wlen) {
if (!mpd_qresize(w, n+1, status)) {
return SIZE_MAX;
}
wlen = n+1;
}
w->data[n++] = carry;
}
carry = _mpd_shortadd_b(w->data, n, u[ulen], wbase);
if (carry) {
if (n >= wlen) {
if (!mpd_qresize(w, n+1, status)) {
return SIZE_MAX;
}
wlen = n+1;
}
w->data[n++] = carry;
} }
} }
n = _to_base_u16(rdata, rlen, rbase, tsrc->data, tsrc->len);
mpd_del(tsrc);
return n; return n;
} }
/* /*
* Converts an integer mpd_t to a multiprecision integer with * Convert an integer mpd_t to a multiprecision integer with base <= 2**16.
* base <= UINT32_MAX. The least significant word of the result * The least significant word of the result is (*rdata)[0].
* is rdata[0]. *
* If rdata is NULL, space is allocated by the function and rlen is irrelevant.
* In case of an error any allocated storage is freed and rdata is set back to
* NULL.
*
* If rdata is non-NULL, it MUST be allocated by one of libmpdec's allocation
* functions and rlen MUST be correct. If necessary, the function will resize
* rdata. In case of an error the caller must free rdata.
*
* Return value: In case of success, the exact length of rdata, SIZE_MAX
* otherwise.
*/ */
size_t size_t
mpd_qexport_u32(uint32_t *rdata, size_t rlen, uint32_t rbase, mpd_qexport_u16(uint16_t **rdata, size_t rlen, uint32_t rbase,
const mpd_t *src, uint32_t *status) const mpd_t *src, uint32_t *status)
{ {
mpd_t *tsrc; MPD_NEW_STATIC(tsrc,0,0,0,0);
int alloc = 0; /* rdata == NULL */
size_t n;
assert(rbase <= (1U<<16));
if (mpd_isspecial(src) || !_mpd_isint(src)) {
*status |= MPD_Invalid_operation;
return SIZE_MAX;
}
if (*rdata == NULL) {
rlen = mpd_sizeinbase(src, rbase);
if (rlen == SIZE_MAX) {
*status |= MPD_Invalid_operation;
return SIZE_MAX;
}
*rdata = mpd_alloc(rlen, sizeof **rdata);
if (*rdata == NULL) {
goto malloc_error;
}
alloc = 1;
}
if (mpd_iszero(src)) {
**rdata = 0;
return 1;
}
if (src->exp >= 0) {
if (!mpd_qshiftl(&tsrc, src, src->exp, status)) {
goto malloc_error;
}
}
else {
if (mpd_qshiftr(&tsrc, src, -src->exp, status) == MPD_UINT_MAX) {
goto malloc_error;
}
}
n = _baseconv_to_u16(rdata, rlen, rbase, tsrc.data, tsrc.len);
if (n == SIZE_MAX) {
goto malloc_error;
}
out:
mpd_del(&tsrc);
return n;
malloc_error:
if (alloc) {
mpd_free(*rdata);
*rdata = NULL;
}
n = SIZE_MAX;
*status |= MPD_Malloc_error;
goto out;
}
/*
* Convert an integer mpd_t to a multiprecision integer with base<=UINT32_MAX.
* The least significant word of the result is (*rdata)[0].
*
* If rdata is NULL, space is allocated by the function and rlen is irrelevant.
* In case of an error any allocated storage is freed and rdata is set back to
* NULL.
*
* If rdata is non-NULL, it MUST be allocated by one of libmpdec's allocation
* functions and rlen MUST be correct. If necessary, the function will resize
* rdata. In case of an error the caller must free rdata.
*
* Return value: In case of success, the exact length of rdata, SIZE_MAX
* otherwise.
*/
size_t
mpd_qexport_u32(uint32_t **rdata, size_t rlen, uint32_t rbase,
const mpd_t *src, uint32_t *status)
{
MPD_NEW_STATIC(tsrc,0,0,0,0);
int alloc = 0; /* rdata == NULL */
size_t n; size_t n;
if (mpd_isspecial(src) || !_mpd_isint(src)) { if (mpd_isspecial(src) || !_mpd_isint(src)) {
*status |= MPD_Invalid_operation; *status |= MPD_Invalid_operation;
return SIZE_MAX; return SIZE_MAX;
} }
#if MPD_SIZE_MAX < SIZE_MAX
if (rlen > MPD_SSIZE_MAX) {
*status |= MPD_Invalid_operation;
return SIZE_MAX;
}
#endif
assert(rlen <= SIZE_MAX/(sizeof *rdata)); if (*rdata == NULL) {
memset(rdata, 0, rlen * (sizeof *rdata)); rlen = mpd_sizeinbase(src, rbase);
if (rlen == SIZE_MAX) {
*status |= MPD_Invalid_operation;
return SIZE_MAX;
}
*rdata = mpd_alloc(rlen, sizeof **rdata);
if (*rdata == NULL) {
goto malloc_error;
}
alloc = 1;
}
if (mpd_iszero(src)) { if (mpd_iszero(src)) {
**rdata = 0;
return 1; return 1;
} }
if ((tsrc = mpd_qnew()) == NULL) {
*status |= MPD_Malloc_error;
return SIZE_MAX;
}
if (src->exp >= 0) { if (src->exp >= 0) {
if (!mpd_qshiftl(tsrc, src, src->exp, status)) { if (!mpd_qshiftl(&tsrc, src, src->exp, status)) {
mpd_del(tsrc); goto malloc_error;
return SIZE_MAX;
} }
} }
else { else {
if (mpd_qshiftr(tsrc, src, -src->exp, status) == MPD_UINT_MAX) { if (mpd_qshiftr(&tsrc, src, -src->exp, status) == MPD_UINT_MAX) {
mpd_del(tsrc); goto malloc_error;
return SIZE_MAX;
} }
} }
#ifdef CONFIG_64 #ifdef CONFIG_64
n = _baseconv_to_smaller(rdata, rlen, rbase, n = _baseconv_to_smaller(rdata, rlen, rbase,
tsrc->data, tsrc->len, MPD_RADIX); tsrc.data, tsrc.len, MPD_RADIX);
#else #else
if (rbase <= MPD_RADIX) { if (rbase == MPD_RADIX) {
n = _copy_equal_base(rdata, rlen, tsrc.data, tsrc.len);
}
else if (rbase < MPD_RADIX) {
n = _baseconv_to_smaller(rdata, rlen, rbase, n = _baseconv_to_smaller(rdata, rlen, rbase,
tsrc->data, tsrc->len, MPD_RADIX); tsrc.data, tsrc.len, MPD_RADIX);
} }
else { else {
_baseconv_to_larger(rdata, (mpd_ssize_t)rlen, rbase, n = _baseconv_to_larger(rdata, rlen, rbase,
tsrc->data, tsrc->len, MPD_RADIX); tsrc.data, tsrc.len, MPD_RADIX);
n = _mpd_real_size(rdata, (mpd_ssize_t)rlen);
} }
#endif #endif
mpd_del(tsrc); if (n == SIZE_MAX) {
goto malloc_error;
}
out:
mpd_del(&tsrc);
return n; return n;
malloc_error:
if (alloc) {
mpd_free(*rdata);
*rdata = NULL;
}
n = SIZE_MAX;
*status |= MPD_Malloc_error;
goto out;
} }
@ -7846,20 +8021,19 @@ mpd_qimport_u16(mpd_t *result,
{ {
mpd_uint_t *usrc; /* uint16_t src copied to an mpd_uint_t array */ mpd_uint_t *usrc; /* uint16_t src copied to an mpd_uint_t array */
mpd_ssize_t rlen; /* length of the result */ mpd_ssize_t rlen; /* length of the result */
size_t n = 0; size_t n;
assert(srclen > 0); assert(srclen > 0);
assert(srcbase <= (1U<<16)); assert(srcbase <= (1U<<16));
if ((rlen = _mpd_importsize(srclen, srcbase)) == MPD_SSIZE_MAX) { rlen = _mpd_importsize(srclen, srcbase);
if (rlen == MPD_SSIZE_MAX) {
mpd_seterror(result, MPD_Invalid_operation, status); mpd_seterror(result, MPD_Invalid_operation, status);
return; return;
} }
if (srclen > MPD_SIZE_MAX/(sizeof *usrc)) {
mpd_seterror(result, MPD_Invalid_operation, status); usrc = mpd_alloc((mpd_size_t)srclen, sizeof *usrc);
return; if (usrc == NULL) {
}
if ((usrc = mpd_alloc((mpd_size_t)srclen, sizeof *usrc)) == NULL) {
mpd_seterror(result, MPD_Malloc_error, status); mpd_seterror(result, MPD_Malloc_error, status);
return; return;
} }
@ -7867,16 +8041,18 @@ mpd_qimport_u16(mpd_t *result,
usrc[n] = srcdata[n]; usrc[n] = srcdata[n];
} }
/* result->data is initialized to zero */ if (!mpd_qresize(result, rlen, status)) {
if (!mpd_qresize_zero(result, rlen, status)) {
goto finish; goto finish;
} }
_from_base_u16(result->data, rlen, usrc, srclen, srcbase); n = _coeff_from_u16(result, rlen, usrc, srclen, srcbase, status);
if (n == SIZE_MAX) {
goto finish;
}
mpd_set_flags(result, srcsign); mpd_set_flags(result, srcsign);
result->exp = 0; result->exp = 0;
result->len = _mpd_real_size(result->data, rlen); result->len = n;
mpd_setdigits(result); mpd_setdigits(result);
mpd_qresize(result, result->len, status); mpd_qresize(result, result->len, status);
@ -7897,58 +8073,66 @@ mpd_qimport_u32(mpd_t *result,
uint8_t srcsign, uint32_t srcbase, uint8_t srcsign, uint32_t srcbase,
const mpd_context_t *ctx, uint32_t *status) const mpd_context_t *ctx, uint32_t *status)
{ {
mpd_uint_t *usrc; /* uint32_t src copied to an mpd_uint_t array */
mpd_ssize_t rlen; /* length of the result */ mpd_ssize_t rlen; /* length of the result */
size_t n = 0; size_t n;
assert(srclen > 0); assert(srclen > 0);
if ((rlen = _mpd_importsize(srclen, srcbase)) == MPD_SSIZE_MAX) { rlen = _mpd_importsize(srclen, srcbase);
if (rlen == MPD_SSIZE_MAX) {
mpd_seterror(result, MPD_Invalid_operation, status); mpd_seterror(result, MPD_Invalid_operation, status);
return; return;
} }
if (srclen > MPD_SIZE_MAX/(sizeof *usrc)) {
mpd_seterror(result, MPD_Invalid_operation, status);
return;
}
if ((usrc = mpd_alloc((mpd_size_t)srclen, sizeof *usrc)) == NULL) {
mpd_seterror(result, MPD_Malloc_error, status);
return;
}
for (n = 0; n < srclen; n++) {
usrc[n] = srcdata[n];
}
/* result->data is initialized to zero */ if (!mpd_qresize(result, rlen, status)) {
if (!mpd_qresize_zero(result, rlen, status)) { return;
goto finish;
} }
#ifdef CONFIG_64 #ifdef CONFIG_64
_baseconv_to_larger(result->data, rlen, MPD_RADIX, n = _coeff_from_smaller_base(result, rlen, MPD_RADIX,
usrc, srclen, srcbase); srcdata, srclen, srcbase,
status);
#else #else
if (srcbase <= MPD_RADIX) { if (srcbase == MPD_RADIX) {
_baseconv_to_larger(result->data, rlen, MPD_RADIX, if (!mpd_qresize(result, srclen, status)) {
usrc, srclen, srcbase); return;
}
memcpy(result->data, srcdata, srclen * (sizeof *srcdata));
n = srclen;
}
else if (srcbase < MPD_RADIX) {
n = _coeff_from_smaller_base(result, rlen, MPD_RADIX,
srcdata, srclen, srcbase,
status);
} }
else { else {
_baseconv_to_smaller(result->data, rlen, MPD_RADIX, mpd_uint_t *usrc = mpd_alloc((mpd_size_t)srclen, sizeof *usrc);
usrc, (mpd_ssize_t)srclen, srcbase); if (usrc == NULL) {
mpd_seterror(result, MPD_Malloc_error, status);
return;
}
for (n = 0; n < srclen; n++) {
usrc[n] = srcdata[n];
}
n = _coeff_from_larger_base(result, rlen, MPD_RADIX,
usrc, (mpd_ssize_t)srclen, srcbase,
status);
mpd_free(usrc);
} }
#endif #endif
if (n == SIZE_MAX) {
return;
}
mpd_set_flags(result, srcsign); mpd_set_flags(result, srcsign);
result->exp = 0; result->exp = 0;
result->len = _mpd_real_size(result->data, rlen); result->len = n;
mpd_setdigits(result); mpd_setdigits(result);
mpd_qresize(result, result->len, status); mpd_qresize(result, result->len, status);
mpd_qfinalize(result, ctx, status); mpd_qfinalize(result, ctx, status);
finish:
mpd_free(usrc);
} }

View file

@ -511,16 +511,16 @@ void mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t
void mpd_qinvroot(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status); void mpd_qinvroot(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
size_t mpd_sizeinbase(mpd_t *a, uint32_t base); size_t mpd_sizeinbase(const mpd_t *a, uint32_t base);
void mpd_qimport_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, void mpd_qimport_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen,
uint8_t srcsign, uint32_t srcbase, uint8_t srcsign, uint32_t srcbase,
const mpd_context_t *ctx, uint32_t *status); const mpd_context_t *ctx, uint32_t *status);
void mpd_qimport_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, void mpd_qimport_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen,
uint8_t srcsign, uint32_t srcbase, uint8_t srcsign, uint32_t srcbase,
const mpd_context_t *ctx, uint32_t *status); const mpd_context_t *ctx, uint32_t *status);
size_t mpd_qexport_u16(uint16_t *rdata, size_t rlen, uint32_t base, size_t mpd_qexport_u16(uint16_t **rdata, size_t rlen, uint32_t base,
const mpd_t *src, uint32_t *status); const mpd_t *src, uint32_t *status);
size_t mpd_qexport_u32(uint32_t *rdata, size_t rlen, uint32_t base, size_t mpd_qexport_u32(uint32_t **rdata, size_t rlen, uint32_t base,
const mpd_t *src, uint32_t *status); const mpd_t *src, uint32_t *status);
@ -531,8 +531,8 @@ size_t mpd_qexport_u32(uint32_t *rdata, size_t rlen, uint32_t base,
char * mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx); char * mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx);
void mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx); void mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx);
void mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx); void mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx);
size_t mpd_export_u16(uint16_t *rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx); size_t mpd_export_u16(uint16_t **rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx);
size_t mpd_export_u32(uint32_t *rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx); size_t mpd_export_u32(uint32_t **rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx);
void mpd_finalize(mpd_t *result, mpd_context_t *ctx); void mpd_finalize(mpd_t *result, mpd_context_t *ctx);
int mpd_check_nan(mpd_t *result, const mpd_t *a, mpd_context_t *ctx); int mpd_check_nan(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
int mpd_check_nans(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx); int mpd_check_nans(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);

232
configure vendored
View file

@ -646,6 +646,8 @@ INSTALL_SCRIPT
INSTALL_PROGRAM INSTALL_PROGRAM
HAS_PYTHON HAS_PYTHON
DISABLE_ASDLGEN DISABLE_ASDLGEN
ac_ct_READELF
READELF
ARFLAGS ARFLAGS
ac_ct_AR ac_ct_AR
AR AR
@ -680,6 +682,7 @@ CC
EXPORT_MACOSX_DEPLOYMENT_TARGET EXPORT_MACOSX_DEPLOYMENT_TARGET
CONFIGURE_MACOSX_DEPLOYMENT_TARGET CONFIGURE_MACOSX_DEPLOYMENT_TARGET
SGI_ABI SGI_ABI
_PYTHON_HOST_PLATFORM
MACHDEP MACHDEP
FRAMEWORKINSTALLAPPSPREFIX FRAMEWORKINSTALLAPPSPREFIX
FRAMEWORKUNIXTOOLSPREFIX FRAMEWORKUNIXTOOLSPREFIX
@ -698,6 +701,7 @@ UNIVERSALSDK
CONFIG_ARGS CONFIG_ARGS
SOVERSION SOVERSION
VERSION VERSION
PYTHON_FOR_BUILD
host_os host_os
host_vendor host_vendor
host_cpu host_cpu
@ -2878,6 +2882,29 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
if test "$cross_compiling" = yes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5
$as_echo_n "checking for python interpreter for cross build... " >&6; }
if test -z "$PYTHON_FOR_BUILD"; then
for interp in python$PACKAGE_VERSION python3 python; do
which $interp >/dev/null 2>&1 || continue
if $interp -c 'import sys;sys.exit(not sys.version_info[:2] >= (3,3))'; then
break
fi
interp=
done
if test x$interp = x; then
as_fn_error $? "python$PACKAGE_VERSION interpreter not found" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
$as_echo "$interp" >&6; }
PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
fi
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
fi
if test "$prefix" != "/"; then if test "$prefix" != "/"; then
prefix=`echo "$prefix" | sed -e 's/\/$//g'` prefix=`echo "$prefix" | sed -e 's/\/$//g'`
@ -3216,6 +3243,29 @@ then
esac esac
fi fi
if test "$cross_compiling" = yes; then
case "$host" in
*-*-linux*)
case "$host_cpu" in
arm*)
_host_cpu=arm
;;
*)
_host_cpu=$host_cpu
esac
;;
*-*-cygwin*)
_host_cpu=
;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
as_fn_error $? "cross build not supported for $host" "$LINENO" 5
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
fi
# Some systems cannot stand _XOPEN_SOURCE being defined at all; they # Some systems cannot stand _XOPEN_SOURCE being defined at all; they
# disable features if it is defined, without any means to access these # disable features if it is defined, without any means to access these
# features as extensions. For these systems, we skip the definition of # features as extensions. For these systems, we skip the definition of
@ -5538,6 +5588,10 @@ else # shared is disabled
esac esac
fi fi
if test "$cross_compiling" = yes; then
RUNSHARED=
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDLIBRARY" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDLIBRARY" >&5
$as_echo "$LDLIBRARY" >&6; } $as_echo "$LDLIBRARY" >&6; }
@ -5742,6 +5796,115 @@ then
ARFLAGS="rc" ARFLAGS="rc"
fi fi
if test -n "$ac_tool_prefix"; then
for ac_prog in readelf
do
# Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_READELF+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$READELF"; then
ac_cv_prog_READELF="$READELF" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
ac_cv_prog_READELF="$ac_tool_prefix$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
READELF=$ac_cv_prog_READELF
if test -n "$READELF"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $READELF" >&5
$as_echo "$READELF" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$READELF" && break
done
fi
if test -z "$READELF"; then
ac_ct_READELF=$READELF
for ac_prog in readelf
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_READELF+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$ac_ct_READELF"; then
ac_cv_prog_ac_ct_READELF="$ac_ct_READELF" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
ac_cv_prog_ac_ct_READELF="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
ac_ct_READELF=$ac_cv_prog_ac_ct_READELF
if test -n "$ac_ct_READELF"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_READELF" >&5
$as_echo "$ac_ct_READELF" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
test -n "$ac_ct_READELF" && break
done
if test "x$ac_ct_READELF" = x; then
READELF=":"
else
case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
READELF=$ac_ct_READELF
fi
fi
if test "$cross_compiling" = yes; then
case "$READELF" in
readelf|:)
as_fn_error $? "readelf for the host is required for cross builds" "$LINENO" 5
;;
esac
fi
DISABLE_ASDLGEN="" DISABLE_ASDLGEN=""
# Extract the first word of "python", so it can be a program name with args. # Extract the first word of "python", so it can be a program name with args.
@ -14341,34 +14504,73 @@ $as_echo "no" >&6; }
fi fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for device files" >&5
$as_echo "$as_me: checking for device files" >&6;}
if test "x$cross_compiling" = xyes; then
if test "${ac_cv_file__dev_ptmx+set}" != set; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptmx" >&5
$as_echo_n "checking for /dev/ptmx... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not set" >&5
$as_echo "not set" >&6; }
as_fn_error $? "set ac_cv_file__dev_ptmx to yes/no in your CONFIG_SITE file when cross compiling" "$LINENO" 5
fi
if test "${ac_cv_file__dev_ptc+set}" != set; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptc" >&5
$as_echo_n "checking for /dev/ptc... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not set" >&5
$as_echo "not set" >&6; }
as_fn_error $? "set ac_cv_file__dev_ptc to yes/no in your CONFIG_SITE file when cross compiling" "$LINENO" 5
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptmx" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptmx" >&5
$as_echo_n "checking for /dev/ptmx... " >&6; } $as_echo_n "checking for /dev/ptmx... " >&6; }
if ${ac_cv_file__dev_ptmx+:} false; then :
$as_echo_n "(cached) " >&6
else
test "$cross_compiling" = yes &&
as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
if test -r "/dev/ptmx"; then
ac_cv_file__dev_ptmx=yes
else
ac_cv_file__dev_ptmx=no
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file__dev_ptmx" >&5
$as_echo "$ac_cv_file__dev_ptmx" >&6; }
if test "x$ac_cv_file__dev_ptmx" = xyes; then :
if test -r /dev/ptmx fi
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 if test "x$ac_cv_file__dev_ptmx" = xyes; then
$as_echo "yes" >&6; }
$as_echo "#define HAVE_DEV_PTMX 1" >>confdefs.h $as_echo "#define HAVE_DEV_PTMX 1" >>confdefs.h
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptc" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for /dev/ptc" >&5
$as_echo_n "checking for /dev/ptc... " >&6; } $as_echo_n "checking for /dev/ptc... " >&6; }
if ${ac_cv_file__dev_ptc+:} false; then :
$as_echo_n "(cached) " >&6
else
test "$cross_compiling" = yes &&
as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
if test -r "/dev/ptc"; then
ac_cv_file__dev_ptc=yes
else
ac_cv_file__dev_ptc=no
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_file__dev_ptc" >&5
$as_echo "$ac_cv_file__dev_ptc" >&6; }
if test "x$ac_cv_file__dev_ptc" = xyes; then :
if test -r /dev/ptc fi
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 if test "x$ac_cv_file__dev_ptc" = xyes; then
$as_echo "yes" >&6; }
$as_echo "#define HAVE_DEV_PTC 1" >>confdefs.h $as_echo "#define HAVE_DEV_PTC 1" >>confdefs.h
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi fi
if test "$have_long_long" = yes if test "$have_long_long" = yes

View file

@ -35,6 +35,27 @@ AC_CONFIG_HEADER(pyconfig.h)
AC_CANONICAL_HOST AC_CANONICAL_HOST
if test "$cross_compiling" = yes; then
AC_MSG_CHECKING([for python interpreter for cross build])
if test -z "$PYTHON_FOR_BUILD"; then
for interp in python$PACKAGE_VERSION python3 python; do
which $interp >/dev/null 2>&1 || continue
if $interp -c 'import sys;sys.exit(not sys.version_info@<:@:2@:>@ >= (3,3))'; then
break
fi
interp=
done
if test x$interp = x; then
AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found])
fi
AC_MSG_RESULT($interp)
PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
fi
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
fi
AC_SUBST(PYTHON_FOR_BUILD)
dnl Ensure that if prefix is specified, it does not end in a slash. If dnl Ensure that if prefix is specified, it does not end in a slash. If
dnl it does, we get path names containing '//' which is both ugly and dnl it does, we get path names containing '//' which is both ugly and
dnl can cause trouble. dnl can cause trouble.
@ -352,6 +373,29 @@ then
'') MACHDEP="unknown";; '') MACHDEP="unknown";;
esac esac
fi fi
AC_SUBST(_PYTHON_HOST_PLATFORM)
if test "$cross_compiling" = yes; then
case "$host" in
*-*-linux*)
case "$host_cpu" in
arm*)
_host_cpu=arm
;;
*)
_host_cpu=$host_cpu
esac
;;
*-*-cygwin*)
_host_cpu=
;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
AC_MSG_ERROR([cross build not supported for $host])
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
fi
# Some systems cannot stand _XOPEN_SOURCE being defined at all; they # Some systems cannot stand _XOPEN_SOURCE being defined at all; they
# disable features if it is defined, without any means to access these # disable features if it is defined, without any means to access these
@ -913,6 +957,10 @@ else # shared is disabled
esac esac
fi fi
if test "$cross_compiling" = yes; then
RUNSHARED=
fi
AC_MSG_RESULT($LDLIBRARY) AC_MSG_RESULT($LDLIBRARY)
AC_PROG_RANLIB AC_PROG_RANLIB
@ -926,6 +974,16 @@ then
ARFLAGS="rc" ARFLAGS="rc"
fi fi
AC_CHECK_TOOLS([READELF], [readelf], [:])
if test "$cross_compiling" = yes; then
case "$READELF" in
readelf|:)
AC_MSG_ERROR([readelf for the host is required for cross builds])
;;
esac
fi
AC_SUBST(READELF)
AC_SUBST(DISABLE_ASDLGEN) AC_SUBST(DISABLE_ASDLGEN)
DISABLE_ASDLGEN="" DISABLE_ASDLGEN=""
AC_CHECK_PROG(HAS_PYTHON, python, found, not-found) AC_CHECK_PROG(HAS_PYTHON, python, found, not-found)
@ -4202,26 +4260,31 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[void *x=resizeterm
[AC_MSG_RESULT(no)] [AC_MSG_RESULT(no)]
) )
AC_MSG_CHECKING(for /dev/ptmx) AC_MSG_NOTICE([checking for device files])
if test -r /dev/ptmx dnl NOTE: Inform user how to proceed with files when cross compiling.
then if test "x$cross_compiling" = xyes; then
AC_MSG_RESULT(yes) if test "${ac_cv_file__dev_ptmx+set}" != set; then
AC_DEFINE(HAVE_DEV_PTMX, 1, AC_MSG_CHECKING([for /dev/ptmx])
[Define if we have /dev/ptmx.]) AC_MSG_RESULT([not set])
else AC_MSG_ERROR([set ac_cv_file__dev_ptmx to yes/no in your CONFIG_SITE file when cross compiling])
AC_MSG_RESULT(no) fi
if test "${ac_cv_file__dev_ptc+set}" != set; then
AC_MSG_CHECKING([for /dev/ptc])
AC_MSG_RESULT([not set])
AC_MSG_ERROR([set ac_cv_file__dev_ptc to yes/no in your CONFIG_SITE file when cross compiling])
fi
fi fi
AC_MSG_CHECKING(for /dev/ptc) AC_CHECK_FILE(/dev/ptmx, [], [])
if test "x$ac_cv_file__dev_ptmx" = xyes; then
if test -r /dev/ptc AC_DEFINE(HAVE_DEV_PTMX, 1,
then [Define to 1 if you have the /dev/ptmx device file.])
AC_MSG_RESULT(yes) fi
AC_CHECK_FILE(/dev/ptc, [], [])
if test "x$ac_cv_file__dev_ptc" = xyes; then
AC_DEFINE(HAVE_DEV_PTC, 1, AC_DEFINE(HAVE_DEV_PTC, 1,
[Define if we have /dev/ptc.]) [Define to 1 if you have the /dev/ptc device file.])
else
AC_MSG_RESULT(no)
fi fi
if test "$have_long_long" = yes if test "$have_long_long" = yes

View file

@ -168,10 +168,10 @@
/* Define to 1 if you have the device macros. */ /* Define to 1 if you have the device macros. */
#undef HAVE_DEVICE_MACROS #undef HAVE_DEVICE_MACROS
/* Define if we have /dev/ptc. */ /* Define to 1 if you have the /dev/ptc device file. */
#undef HAVE_DEV_PTC #undef HAVE_DEV_PTC
/* Define if we have /dev/ptmx. */ /* Define to 1 if you have the /dev/ptmx device file. */
#undef HAVE_DEV_PTMX #undef HAVE_DEV_PTMX
/* Define to 1 if you have the <direct.h> header file. */ /* Define to 1 if you have the <direct.h> header file. */

104
setup.py
View file

@ -15,7 +15,12 @@ from distutils.command.install_lib import install_lib
from distutils.command.build_scripts import build_scripts from distutils.command.build_scripts import build_scripts
from distutils.spawn import find_executable from distutils.spawn import find_executable
cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
def get_platform(): def get_platform():
# cross build
if "_PYTHON_HOST_PLATFORM" in os.environ:
return os.environ["_PYTHON_HOST_PLATFORM"]
# Get value of sys.platform # Get value of sys.platform
if sys.platform.startswith('osf1'): if sys.platform.startswith('osf1'):
return 'osf1' return 'osf1'
@ -23,7 +28,7 @@ def get_platform():
host_platform = get_platform() host_platform = get_platform()
# Were we compiled --with-pydebug or with #define Py_DEBUG? # Were we compiled --with-pydebug or with #define Py_DEBUG?
COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount') COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
# This global variable is used to hold the list of modules to be disabled. # This global variable is used to hold the list of modules to be disabled.
disabled_module_list = [] disabled_module_list = []
@ -334,6 +339,10 @@ class PyBuildExt(build_ext):
# cached. Clear that cache before trying to import. # cached. Clear that cache before trying to import.
sys.path_importer_cache.clear() sys.path_importer_cache.clear()
# Don't try to load extensions for cross builds
if cross_compiling:
return
try: try:
imp.load_dynamic(ext.name, ext_filename) imp.load_dynamic(ext.name, ext_filename)
except ImportError as why: except ImportError as why:
@ -370,12 +379,15 @@ class PyBuildExt(build_ext):
# https://wiki.ubuntu.com/MultiarchSpec # https://wiki.ubuntu.com/MultiarchSpec
if not find_executable('dpkg-architecture'): if not find_executable('dpkg-architecture'):
return return
opt = ''
if cross_compiling:
opt = '-t' + sysconfig.get_config_var('HOST_GNU_TYPE')
tmpfile = os.path.join(self.build_temp, 'multiarch') tmpfile = os.path.join(self.build_temp, 'multiarch')
if not os.path.exists(self.build_temp): if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp) os.makedirs(self.build_temp)
ret = os.system( ret = os.system(
'dpkg-architecture -qDEB_HOST_MULTIARCH > %s 2> /dev/null' % 'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
tmpfile) (opt, tmpfile))
try: try:
if ret >> 8 == 0: if ret >> 8 == 0:
with open(tmpfile) as fp: with open(tmpfile) as fp:
@ -387,12 +399,46 @@ class PyBuildExt(build_ext):
finally: finally:
os.unlink(tmpfile) os.unlink(tmpfile)
def add_gcc_paths(self):
gcc = sysconfig.get_config_var('CC')
tmpfile = os.path.join(self.build_temp, 'gccpaths')
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
is_gcc = False
in_incdirs = False
inc_dirs = []
lib_dirs = []
try:
if ret >> 8 == 0:
with open(tmpfile) as fp:
for line in fp.readlines():
if line.startswith("gcc version"):
is_gcc = True
elif line.startswith("#include <...>"):
in_incdirs = True
elif line.startswith("End of search list"):
in_incdirs = False
elif is_gcc and line.startswith("LIBRARY_PATH"):
for d in line.strip().split("=")[1].split(":"):
d = os.path.normpath(d)
if '/gcc/' not in d:
add_dir_to_list(self.compiler.library_dirs,
d)
elif is_gcc and in_incdirs and '/gcc/' not in line:
add_dir_to_list(self.compiler.include_dirs,
line.strip())
finally:
os.unlink(tmpfile)
def detect_modules(self): def detect_modules(self):
# Ensure that /usr/local is always used, but the local build # Ensure that /usr/local is always used, but the local build
# directories (i.e. '.' and 'Include') must be first. See issue # directories (i.e. '.' and 'Include') must be first. See issue
# 10520. # 10520.
add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') if not cross_compiling:
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
self.add_gcc_paths()
self.add_multiarch_paths() self.add_multiarch_paths()
# Add paths specified in the environment variables LDFLAGS and # Add paths specified in the environment variables LDFLAGS and
@ -443,11 +489,18 @@ class PyBuildExt(build_ext):
# lib_dirs and inc_dirs are used to search for files; # lib_dirs and inc_dirs are used to search for files;
# if a file is found in one of those directories, it can # if a file is found in one of those directories, it can
# be assumed that no additional -I,-L directives are needed. # be assumed that no additional -I,-L directives are needed.
lib_dirs = self.compiler.library_dirs + [ inc_dirs = self.compiler.include_dirs[:]
'/lib64', '/usr/lib64', lib_dirs = self.compiler.library_dirs[:]
'/lib', '/usr/lib', if not cross_compiling:
] for d in (
inc_dirs = self.compiler.include_dirs + ['/usr/include'] '/usr/include',
):
add_dir_to_list(inc_dirs, d)
for d in (
'/lib64', '/usr/lib64',
'/lib', '/usr/lib',
):
add_dir_to_list(lib_dirs, d)
exts = [] exts = []
missing = [] missing = []
@ -590,13 +643,20 @@ class PyBuildExt(build_ext):
do_readline = self.compiler.find_library_file(lib_dirs, 'readline') do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
readline_termcap_library = "" readline_termcap_library = ""
curses_library = "" curses_library = ""
# Cannot use os.popen here in py3k.
tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
# Determine if readline is already linked against curses or tinfo. # Determine if readline is already linked against curses or tinfo.
if do_readline and find_executable('ldd'): if do_readline:
# Cannot use os.popen here in py3k. if cross_compiling:
tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib') ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
if not os.path.exists(self.build_temp): % (sysconfig.get_config_var('READELF'),
os.makedirs(self.build_temp) do_readline, tmpfile))
ret = os.system("ldd %s > %s" % (do_readline, tmpfile)) elif find_executable('ldd'):
ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
else:
ret = 256
if ret == 0: if ret == 0:
with open(tmpfile) as fp: with open(tmpfile) as fp:
for ln in fp: for ln in fp:
@ -830,6 +890,9 @@ class PyBuildExt(build_ext):
db_inc_paths.append('/pkg/db-3.%d/include' % x) db_inc_paths.append('/pkg/db-3.%d/include' % x)
db_inc_paths.append('/opt/db-3.%d/include' % x) db_inc_paths.append('/opt/db-3.%d/include' % x)
if cross_compiling:
db_inc_paths = []
# Add some common subdirectories for Sleepycat DB to the list, # Add some common subdirectories for Sleepycat DB to the list,
# based on the standard include directories. This way DB3/4 gets # based on the standard include directories. This way DB3/4 gets
# picked up when it is installed in a non-standard prefix and # picked up when it is installed in a non-standard prefix and
@ -966,7 +1029,9 @@ class PyBuildExt(build_ext):
'/usr/local/include', '/usr/local/include',
'/usr/local/include/sqlite', '/usr/local/include/sqlite',
'/usr/local/include/sqlite3', '/usr/local/include/sqlite3',
] ]
if cross_compiling:
sqlite_inc_paths = []
MIN_SQLITE_VERSION_NUMBER = (3, 0, 8) MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
MIN_SQLITE_VERSION = ".".join([str(x) MIN_SQLITE_VERSION = ".".join([str(x)
for x in MIN_SQLITE_VERSION_NUMBER]) for x in MIN_SQLITE_VERSION_NUMBER])
@ -1701,7 +1766,8 @@ class PyBuildExt(build_ext):
ffi_configfile): ffi_configfile):
from distutils.dir_util import mkpath from distutils.dir_util import mkpath
mkpath(ffi_builddir) mkpath(ffi_builddir)
config_args = [] config_args = [arg for arg in sysconfig.get_config_var("CONFIG_ARGS").split()
if (('--host=' in arg) or ('--build=' in arg))]
# Pass empty CFLAGS because we'll just append the resulting # Pass empty CFLAGS because we'll just append the resulting
# CFLAGS to Python's; -g or -O2 is to be avoided. # CFLAGS to Python's; -g or -O2 is to be avoided.
@ -1811,7 +1877,7 @@ class PyBuildExt(build_ext):
def _decimal_ext(self): def _decimal_ext(self):
extra_compile_args = [] extra_compile_args = []
undef_macros=['NDEBUG'] undef_macros = ['NDEBUG']
if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"): if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
include_dirs = [] include_dirs = []
libraries = ['mpdec'] libraries = ['mpdec']