1
0
Files
electrum/contrib/make_libusb.sh
SomberNight 0df8392c86 build: rm need for sudo in most places; and do not run as root
This includes two logically separate changes:
- on the host, try not to require sudo when running the build scripts
    - namely when interacting with the docker daemon, this requires
      the unix user on the host to be part of the `docker` group
    - this solves part of https://github.com/spesmilo/electrum/issues/7602
- while running inside the docker containers, do not run as root
    - this means that e.g. files created in mounted folders should
      no longer be owned by root on the host
    - there is some code duplication involved here - not sure
      how it could be deduped.
2022-03-03 19:24:18 +01:00

64 lines
2.2 KiB
Bash
Executable File

#!/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 || warn "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
)