Browse Source

mac build: build libusb from source

fixes https://github.com/spesmilo/electrum/issues/7393
patch-4
SomberNight 3 years ago
parent
commit
5b627208f1
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 1
      .gitignore
  2. 6
      contrib/build-wine/make_win.sh
  3. 32
      contrib/build-wine/prepare-wine.sh
  4. 63
      contrib/make_libusb.sh
  5. 13
      contrib/osx/make_osx

1
.gitignore

@ -36,6 +36,7 @@ contrib/android/fresh_clone
contrib/android/android_debug.keystore contrib/android/android_debug.keystore
contrib/secp256k1/ contrib/secp256k1/
contrib/zbar/ contrib/zbar/
contrib/libusb/
contrib/osx/build-venv/ contrib/osx/build-venv/
# shared objects # shared objects

6
contrib/build-wine/make_win.sh

@ -53,6 +53,12 @@ else
"$CONTRIB"/make_zbar.sh || fail "Could not build zbar" "$CONTRIB"/make_zbar.sh || fail "Could not build zbar"
fi fi
if [ -f "$DLL_TARGET_DIR/libusb-1.0.dll" ]; then
info "libusb already built, skipping"
else
"$CONTRIB"/make_libusb.sh || fail "Could not build libusb"
fi
"$here/prepare-wine.sh" || fail "prepare-wine failed" "$here/prepare-wine.sh" || fail "prepare-wine failed"
info "Resetting modification time in C:\Python..." info "Resetting modification time in C:\Python..."

32
contrib/build-wine/prepare-wine.sh

@ -5,10 +5,6 @@ NSIS_FILENAME=nsis-3.05-setup.exe
NSIS_URL=https://downloads.sourceforge.net/project/nsis/NSIS%203/3.05/$NSIS_FILENAME NSIS_URL=https://downloads.sourceforge.net/project/nsis/NSIS%203/3.05/$NSIS_FILENAME
NSIS_SHA256=1a3cc9401667547b9b9327a177b13485f7c59c2303d4b6183e7bc9e6c8d6bfdb NSIS_SHA256=1a3cc9401667547b9b9327a177b13485f7c59c2303d4b6183e7bc9e6c8d6bfdb
LIBUSB_REPO="https://github.com/libusb/libusb.git"
LIBUSB_COMMIT="c6a35c56016ea2ab2f19115d2ea1e85e0edae155"
# ^ tag v1.0.24
PYINSTALLER_REPO="https://github.com/SomberNight/pyinstaller.git" PYINSTALLER_REPO="https://github.com/SomberNight/pyinstaller.git"
PYINSTALLER_COMMIT="80ee4d613ecf75a1226b960a560ee01459e65ddb" PYINSTALLER_COMMIT="80ee4d613ecf75a1226b960a560ee01459e65ddb"
# ^ tag 4.2, plus a custom commit that fixes cross-compilation with MinGW # ^ tag 4.2, plus a custom commit that fixes cross-compilation with MinGW
@ -64,36 +60,10 @@ verify_hash "$CACHEDIR/$NSIS_FILENAME" "$NSIS_SHA256"
wine "$CACHEDIR/$NSIS_FILENAME" /S wine "$CACHEDIR/$NSIS_FILENAME" /S
info "Compiling libusb..."
(
cd "$CACHEDIR"
if [ -f "libusb/libusb/.libs/libusb-1.0.dll" ]; then
info "libusb-1.0.dll already built, skipping"
exit 0
fi
rm -rf libusb
mkdir libusb
cd libusb
# Shallow clone
git init
git remote add origin $LIBUSB_REPO
git fetch --depth 1 origin $LIBUSB_COMMIT
git checkout -b pinned "${LIBUSB_COMMIT}^{commit}"
echo "libusb_1_0_la_LDFLAGS += -Wc,-static" >> libusb/Makefile.am
./bootstrap.sh || fail "Could not bootstrap libusb"
host="$GCC_TRIPLET_HOST"
LDFLAGS="-Wl,--no-insert-timestamp" ./configure \
--host=$host \
--build=$GCC_TRIPLET_BUILD || fail "Could not run ./configure for libusb"
make -j4 || fail "Could not build libusb"
${host}-strip libusb/.libs/libusb-1.0.dll
) || fail "libusb build failed"
cp "$CACHEDIR/libusb/libusb/.libs/libusb-1.0.dll" $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libusb to its destination"
# copy already built DLLs # copy already built DLLs
cp "$DLL_TARGET_DIR/libsecp256k1-0.dll" $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libsecp to its destination" cp "$DLL_TARGET_DIR/libsecp256k1-0.dll" $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libsecp to its destination"
cp "$DLL_TARGET_DIR/libzbar-0.dll" $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libzbar to its destination" cp "$DLL_TARGET_DIR/libzbar-0.dll" $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libzbar to its destination"
cp "$DLL_TARGET_DIR/libusb-1.0.dll" $WINEPREFIX/drive_c/tmp/ || fail "Could not copy libusb to its destination"
info "Building PyInstaller." info "Building PyInstaller."

63
contrib/make_libusb.sh

@ -0,0 +1,63 @@
#!/bin/bash
LIBUSB_VERSION="c6a35c56016ea2ab2f19115d2ea1e85e0edae155"
# ^ tag v1.0.24
set -e
. $(dirname "$0")/build_tools_util.sh || (echo "Could not source build_tools_util.sh" && exit 1)
here=$(dirname $(realpath "$0" 2> /dev/null || grealpath "$0"))
CONTRIB="$here"
PROJECT_ROOT="$CONTRIB/.."
pkgname="libusb"
info "Building $pkgname..."
(
cd $CONTRIB
if [ ! -d libusb ]; then
git clone https://github.com/libusb/libusb.git
fi
cd libusb
if ! $(git cat-file -e ${LIBUSB_VERSION}) ; then
info "Could not find requested version $LIBUSB_VERSION in local clone; fetching..."
git fetch --all
fi
git reset --hard
git clean -dfxq
git checkout "${LIBUSB_VERSION}^{commit}"
if [ "$BUILD_TYPE" = "wine" ] ; then
echo "libusb_1_0_la_LDFLAGS += -Wc,-static" >> libusb/Makefile.am
fi
./bootstrap.sh || fail "Could not bootstrap libusb"
if ! [ -r config.status ] ; then
if [ "$BUILD_TYPE" = "wine" ] ; then
# windows target
LDFLAGS="-Wl,--no-insert-timestamp"
elif [ $(uname) == "Darwin" ]; then
# macos target
LDFLAGS="-Wl -lm"
else
# linux target
LDFLAGS=""
fi
LDFLAGS="$LDFLAGS" ./configure \
$AUTOCONF_FLAGS \
|| fail "Could not configure $pkgname. Please make sure you have a C compiler installed and try again."
fi
make -j4 || fail "Could not build $pkgname"
make install || fail "Could not install $pkgname"
. "$here/$pkgname/libusb/.libs/libusb-1.0.la"
host_strip "$here/$pkgname/libusb/.libs/$dlname"
TARGET_NAME="$dlname"
if [ $(uname) == "Darwin" ]; then # on mac, dlname is "libusb-1.0.0.dylib"
TARGET_NAME="libusb-1.0.dylib"
fi
cp -fpv "$here/$pkgname/libusb/.libs/$dlname" "$PROJECT_ROOT/electrum/$TARGET_NAME" || fail "Could not copy the $pkgname binary to its destination"
info "$TARGET_NAME has been placed in the inner 'electrum' folder."
if [ -n "$DLL_TARGET_DIR" ] ; then
cp -fpv "$here/$pkgname/libusb/.libs/$dlname" "$DLL_TARGET_DIR/$TARGET_NAME" || fail "Could not copy the $pkgname binary to DLL_TARGET_DIR"
fi
)

13
contrib/osx/make_osx

@ -21,7 +21,7 @@ cd "$src_dir/../.."
which brew > /dev/null 2>&1 || fail "Please install brew from https://brew.sh/ to continue" which brew > /dev/null 2>&1 || fail "Please install brew from https://brew.sh/ to continue"
which xcodebuild > /dev/null 2>&1 || fail "Please install Xcode and xcode command line tools to continue" which xcodebuild > /dev/null 2>&1 || fail "Please install xcode command line tools to continue"
# Code Signing: See https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html # Code Signing: See https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html
if [ -n "$CODESIGN_CERT" ]; then if [ -n "$CODESIGN_CERT" ]; then
@ -115,13 +115,6 @@ info "generating locale"
) || fail "failed generating locale" ) || fail "failed generating locale"
info "Downloading libusb..."
curl https://homebrew.bintray.com/bottles/libusb-1.0.23.high_sierra.bottle.tar.gz | \
tar xz --directory "$BUILDDIR"
cp "$BUILDDIR/libusb/1.0.23/lib/libusb-1.0.dylib" contrib/osx
echo "caea266f3fc3982adc55d6cb8d9bad10f6e61f0c24ce5901aa1804618e08e14d contrib/osx/libusb-1.0.dylib" | \
shasum -a 256 -c || fail "libusb checksum mismatched"
info "Installing some build-time deps for compilation..." info "Installing some build-time deps for compilation..."
brew install autoconf automake libtool gettext coreutils pkgconfig brew install autoconf automake libtool gettext coreutils pkgconfig
@ -133,6 +126,10 @@ info "Building ZBar dylib..."
"$CONTRIB"/make_zbar.sh || fail "Could not build ZBar dylib" "$CONTRIB"/make_zbar.sh || fail "Could not build ZBar dylib"
cp "$ROOT_FOLDER"/electrum/libzbar.0.dylib "$CONTRIB"/osx cp "$ROOT_FOLDER"/electrum/libzbar.0.dylib "$CONTRIB"/osx
info "Building libusb dylib..."
"$CONTRIB"/make_libusb.sh || fail "Could not build libusb dylib"
cp "$ROOT_FOLDER"/electrum/libusb-1.0.dylib "$CONTRIB"/osx
info "Installing requirements..." info "Installing requirements..."
python3 -m pip install --no-dependencies --no-warn-script-location -Ir ./contrib/deterministic-build/requirements.txt \ python3 -m pip install --no-dependencies --no-warn-script-location -Ir ./contrib/deterministic-build/requirements.txt \

Loading…
Cancel
Save