diff --git a/kiwixbuild/patches/fixenv-nonstd-libdir b/kiwixbuild/patches/fixenv-nonstd-libdir new file mode 100644 index 0000000..0db8731 --- /dev/null +++ b/kiwixbuild/patches/fixenv-nonstd-libdir @@ -0,0 +1,27 @@ +#!/bin/sh + +BASENAME=`basename $0` +SCRIPT=`realpath $0` +SCRIPTPATH=`dirname $SCRIPT` + +if ! test -L "$0" +then + cd "$SCRIPTPATH" && find -type f | grep -v ".real$" | \ + while read b + do + if hexdump -C "$b" | head -1 | grep -q ELF + then + mv -iv "$b" "$b.real" + ln -s "$BASENAME" "$b" + fi + done +else + for fullarch in "" mips-linux-uclibc + do for libdir in usr/lib lib + do LD_LIBRARY_PATH="${SCRIPTPATH%/bin}/$libdir/$fullarch:$LD_LIBRARY_PATH" + done + done + + export LD_LIBRARY_PATH + exec ${SCRIPTPATH}/$BASENAME.real "$@" +fi diff --git a/kiwixbuild/patches/fixenv-nonstd-libdir.sh b/kiwixbuild/patches/fixenv-nonstd-libdir.sh deleted file mode 100644 index 477f035..0000000 --- a/kiwixbuild/patches/fixenv-nonstd-libdir.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -if ! test -f kiwix-serve -then - echo Needs to run in the same directory that hosts kiwix-serve binary. - exit 1 -fi - -find -type f | \ -while read -do - if hexdump -C $REPLY | head -1 | grep -q ELF - then - mv -iv "$REPLY" "$REPLY.real" - ln -s run-nonroot "$REPLY" - fi -done - -cat <<'EOF' > run-nonroot -#!/bin/sh - -BASENAME=`basename $0` -SCRIPT=`realpath $0` -SCRIPTPATH=`dirname $SCRIPT` - -if test x"$BASENAME" != xrun-nonroot -then - for fullarch in "" ${ARCH_FULL:-mips-linux-gnu} - do for libdir in usr/lib lib - do LD_LIBRARY_PATH="${SCRIPTPATH%/bin}/$libdir/$fullarch:$LD_LIBRARY_PATH" - done - done - - export LD_LIBRARY_PATH - exec ${SCRIPTPATH}/$BASENAME.real "$@" -fi -EOF - -chmod +x run-nonroot diff --git a/kiwixbuild/platforms/mips32r2.py b/kiwixbuild/platforms/mips32r2.py index 0d123d9..2b2797e 100644 --- a/kiwixbuild/platforms/mips32r2.py +++ b/kiwixbuild/platforms/mips32r2.py @@ -2,19 +2,28 @@ from .base import PlatformInfo, _SCRIPT_DIR from kiwixbuild.utils import pj from kiwixbuild._global import get_target_step -from re import sub as sed from glob import glob from os import makedirs, chmod, readlink, symlink from os.path import basename, islink +from re import sub as subst from shutil import copy2 -def copy(src, dst): +def copy(src, dst, search=None, repl=None, mode=None): if islink(src): linkto = readlink(src) symlink(linkto, dst) else: - copy2(src,dst) + if search is None: + copy2(src, dst) + else: + with open(src, "r") as sources: + lines = sources.readlines() + with open(dst, "w") as sources: + for line in lines: + sources.write(subst(search, repl, line)) + if mode is not None: + chmod(dst, mode) class MIPS32R2PlatformInfo(PlatformInfo): @@ -115,7 +124,7 @@ class MIPS32R2Static(MIPS32R2PlatformInfo): class MIPS32R2_UC_GCXXPlatformInfo(MIPS32R2PlatformInfo): - build = 'mips32r2_uclibc_gclibcxx' # "shared, heterogeneous" + build = 'mips32r2_uclibc_glibcxx' # "shared, heterogeneous" arch_full = 'mips-linux-uclibc' @property @@ -140,12 +149,11 @@ class MIPS32R2_UC_GCXXDyn(MIPS32R2_UC_GCXXPlatformInfo): d = pj(_SCRIPT_DIR, '..', '..', 'BUILD_'+self.name, 'INSTALL') makedirs(pj(d, 'bin'), mode=0o755, exist_ok=True) - with open(pj(_SCRIPT_DIR, '..', 'patches', 'fixenv-nonstd-libdir.sh'), "r") as sources: - lines = sources.readlines() - with open(pj(d, 'bin', 'fixenv-nonstd-libdir'), "w") as sources: - for line in lines: - sources.write(sed(r'\$\{ARCH_FULL[^}]*\}', self.arch_full, line)) - chmod(pj(d, 'bin', 'fixenv-nonstd-libdir'), 0o755) + copy(pj(_SCRIPT_DIR, '..', 'patches', 'fixenv-nonstd-libdir'), + pj(d, 'bin', 'fixenv-nonstd-libdir'), + search=r'\$\{ARCH_FULL[^}]*\}', + repl=self.arch_full, + mode=0o755) d = pj(d, 'lib', self.arch_full) makedirs(d, mode=0o755, exist_ok=True)