Last active
December 13, 2023 16:16
-
-
Save eddiezato/866f28db35b56402e4ea9e1bb36d30ba to your computer and use it in GitHub Desktop.
Build yacreader without yaclibrary in msys2/clang64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while getopts 'csajpyd' flag ; do | |
case "${flag}" in | |
c) CLR=1 ;; # remove clang folder | |
s) DSRC=1 ;; # download source-code | |
a) BAVIF=1 ;; # build libavif | |
j) BJXL=1 ;; # build libjxl | |
p) BPLGS=1 ;; # build plugins | |
y) BYACR=1 ;; # build yacreader | |
d) DYACR=1 ;; # deploy yacreader | |
esac | |
done | |
if [[ $OPTIND == 1 ]]; then | |
printf '\nOptions:\n' | |
printf ' -c remove clang folder\n' | |
printf ' -s download source-code\n' | |
printf ' -a build libavif\n' | |
printf ' -j build libjxl\n' | |
printf ' -p build plugins\n' | |
printf ' -y build yacreader\n' | |
printf ' -d deploy yacreader\n' | |
exit | |
fi | |
if [[ $MSYSTEM != 'CLANG64' ]] ; then | |
printf '\e[1;31mNot CLANG64 environment\e[0m\n' | |
exit 1 | |
fi | |
set -e | |
MGNT='\e[1;35m' | |
RST='\e[0m' | |
export CC=clang CXX=clang++ | |
CFL='-flto=thin -ffunction-sections -fdata-sections -march=native -mtune=native -O3 -pipe' | |
LFL='-flto=thin -Wl,--gc-sections' | |
if [[ $CLR == 1 ]] ; then | |
printf "\n${MGNT}:: Remove clang folder ::${RST}\n" | |
rm -rf clang | |
fi | |
mkdir -p clang/install | |
EXTDIR=$(realpath clang/install) | |
cd clang | |
# download source-code | |
if [[ $DSRC == 1 ]] ; then | |
# download libavif | |
if [[ ! -d libavif ]]; then | |
printf "\n${MGNT}:: Download libavif ::${RST}\n" | |
git clone --depth 1 --branch v1.0.3 https://github.com/AOMediaCodec/libavif.git | |
cd libavif/ext | |
if [[ ! -d dav1d ]]; then | |
branch=($(grep -i "git clone" dav1d.cmd)) | |
git clone -b ${branch[3]} --depth 1 https://code.videolan.org/videolan/dav1d.git | |
mkdir -p dav1d/build | |
fi | |
if [[ ! -d libyuv ]]; then | |
branch=($(grep -i "git checkout" libyuv.cmd)) | |
git clone --single-branch https://chromium.googlesource.com/libyuv/libyuv | |
cd libyuv | |
git checkout ${branch[2]} | |
cd .. | |
fi | |
cd .. | |
sed -i 's|${AVIF_LIBRARY_PREFIX}yuv${AVIF_LIBRARY_SUFFIX}|libyuv.a|' CMakeLists.txt | |
cd .. | |
fi | |
# download libjxl | |
if [[ ! -d libjxl ]]; then | |
printf "\n${MGNT}:: Download libjxl ::${RST}\n" | |
git clone --branch v0.8.2 --depth 1 https://github.com/libjxl/libjxl.git | |
cd libjxl/third_party | |
if [[ -z "$(ls -A skcms)" ]]; then git clone --single-branch https://skia.googlesource.com/skcms; cd skcms; git checkout '568ad63'; cd ..; fi | |
if [[ -z "$(ls -A sjpeg)" ]]; then git clone --depth 1 https://github.com/webmproject/sjpeg.git; fi | |
cd .. | |
if [[ -z "$(ls -A testdata)" ]]; then git clone --depth 1 https://github.com/libjxl/testdata; fi | |
cd .. | |
fi | |
# download qavif | |
if [[ ! -d qt-avif-image-plugin ]]; then | |
printf "\n${MGNT}:: Download qavif ::${RST}\n" | |
git clone --depth 1 https://github.com/novomesk/qt-avif-image-plugin.git | |
cd qt-avif-image-plugin | |
sed -i 's|set(REQUIRED_QT_VERSION 5.14.0)|set(REQUIRED_QT_VERSION 6.5.1)|' CMakeLists.txt | |
sed -i 's|${QT_MAJOR_VERSION}|6|' CMakeLists.txt | |
sed -i 's|${QT_MAJOR_VERSION}|6|' src/CMakeLists.txt | |
cd .. | |
fi | |
# download qjpegxl | |
if [[ ! -d qt-jpegxl-image-plugin ]]; then | |
printf "\n${MGNT}:: Download qjpegxl ::${RST}\n" | |
git clone --depth 1 https://github.com/novomesk/qt-jpegxl-image-plugin.git | |
cd qt-jpegxl-image-plugin | |
sed -i 's|set(REQUIRED_QT_VERSION 5.14.0)|set(REQUIRED_QT_VERSION 6.5.1)|' CMakeLists.txt | |
sed -i 's|${QT_MAJOR_VERSION}|6|' CMakeLists.txt | |
sed -i 's|${QT_MAJOR_VERSION}|6|' src/CMakeLists.txt | |
cd .. | |
fi | |
# download yacreader | |
if [[ ! -d yacreader ]]; then | |
printf "\n${MGNT}:: Download yacreader ::${RST}\n" | |
git clone --depth 1 https://github.com/YACReader/yacreader.git | |
curl -#O https://www.7-zip.org/a/7z2301-src.7z | |
7z x 7z2301-src.7z -oyacreader/compressed_archive/lib7zip -y | |
rm -f 7z2301-src.7z | |
cd yacreader | |
printf 'Apply custom patches .' | |
printf 'TEMPLATE = subdirs\nSUBDIRS = YACReader' > YACReader2.pro | |
sed -i 's|.*std:c++17.*||' config.pri && printf '.' | |
sed -i 's|PassThrough|Floor|' YACReader/main.cpp && printf '.' | |
sed -i 's|-luser32|-luser32 -luuid|;s|QMAKE_CXXFLAGS_RELEASE.*||;s|QMAKE_LFLAGS_RELEASE.*||' YACReader/YACReader.pro && printf '.' | |
sed -i 's|QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)|(QCoreApplication::applicationDirPath() + "/conf");|' common/yacreader_global.cpp && printf '.' | |
sed -i 's|#include <QDataStream>|#include <QDataStream>\n#include <QCoreApplication>|' common/yacreader_global.h && printf '.' | |
sed -i 's|QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)|QCoreApplication::applicationDirPath()| | |
s|/YACReader/YACReaderCommon.ini|/conf/YACReaderCommon.ini|' custom_widgets/whats_new_controller.cpp && printf '.' | |
sed -i 's|#include <QObject>|#include <QObject>\n#include <QCoreApplication>|' custom_widgets/whats_new_dialog.h && printf '.\n' | |
cd .. | |
fi | |
fi | |
# build libavif | |
if [[ $BAVIF == 1 ]] ; then | |
printf "\n${MGNT}:: Build libavif ::${RST}\n" | |
cd libavif/ext | |
# build dav1d | |
cd dav1d | |
rm -rf build | |
CFLAGS="$CFL" CXXFLAGS="$CFL" LDFLAGS="$LFL" meson setup --default-library=static --buildtype=release -Denable_tools=false -Denable_tests=false build ./ | |
ninja -C build | |
cd .. | |
# build libyuv | |
cd libyuv | |
rm -rf build | |
cmake -B build -G Ninja -S ./ \ | |
-DBUILD_SHARED_LIBS=OFF \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_C_FLAGS="$CFL" -DCMAKE_CXX_FLAGS="$CFL" -DCMAKE_EXE_LINKER_FLAGS="$LFL" \ | |
-Wno-dev | |
ninja -C build yuv | |
cd ../.. | |
# build libavif | |
rm -rf build | |
cmake -B build -G Ninja -S ./ \ | |
-DCMAKE_INSTALL_PREFIX="$EXTDIR" \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DAVIF_CODEC_DAV1D=ON \ | |
-DAVIF_LOCAL_DAV1D=ON \ | |
-DAVIF_LOCAL_LIBYUV=ON \ | |
-DCMAKE_C_FLAGS="$CFL" -DCMAKE_CXX_FLAGS="$CFL" -DCMAKE_EXE_LINKER_FLAGS="$LFL" | |
ninja install -C build | |
cd .. | |
fi | |
# build libjxl | |
if [[ $BJXL == 1 ]] ; then | |
printf "\n${MGNT}:: Build libjxl ::${RST}\n" | |
cd libjxl | |
rm -rf build | |
cmake -B build -G Ninja -S ./ \ | |
-DCMAKE_INSTALL_PREFIX="$EXTDIR" \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DBUILD_TESTING=OFF \ | |
-DJPEGXL_ENABLE_TOOLS=OFF \ | |
-DJPEGXL_ENABLE_DOXYGEN=OFF \ | |
-DJPEGXL_ENABLE_MANPAGES=OFF \ | |
-DJPEGXL_ENABLE_BENCHMARK=OFF \ | |
-DJPEGXL_ENABLE_EXAMPLES=OFF \ | |
-DJPEGXL_ENABLE_JNI=OFF \ | |
-DJPEGXL_ENABLE_OPENEXR=OFF \ | |
-DJPEGXL_WARNINGS_AS_ERRORS=OFF \ | |
-DJPEGXL_FORCE_SYSTEM_BROTLI=ON \ | |
-DJPEGXL_FORCE_SYSTEM_LCMS2=ON \ | |
-DJPEGXL_FORCE_SYSTEM_HWY=ON \ | |
-DCMAKE_C_FLAGS="$CFL" -DCMAKE_CXX_FLAGS="$CFL" -DCMAKE_EXE_LINKER_FLAGS="$LFL" \ | |
-Wno-dev | |
ninja install -C build | |
cd .. | |
fi | |
# build plugins | |
if [[ $BPLGS == 1 ]] ; then | |
# build qavif | |
printf "\n${MGNT}:: Build qavif ::${RST}\n" | |
cd qt-avif-image-plugin | |
rm -rf build | |
cmake -B build -G Ninja -S ./ -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$EXTDIR" \ | |
-DCMAKE_C_FLAGS="$CFL" -DCMAKE_CXX_FLAGS="$CFL" -DCMAKE_EXE_LINKER_FLAGS="$LFL" | |
ninja -C build | |
cd .. | |
# build qjpegxl | |
printf "\n${MGNT}:: Build qjpegxl ::${RST}\n" | |
cd qt-jpegxl-image-plugin | |
rm -rf build | |
cmake -B build -G Ninja -S ./ -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$EXTDIR" \ | |
-DCMAKE_C_FLAGS="$CFL" -DCMAKE_CXX_FLAGS="$CFL" -DCMAKE_EXE_LINKER_FLAGS="$LFL" | |
ninja -C build | |
cd .. | |
fi | |
# build yacreader | |
if [[ $BYACR == 1 ]] ; then | |
printf "\n${MGNT}:: Build yacreader ::${RST}\n" | |
cd yacreader | |
rm -rf build | |
mkdir build && cd build | |
qmake-qt6 "QMAKE_CFLAGS *= $CFL" "QMAKE_CXXFLAGS *= $CFL" QLFL="QMAKE_LFLAGS *= $LFL" "QT_MEDIA_BACKEND = windows" "CONFIG += optimize_full no_pdf" ../YACReader2.pro | |
make | |
cd ../.. | |
fi | |
# deploy yacreader | |
if [[ $DYACR == 1 ]] ; then | |
printf "\n${MGNT}:: Deploy portable yacreader ::${RST}\n" | |
rm -rf YACReader_w64 | |
mkdir -p YACReader_w64/utils | |
cp yacreader/build/release64/YACReader.exe YACReader_w64/ | |
windeployqt-qt6 YACReader_w64/YACReader.exe \ | |
--compiler-runtime \ | |
--no-system-d3d-compiler \ | |
--no-translations \ | |
--skip-plugin-types generic,networkinformation,tls \ | |
--exclude-plugins ffmpegmediaplugin \ | |
--qtpaths "/clang64/bin/qtpaths-qt6.exe" | |
printf 'Copying dependencies ' | |
cp install/bin/{libavif.dll,libjxl.dll,libjxl_threads.dll} YACReader_w64/ && printf '.' | |
cp qt-jpegxl-image-plugin/build/bin/imageformats/libqjpegxl*.dll YACReader_w64/imageformats/qjpegxl.dll && printf '.' | |
cp qt-avif-image-plugin/build/bin/imageformats/libqavif*.dll YACReader_w64/imageformats/qavif.dll && printf '.' | |
while | |
files2=$files1 | |
files1=$(ldd YACReader_w64/{*.{exe,dll},imageformats/*.dll} | grep "/clang64/bin/" | grep -v 'Qt6' | sed 's/.* => //;s/ (.*//' | sort -u) | |
printf '.' | |
for f in $files1; do | |
cp -u $f YACReader_w64/ | |
done | |
[[ $files1 != $files2 ]] | |
do :; done | |
cp -u /usr/bin/7z.dll YACReader_w64/utils/ && printf '.' | |
echo 'ok' | |
printf 'Reduce file sizes .' | |
strip -s YACReader_w64/{YACReader.exe,{./,*/}*.dll} | |
printf 'ok\n' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment