Added BlueZ build scripts
[ti-bt/build-utils.git] / patches / 0001-Python-2.7.3-xcompile.patch
1 From 846cdf11adb55e88f311bf5ff3ec4173cbe073d9 Mon Sep 17 00:00:00 2001
2 From: Eyal Reizer <eyalr@ti.com>
3 Date: Mon, 22 Oct 2012 18:57:22 +0300
4 Subject: [PATCH] Python-2.7.3-xcompile
6 Signed-off-by: Eyal Reizer <eyalr@ti.com>
7 ---
8  Lib/plat-linux3/regen |    8 ++++++++
9  Makefile.pre.in       |   27 ++++++++++++++++-----------
10  configure             |    4 ++--
11  setup.py              |   43 ++++++++++++++++++++++++++++++++-----------
12  4 files changed, 58 insertions(+), 24 deletions(-)
13  create mode 100644 Lib/plat-linux3/regen
15 diff --git a/Lib/plat-linux3/regen b/Lib/plat-linux3/regen
16 new file mode 100644
17 index 0000000..7a78072
18 --- /dev/null
19 +++ b/Lib/plat-linux3/regen
20 @@ -0,0 +1,8 @@
21 +#! /bin/sh
22 +case `uname` in
23 +Linux*) ;;
24 +*) echo Probably not on a Linux system 1>&2
25 + exit 1;;
26 +esac
27 +set -v
28 +h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h
29 diff --git a/Makefile.pre.in b/Makefile.pre.in
30 index e2237a9..fc6b2d7 100644
31 --- a/Makefile.pre.in
32 +++ b/Makefile.pre.in
33 @@ -182,6 +182,7 @@ UNICODE_OBJS=   @UNICODE_OBJS@
34  
35  PYTHON=                python$(EXE)
36  BUILDPYTHON=   python$(BUILDEXE)
37 +HOSTPYTHON=     ./$(BUILDPYTHON)
38  
39  # The task to run while instrument when building the profile-opt target
40  PROFILE_TASK=  $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
41 @@ -215,6 +216,8 @@ LIBFFI_INCLUDEDIR=  @LIBFFI_INCLUDEDIR@
42  # Parser
43  PGEN=          Parser/pgen$(EXE)
44  
45 +HOSTPGEN=   $(PGEN)
46 +
47  POBJS=         \
48                 Parser/acceler.o \
49                 Parser/grammar1.o \
50 @@ -408,8 +411,8 @@ platform: $(BUILDPYTHON)
51  # Build the shared modules
52  sharedmods: $(BUILDPYTHON)
53         @case $$MAKEFLAGS in \
54 -       *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
55 -       *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
56 +       *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
57 +       *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
58         esac
59  
60  # Build static library
61 @@ -543,7 +546,7 @@ Modules/python.o: $(srcdir)/Modules/python.c
62  $(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
63  Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
64                 -@$(INSTALL) -d Include
65 -               $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
66 +               -$(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
67                 -touch Parser/pgen.stamp
68  
69  $(PGEN):       $(PGENOBJS)
70 @@ -938,26 +941,26 @@ libinstall:       build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
71                 $(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
72                         $(DESTDIR)$(LIBDEST)/distutils/tests ; \
73         fi
74 -       PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
75 -               ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
76 +       -PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
77 +               $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
78                 -d $(LIBDEST) -f \
79                 -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
80                 $(DESTDIR)$(LIBDEST)
81 -       PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
82 -               ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
83 +       -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
84 +               $(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
85                 -d $(LIBDEST) -f \
86                 -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
87                 $(DESTDIR)$(LIBDEST)
88         -PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
89 -               ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
90 +               $(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
91                 -d $(LIBDEST)/site-packages -f \
92                 -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
93         -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
94 -               ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
95 +               $(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
96                 -d $(LIBDEST)/site-packages -f \
97                 -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
98         -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
99 -               ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
100 +               $(HOSTPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
101  
102  # Create the PLATDIR source directory, if one wasn't distributed..
103  $(srcdir)/Lib/$(PLATDIR):
104 @@ -1062,7 +1065,9 @@ libainstall:      all python-config
105  # Install the dynamically loadable modules
106  # This goes into $(exec_prefix)
107  sharedinstall: sharedmods
108 -       $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
109 +       CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
110 +       $(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
111 +               --skip-build \
112                 --prefix=$(prefix) \
113                 --install-scripts=$(BINDIR) \
114                 --install-platlib=$(DESTSHARED) \
115 diff --git a/configure b/configure
116 index 3948080..acf3c8a 100755
117 --- a/configure
118 +++ b/configure
119 @@ -13697,7 +13697,7 @@ $as_echo_n "checking for %lld and %llu printf() format support... " >&6; }
120    $as_echo_n "(cached) " >&6
121  else
122    if test "$cross_compiling" = yes; then :
123 -  ac_cv_have_long_long_format=no
124 +  ac_cv_have_long_long_format="cross -- assuming yes"
125  else
126    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
127  /* end confdefs.h.  */
128 @@ -13749,7 +13749,7 @@ fi
129  $as_echo "$ac_cv_have_long_long_format" >&6; }
130  fi
131  
132 -if test "$ac_cv_have_long_long_format" = yes
133 +if test "$ac_cv_have_long_long_format" != no
134  then
135  
136  $as_echo "#define PY_FORMAT_LONG_LONG \"ll\"" >>confdefs.h
137 diff --git a/setup.py b/setup.py
138 index 6b47451..ed56aed 100644
139 --- a/setup.py
140 +++ b/setup.py
141 @@ -145,6 +145,7 @@ class PyBuildExt(build_ext):
142      def __init__(self, dist):
143          build_ext.__init__(self, dist)
144          self.failed = []
145 +        self.cross_compile = os.environ.get('CROSS_COMPILE_TARGET') == 'yes'
146  
147      def build_extensions(self):
148  
149 @@ -278,6 +279,14 @@ class PyBuildExt(build_ext):
150                            (ext.name, sys.exc_info()[1]))
151              self.failed.append(ext.name)
152              return
154 +        # Import check will not work when cross-compiling.
155 +        if os.environ.has_key('PYTHONXCPREFIX'):
156 +            self.announce(
157 +                'WARNING: skipping import check for cross-compiled: "%s"' %
158 +                ext.name)
159 +            return
161          # Workaround for Mac OS X: The Carbon-based modules cannot be
162          # reliably imported into a command-line Python
163          if 'Carbon' in ext.extra_link_args:
164 @@ -369,9 +378,10 @@ class PyBuildExt(build_ext):
165  
166      def detect_modules(self):
167          # Ensure that /usr/local is always used
168 -        add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
169 -        add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
170 -        self.add_multiarch_paths()
171 +        if not self.cross_compile:
172 +            add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
173 +            add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
174 +            self.add_multiarch_paths()
175  
176          # Add paths specified in the environment variables LDFLAGS and
177          # CPPFLAGS for header and library files.
178 @@ -408,7 +418,8 @@ class PyBuildExt(build_ext):
179                          add_dir_to_list(dir_list, directory)
180  
181          if os.path.normpath(sys.prefix) != '/usr' \
182 -                and not sysconfig.get_config_var('PYTHONFRAMEWORK'):
183 +                and not sysconfig.get_config_var('PYTHONFRAMEWORK') \
184 +                and not self.cross_compile:
185              # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
186              # (PYTHONFRAMEWORK is set) to avoid # linking problems when
187              # building a framework with different architectures than
188 @@ -426,11 +437,14 @@ class PyBuildExt(build_ext):
189          # lib_dirs and inc_dirs are used to search for files;
190          # if a file is found in one of those directories, it can
191          # be assumed that no additional -I,-L directives are needed.
192 -        lib_dirs = self.compiler.library_dirs + [
193 -            '/lib64', '/usr/lib64',
194 -            '/lib', '/usr/lib',
195 -            ]
196 -        inc_dirs = self.compiler.include_dirs + ['/usr/include']
197 +        lib_dirs = self.compiler.library_dirs
198 +        inc_dirs = self.compiler.include_dirs
199 +        if not self.cross_compile:
200 +            lib_dirs += [
201 +                '/lib64', '/usr/lib64',
202 +                '/lib', '/usr/lib',
203 +                ]
204 +            inc_dirs += ['/usr/include']
205          exts = []
206          missing = []
207  
208 @@ -1864,8 +1878,15 @@ class PyBuildExt(build_ext):
209  
210                  # Pass empty CFLAGS because we'll just append the resulting
211                  # CFLAGS to Python's; -g or -O2 is to be avoided.
212 -                cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
213 -                      % (ffi_builddir, ffi_srcdir, " ".join(config_args))
214 +                if self.cross_compile:
215 +                    cmd = "cd %s && env CFLAGS='' %s/configure --host=%s --build=%s %s" \
216 +                          % (ffi_builddir, ffi_srcdir,
217 +                             os.environ.get('HOSTARCH'),
218 +                             os.environ.get('BUILDARCH'),
219 +                             " ".join(config_args))
220 +                else:
221 +                    cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
222 +                          % (ffi_builddir, ffi_srcdir, " ".join(config_args))
223  
224                  res = os.system(cmd)
225                  if res or not os.path.exists(ffi_configfile):
226 -- 
227 1.7.9.5