Implement new way to override libc functions from within shared as well as static...
[xbmc:xbmc-antiquated.git] / xbmc / lib / libPython / linux / Makefile.in
1 ARCH=@ARCH@
2 CC=@CC@
3 CFLAGS=@CFLAGS@
4 LDFLAGS=@LDFLAGS@
5 SHELL=/bin/bash
6 SYSDIR=../../../../system/python
7
8 ifeq (@USE_PYTHON2_6@,1)
9     PYVERSION=python2.6
10     SO=python26-$(ARCH).so
11 else ifeq (@USE_PYTHON2_5@,1)
12     PYVERSION=python2.5
13     SO=python25-$(ARCH).so
14 else ifeq (@USE_PYTHON2_4@,1)
15     PYVERSION=python2.4
16     SO=python24-$(ARCH).so
17 else
18     SO=python24-$(ARCH).so
19 endif
20 SLIB=$(SYSDIR)/$(SO)
21 ZIP=$(SYSDIR)/python24.zip  ##Should probably add arch here too
22 DIRS=../Python
23 WRAPPER=../../../cores/DllLoader/exports/wrapper.o
24 WRAPPERDEF=$(WRAPPER:.o=.def)
25 PYWRAP=wrapper_python.o
26 PYWRAPDEF=$(PYWRAP:.o=.def)
27 ifeq ($(ARCH), powerpc64-linux)
28         PYLIBDIR=lib.linux-ppc64-2.4
29 else
30 ifeq ($(ARCH), powerpc-linux)
31         PYLIBDIR=lib.linux-ppc-2.4
32 else
33 ifeq ($(ARCH), x86_64-linux)
34         PYLIBDIR=lib.linux-x86_64-2.4
35 else
36 ifeq ($(ARCH), arm)
37         PYLIBDIR=lib.linux-armv6tel-2.4
38 else
39         PYLIBDIR=lib.linux-i686-2.4
40 endif
41 endif
42 endif
43 endif
44
45 PYDIRS=bsddb compiler curses distutils email encodings hotshot idlelib \
46         lib-old lib-tk logging site-packages xml
47 ifeq ($(findstring osx,$(ARCH)),osx)
48         PYLIBDIR=lib.macosx-10.4-@ARCHTYPE@-2.4
49         PYDIRS+=plat-darwin
50         PYDIRS+=plat-mac
51 else
52         PYDIRS+=plat-linux2
53 endif
54
55 PY=$(wildcard ../Python/Lib/*.py)
56 PY+=$(foreach DIR, $(PYDIRS), $(wildcard ../Python/Lib/$(DIR)/*.py))
57 PY+=$(foreach DIR, $(PYDIRS), $(wildcard ../Python/Lib/$(DIR)/*/*.py))
58 PY+=$(foreach DIR, $(PYDIRS), $(wildcard ../Python/Lib/$(DIR)/*/*/*.py))
59 PYC=$(addsuffix c, $(PY))
60 PYO=$(addsuffix o, $(PY))
61
62 .PHONY: compile
63
64 ifeq ($(findstring osx,$(ARCH)), osx)
65 all: $(SLIB)
66
67 $(SLIB): $(PYWRAP) ../Python/libpython2.4.a $(PYO) ../../../../tools/Mach5/wrapper.rb
68         rm -rf $(SYSDIR)/Lib
69         rsync -a --exclude '.svn' -t ../Python/build/$(PYLIBDIR)/*.so $(SYSDIR)/Lib
70         rsync -a --exclude '.svn' -t ../Python/Lib/*.{py,pyo} $(SYSDIR)/Lib
71         for dirs in $(PYDIRS); do rsync -a --exclude 'test*'  --exclude '.svn' ../Python/Lib/$$dirs $(SYSDIR)/Lib; done
72         (mkdir -p tmp && rm -rf tmp/*)
73         (cd ./tmp && ar x ../../Python/libpython2.4.a)
74         $(CXX) -bundle -flat_namespace -undefined suppress -shared -o $@ \
75                 tmp/*.o \
76                 wrapper_python.o
77         ../../../../tools/Mach5/wrapper.rb $@ libpython;mv output.so $@
78         ../../../../tools/Mach5/wrapper.rb $@;mv output.so $@
79         @rm -rf tmp
80
81 ../Python/libpython2.4.a: compile
82         $(MAKE) -C ../Python
83
84 %pyo: %py
85         @echo Compiling $@
86         @../Python/python.exe -O ../Python/Lib/py_compile.py $<
87
88 $(PYWRAP): $(PYWRAP:.o=.c)
89          $(CC) $(CFLAGS) -fPIC -o $@ -D_FILE_DEFINED -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c $<
90
91 else
92 all: $(SLIB)
93 ifneq (@USE_EXTERNAL_PYTHON@,1)
94         $(MAKE) $(ZIP)
95 endif
96
97 ifneq (@USE_EXTERNAL_PYTHON@,1)
98 $(SLIB): $(WRAPPER) $(WRAPPERDEF) $(PYWRAP) $(PYWRAPDEF) ../Python/libpython2.4.a
99         $(CC) $(LDFLAGS) -shared -o $@ -Wl,--whole-archive ../Python/libpython2.4.a \
100                 -Wl,--no-whole-archive `cat wrapper_python.def` wrapper_python.o \
101                 `cat ../../../cores/DllLoader/exports/wrapper.def` \
102                 ../../../cores/DllLoader/exports/wrapper.o
103 else
104 $(SLIB): $(PYWRAP)
105         $(CC) $(LDFLAGS) -shared -o $@ -Wl,--no-as-needed $(PYWRAP) \
106                 -l$(PYVERSION)
107 endif
108
109 $(ZIP): $(PYC) $(PYO)
110         pushd ../Python/build/$(PYLIBDIR)/ && \
111                 zip -0guq ../../$@ *.so; \
112                 popd
113         pushd ../Python/Lib/ && \
114                 zip -0gurq ../$@ *.py* $(PYDIRS) -x *.svn* *test*; \
115                 popd
116
117 ../Python/libpython2.4.a: compile
118         $(MAKE) -C ../Python
119
120 %pyc: %py
121         @echo Compiling $@
122         @LD_PRELOAD=../Python/libpython2.4.so.1.0 ../Python/python \
123                 ../Python/Lib/py_compile.py $<
124
125 %pyo: %py
126         @echo Compiling $@
127         @LD_PRELOAD=../Python/libpython2.4.so.1.0 ../Python/python -O \
128                 ../Python/Lib/py_compile.py $<
129
130 $(PYWRAP): $(PYWRAP:.o=.c)
131          $(CC) $(CFLAGS) -fPIC -o $@ -D_FILE_DEFINED -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c $<
132
133 $(PYWRAPDEF): $(PYWRAPDEF:.def=.c)
134         LD_OPTS=$$(for func in $$(grep PYTHON_WRAP wrapper_python.c | \
135             grep -v define | awk -F ')' '{print $$1}' | \
136             awk -F'(' '{print $$2}' | grep -v '^l*stat$$' | \
137             awk '{printf("%s ",$$0);}'); \
138             do echo -n "-Wl,-wrap,$$func "; done); \
139             echo -n $$LD_OPTS > $@
140
141 endif
142
143
144
145 clean:
146         for d in $(DIRS); do [ ! -f $$d/Makefile ] || make -C $$d clean; done
147         rm -f $(SLIB) $(ZIP) $(PYC) $(PYO) ../Python/libpython2.4.a $(PYWRAP) $(PYWRAPDEF)
148 ifeq ($(findstring osx,$(ARCH)), osx)
149         rm -rf $(SYSDIR)/Lib
150 endif
151
152 distclean:
153         for d in $(DIRS); do [ ! -f $$d/Makefile ] || make -C $$d distclean; done
154         rm -f $(SLIB) $(ZIP) $(PYC) $(PYO) ../Python/libpython2.4.a $(PYWRAP) $(PYWRAPDEF)
155 ifeq ($(findstring osx,$(ARCH)), osx)
156         rm -rf $(SYSDIR)/Lib
157 endif
158
159
160