Skip to content
Snippets Groups Projects
Commit b69d703e authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

macOS: fix qrencode build

Sometimes qrencode failed when built from Jenkins.
This patch:
- Uses cmake for build.
- Automatically detect host architecture if none is specified.

Change-Id: I18dc90099e3b9efc531c7887b00fc615f69c50fa
parent bfe91287
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
# Flags: # Usage:
# ./build_qrencode.sh -a <architecture>
# -a: architecture to build. Accepted values arm64, x86_64, unified # Accepted architectures: arm64, x86_64, unified
# If no architecture is specified, the script builds for the host architecture.
# Initialize variables
arch='' arch=''
while getopts "a:" OPT; do while getopts "a:" OPT; do
case "$OPT" in case "$OPT" in
a) a)
arch="${OPTARG}" arch="${OPTARG}"
;; ;;
\?) \?)
exit 1 echo "Invalid option: -$OPTARG" >&2
;; echo "Usage: $0 [-a architecture]"
echo "Accepted architectures: arm64, x86_64, unified"
exit 1
;;
esac esac
done done
# Determine architectures to build
if [[ "$arch" == 'unified' ]]; then if [[ "$arch" == 'unified' ]]; then
ARCHS=("arm64" "x86_64") ARCHS=("arm64" "x86_64")
elif [[ "$arch" == '' ]]; then elif [[ "$arch" == '' ]]; then
ARCHS=("arm64") # Detect host architecture
HOST_ARCH=$(uname -m)
case "$HOST_ARCH" in
x86_64|arm64)
ARCHS=("$HOST_ARCH")
;;
*)
echo "Unsupported host architecture: $HOST_ARCH"
echo "Supported architectures are: arm64, x86_64, unified"
exit 1
;;
esac
else else
ARCHS=("$arch") # Validate specified architecture
case "$arch" in
x86_64|arm64)
ARCHS=("$arch")
;;
*)
echo "Invalid architecture specified: $arch"
echo "Accepted architectures are: arm64, x86_64, unified"
exit 1
;;
esac
fi fi
TOP="$(pwd)" TOP="$(pwd)"
QRENCODEDIR="${TOP}/3rdparty/libqrencode" QRENCODEDIR="${TOP}/3rdparty/libqrencode"
if [ -z "$NPROC" ]; then BUILDDIR="${QRENCODEDIR}/build-libqrencode"
NPROC=$(sysctl -n hw.ncpu || echo -n 1) LIBDIR="${QRENCODEDIR}/lib"
fi INCLUDEDIR="${QRENCODEDIR}/include"
for ARCH in "${ARCHS[@]}"; do # Clean up build directory
cd "$QRENCODEDIR" || exit 1 echo "Preparing clean build directory"
BUILDDIR="$ARCH-libqrencode" rm -rf "$BUILDDIR"
mkdir "$BUILDDIR" mkdir -p "$BUILDDIR"
make clean
./autogen.sh # Clean output directories
./configure --host="$ARCH" --without-png --prefix="${QRENCODEDIR}/${BUILDDIR}" CFLAGS=" -arch $ARCH $CFLAGS" rm -rf "$LIBDIR" "$INCLUDEDIR"
make -j"$NPROC" mkdir -p "$LIBDIR"
make install mkdir -p "$INCLUDEDIR"
done
mkdir -p "$QRENCODEDIR"/lib # Convert architectures to semicolon-separated format for cmake
mkdir -p "$QRENCODEDIR"/include ARCHS_SEMICOLON_SEPARATED=$(IFS=";"; echo "${ARCHS[*]}")
if ((${#ARCHS[@]} == "2")); then echo "Configuring CMake for architectures: ${ARCHS[*]}"
echo "Making fat lib for ${ARCHS[0]} and ${ARCHS[1]}" cd "$BUILDDIR"
LIBFILES="$QRENCODEDIR/${ARCHS[0]}-libqrencode/lib/*.a" cmake "$QRENCODEDIR" \
for f in $LIBFILES; do -DCMAKE_OSX_ARCHITECTURES="$ARCHS_SEMICOLON_SEPARATED" \
libFile=${f##*/} -DCMAKE_INSTALL_PREFIX="$QRENCODEDIR" \
echo "$libFile" -DWITHOUT_PNG=ON \
lipo -create "$QRENCODEDIR/${ARCHS[0]}-libqrencode/lib/$libFile" \ -DBUILD_SHARED_LIBS=OFF \
"$QRENCODEDIR/${ARCHS[1]}-libqrencode/lib/$libFile" \ -G "Xcode"
-output "${QRENCODEDIR}/lib/$libFile"
done echo "Building libqrencode for architectures: ${ARCHS[*]}"
else cmake --build . --config Release
echo "No need for fat lib"
rsync -ar --delete "$QRENCODEDIR/${ARCHS[0]}-libqrencode/lib/"*.a "${QRENCODEDIR}/lib/" echo "Installing libqrencode to $LIBDIR and $INCLUDEDIR"
fi cmake --install . --config Release
rsync -ar --delete "$QRENCODEDIR/${ARCHS[0]}-libqrencode/include/"* "${QRENCODEDIR}/include/" echo "Build and installation completed successfully, with outputs in $LIBDIR and $INCLUDEDIR."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment