Skip to content

Commit 2854e45

Browse files
committed
reintroduce liblink/biglink. redirect the python obj link to temporary files, and use it to create a big libpymodules.so. closes kivy#3
right now, only used for kivy, android, lxml, pygame and pil.
1 parent cb77423 commit 2854e45

File tree

9 files changed

+176
-1
lines changed

9 files changed

+176
-1
lines changed

distribute.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ SRC_PATH="$ROOT_PATH/src"
1919
JNI_PATH="$SRC_PATH/jni"
2020
DIST_PATH="$ROOT_PATH/dist/default"
2121

22+
# Tools
23+
export LIBLINK_PATH="$BUILD_PATH/objects"
24+
export LIBLINK="$ROOT_PATH/src/tools/liblink"
25+
export BIGLINK="$ROOT_PATH/src/tools/biglink"
26+
2227
# Internals
2328
CRED="\x1b[31;01m"
2429
CBLUE="\x1b[34;01m"
@@ -80,6 +85,7 @@ function push_arm() {
8085
export OLD_RANLIB=$RANLIB
8186
export OLD_STRIP=$STRIP
8287
export OLD_MAKE=$MAKE
88+
export OLD_LD=$LD
8389

8490
# to override the default optimization, set OFLAG
8591
#export OFLAG="-Os"
@@ -121,6 +127,7 @@ function push_arm() {
121127
export CXX="$TOOLCHAIN_PREFIX-g++ $CXXFLAGS"
122128
export AR="$TOOLCHAIN_PREFIX-ar"
123129
export RANLIB="$TOOLCHAIN_PREFIX-ranlib"
130+
export LD="$TOOLCHAIN_PREFIX-ld"
124131
export STRIP="$TOOLCHAIN_PREFIX-strip --strip-unneeded"
125132
export MAKE="make -j5"
126133

@@ -140,6 +147,7 @@ function pop_arm() {
140147
export CC=$OLD_CC
141148
export CXX=$OLD_CXX
142149
export AR=$OLD_AR
150+
export LD=$OLD_LD
143151
export RANLIB=$OLD_RANLIB
144152
export STRIP=$OLD_STRIP
145153
export MAKE=$OLD_MAKE
@@ -239,6 +247,7 @@ function run_prepare() {
239247
test -d $PACKAGES_PATH || mkdir -p $PACKAGES_PATH
240248
test -d $BUILD_PATH || mkdir -p $BUILD_PATH
241249
test -d $LIBS_PATH || mkdir -p $LIBS_PATH
250+
test -d $LIBLINK_PATH || mkdir -p $LIBLINK_PATH
242251

243252
# create initial files
244253
echo "target=android-$ANDROIDAPI" > $SRC_PATH/default.properties
@@ -486,6 +495,7 @@ function run_distribute() {
486495
debug "Fill private directory"
487496
try cp -a python-install/lib private/
488497
try mkdir -p private/include/python2.7
498+
try mv libs/$ARCH/libpymodules.so private/
489499
try cp python-install/include/python2.7/pyconfig.h private/include/python2.7/
490500

491501
debug "Reduce private directory from unwanted files"
@@ -519,12 +529,19 @@ function run_distribute() {
519529

520530
}
521531

532+
function run_biglink() {
533+
push_arm
534+
try $BIGLINK $LIBS_PATH/libpymodules.so $LIBLINK_PATH
535+
pop_arm
536+
}
537+
522538
function run() {
523539
run_prepare
524540
run_source_modules
525541
run_get_packages
526542
run_prebuild
527543
run_build
544+
run_biglink
528545
run_postbuild
529546
run_distribute
530547
info "All done !"
@@ -536,6 +553,23 @@ function list_modules() {
536553
exit 0
537554
}
538555

556+
# one method to deduplicate some symbol in libraries
557+
function arm_deduplicate() {
558+
fn=$(basename $1)
559+
echo "== Trying to remove duplicate symbol in $1"
560+
push_arm
561+
try mkdir ddp
562+
try cd ddp
563+
try $AR x $1
564+
try $AR rc $fn *.o
565+
try $RANLIB $fn
566+
try mv -f $fn $1
567+
try cd ..
568+
try rm -rf ddp
569+
pop_arm
570+
}
571+
572+
539573
# Do the build
540574
while getopts ":hvlfm:d:" opt; do
541575
case $opt in

recipes/android/recipe.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function build_android() {
2626
push_arm
2727

2828
export LDFLAGS="$LDFLAGS -L$LIBS_PATH"
29+
export LDSHARED="$LIBLINK"
2930

3031
# cythonize
3132
try cython android.pyx
@@ -38,6 +39,8 @@ function build_android() {
3839
try cp android_mixer.py \
3940
$BUILD_PATH/python-install/lib/python2.7/
4041

42+
unset LDSHARED
43+
4144
touch .done
4245
pop_arm
4346
}

recipes/kivy/recipe.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ function prebuild_kivy() {
1414
function build_kivy() {
1515
if [ -d "$BUILD_PATH/python-install/lib/python2.7/site-packages/kivy" ]; then
1616
return
17+
true
1718
fi
1819

1920
cd $BUILD_kivy
2021

2122
push_arm
2223

2324
export LDFLAGS="$LDFLAGS -L$LIBS_PATH"
25+
export LDSHARED="$LIBLINK"
2426

2527
# fake try to be able to cythonize generated files
2628
$BUILD_PATH/python-install/bin/python.host setup.py build_ext
@@ -31,6 +33,7 @@ function build_kivy() {
3133

3234
try rm -rf $BUILD_PATH/python-install/lib/python*/site-packages/kivy/tools
3335

36+
unset LDSHARED
3437
pop_arm
3538
}
3639

recipes/lxml/recipe.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ function build_lxml() {
2222

2323
export CC="$CC -I$BUILD_libxml2/include -I$BUILD_libxslt"
2424
export LDFLAGS="$LDFLAGS -L$BUILD_libxslt/libxslt/.libs -L$BUILD_libxslt/libexslt/.libs -L$BUILD_libxml2/.libs"
25+
export LDSHARED="$LIBLINK"
2526

2627
try $BUILD_PATH/python-install/bin/python.host setup.py build_ext
2728
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
2829

30+
unset LDSHARED
2931
pop_arm
3032
}
3133

recipes/pil/recipe.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ function build_pil() {
4141
LIBS="$SRC_PATH/obj/local/$ARCH"
4242
export CFLAGS="$CFLAGS -I$JNI_PATH/png -I$JNI_PATH/jpeg"
4343
export LDFLAGS="$LDFLAGS -L$LIBS -lm -lz"
44+
export LDSHARED="$LIBLINK"
4445
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
4546

47+
unset LDSHARED
4648
pop_arm
4749
}
4850

recipes/pygame/recipe.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function build_pygame() {
3434
CFLAGS="$CFLAGS -I$JNI_PATH/sdl_ttf -I$JNI_PATH/sdl_image"
3535
export CFLAGS="$CFLAGS"
3636
export LDFLAGS="$LDFLAGS -L$LIBS_PATH -L$SRC_PATH/obj/local/$ARCH/ -lm -lz"
37+
export LDSHARED="$LIBLINK"
3738
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
3839
try find build/lib.* -name "*.o" -exec $STRIP {} \;
3940

@@ -42,6 +43,7 @@ function build_pygame() {
4243
try rm -rf $BUILD_PATH/python-install/lib/python*/site-packages/pygame/tests
4344
try rm -rf $BUILD_PATH/python-install/lib/python*/site-packages/pygame/gp2x
4445

46+
unset LDSHARED
4547
pop_arm
4648
}
4749

src/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def select(fn):
114114
fn = fn[len(d):]
115115
if fn.startswith('/site-packages/') or \
116116
fn.startswith('/config/') or \
117-
fn.startswith('/lib-dynload/'):
117+
fn.startswith('/lib-dynload/') or \
118+
fn.startswith('/libpymodules.so'):
118119
return False
119120
return fn
120121

src/tools/biglink

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
import subprocess
6+
7+
sofiles = [ ]
8+
9+
for directory in sys.argv[2:]:
10+
11+
for fn in os.listdir(directory):
12+
fn = os.path.join(directory, fn)
13+
14+
if not fn.endswith(".so.o"):
15+
continue
16+
if not os.path.exists(fn[:-2] + ".libs"):
17+
continue
18+
19+
sofiles.append(fn[:-2])
20+
21+
# The raw argument list.
22+
args = [ ]
23+
24+
for fn in sofiles:
25+
afn = fn + ".o"
26+
libsfn = fn + ".libs"
27+
28+
args.append(afn)
29+
with open(libsfn) as fd:
30+
data = fd.read()
31+
args.extend(data.split(" "))
32+
33+
unique_args = [ ]
34+
while args:
35+
a = args.pop()
36+
if a in ('-L', ):
37+
continue
38+
if a not in unique_args:
39+
unique_args.insert(0, a)
40+
41+
42+
print 'Biglink create %s library' % sys.argv[1]
43+
print 'Biglink arguments:'
44+
for arg in unique_args:
45+
print '', arg
46+
47+
args = os.environ['CC'].split() + \
48+
['-shared', '-O3', '-o', sys.argv[1]] + \
49+
unique_args
50+
51+
sys.exit(subprocess.call(args))

src/tools/liblink

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import subprocess
5+
from os import environ
6+
from os.path import basename, join
7+
8+
libs = [ ]
9+
objects = [ ]
10+
output = None
11+
12+
13+
i = 1
14+
while i < len(sys.argv):
15+
opt = sys.argv[i]
16+
i += 1
17+
18+
if opt == "-o":
19+
output = sys.argv[i]
20+
i += 1
21+
continue
22+
23+
if opt.startswith("-l") or opt.startswith("-L"):
24+
libs.append(opt)
25+
continue
26+
27+
if opt in ("-r", "-pipe", "-no-cpp-precomp"):
28+
continue
29+
30+
if opt in ("--sysroot", "-isysroot", "-framework", "-undefined",
31+
"-macosx_version_min"):
32+
i += 1
33+
continue
34+
35+
if opt.startswith("-I"):
36+
continue
37+
38+
if opt.startswith("-m"):
39+
continue
40+
41+
if opt.startswith("-f"):
42+
continue
43+
44+
if opt.startswith("-O"):
45+
continue
46+
47+
if opt.startswith("-g"):
48+
continue
49+
50+
if opt.startswith("-D"):
51+
continue
52+
53+
if opt.startswith("-"):
54+
print sys.argv
55+
print "Unknown option: ", opt
56+
sys.exit(1)
57+
58+
if not opt.endswith('.o'):
59+
continue
60+
61+
objects.append(opt)
62+
63+
64+
f = file(output, "w")
65+
f.close()
66+
67+
output = join(environ.get('LIBLINK_PATH'), basename(output))
68+
69+
f = file(output + ".libs", "w")
70+
f.write(" ".join(libs))
71+
f.close()
72+
73+
sys.exit(subprocess.call([
74+
environ.get('LD'), '-r',
75+
'-o', output + '.o', '-arch',
76+
environ.get('ARCH')] + objects))
77+

0 commit comments

Comments
 (0)