|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +################################################################################################### |
| 4 | +# build.sh - Batch script for building the Unix version of QCTools # |
| 5 | +# # |
| 6 | +# Script requirements: # |
| 7 | +# - qctools_AllInclusive source # |
| 8 | +# - Qt bin directory in the PATH # |
| 9 | +# - Python3 binary in the PATH # |
| 10 | +# - pkg-config binary in the PATH # |
| 11 | +# - Meson binary in the PATH # |
| 12 | +# - Ninja binary in the PATH # |
| 13 | +# - Git binary in the PATH # |
| 14 | +# Environment: # |
| 15 | +# - MULTIARCH: Compile for arm64 and x86_64 into the same binary (macOS) # |
| 16 | +################################################################################################### |
| 17 | +# setup environment |
| 18 | +set -e |
| 19 | + |
| 20 | +if qmake --version >/dev/null 2>&1 ; then |
| 21 | + BINQMAKE=qmake |
| 22 | +elif qmake-qt6 --version >/dev/null 2>&1 ; then |
| 23 | + BINQMAKE=qmake-qt6 |
| 24 | +elif qmake6 --version >/dev/null 2>&1 ; then |
| 25 | + BINQMAKE=qmake6 |
| 26 | +else |
| 27 | + echo qmake not found |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +SCRIPT_DIR=$(cd $(dirname "$0") && pwd) |
| 32 | +INSTALL_DIR=$(cd $(dirname "$0") && cd ../../.. && pwd) |
| 33 | +cd "$INSTALL_DIR" |
| 34 | + |
| 35 | +FFMPEG_CONFIGURE_OPTS=( |
| 36 | + --enable-gpl |
| 37 | + --enable-version3 |
| 38 | + --disable-doc |
| 39 | + --disable-debug |
| 40 | + --disable-programs |
| 41 | + --disable-autodetect |
| 42 | + --enable-static |
| 43 | + --disable-shared |
| 44 | + --enable-libfreetype |
| 45 | + --enable-libharfbuzz |
| 46 | +) |
| 47 | + |
| 48 | +QT_CONFIGURE_OPTS=() |
| 49 | + |
| 50 | +if sw_vers >/dev/null 2>&1 ; then |
| 51 | + OS=mac |
| 52 | + export CFLAGS="-mmacosx-version-min=11.0 $CFLAGS" |
| 53 | + export CXXFLAGS="-mmacosx-version-min=11.0 $CXXFLAGS" |
| 54 | + export LDFLAGS="-mmacosx-version-min=11.0 $LDFLAGS" |
| 55 | + FFMPEG_CONFIGURE_OPTS+=(--extra-cflags="-mmacosx-version-min=11.0" --extra-ldflags="-mmacosx-version-min=11.0") |
| 56 | + if [[ -n "$MULTIARCH" ]] ; then |
| 57 | + QT_CONFIGURE_OPTS+=(QMAKE_APPLE_DEVICE_ARCHS="x86_64 arm64") |
| 58 | + mkdir -p $INSTALL_DIR/output/lib |
| 59 | + fi |
| 60 | +fi |
| 61 | + |
| 62 | +# get dependencies |
| 63 | +while read LINE; do |
| 64 | + DIR=$(echo "$LINE" | cut -d: -f1) |
| 65 | + URL=$(echo "$LINE" | cut -d: -f2-) |
| 66 | + if [[ -z "$DIR" || -z "$URL" ]] ; then |
| 67 | + continue |
| 68 | + fi |
| 69 | + if [[ ! -e "$DIR" ]] ; then |
| 70 | + mkdir "$DIR" |
| 71 | + pushd "$DIR" |
| 72 | + curl -LO "$URL" |
| 73 | + tar --extract --strip-components=1 --file=${URL##*/} |
| 74 | + rm -f ${URL##*/} |
| 75 | + popd |
| 76 | + fi |
| 77 | +done < $SCRIPT_DIR/dependencies.txt |
| 78 | + |
| 79 | +# freetype |
| 80 | +echo "Build FreeType" |
| 81 | +if [[ -d freetype/build ]] ; then |
| 82 | + rm -fr freetype/build |
| 83 | +fi |
| 84 | +mkdir freetype/build |
| 85 | +pushd freetype/build |
| 86 | + if [[ "$OS" == "mac" && -n "$MULTIARCH" ]] ; then |
| 87 | + mkdir x86_64 |
| 88 | + pushd x86_64 |
| 89 | + ( |
| 90 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/x86_64/lib/pkgconfig |
| 91 | + export CFLAGS="$CFLAGS -arch x86_64" |
| 92 | + export CXXFLAGS="$CXXFLAGS -arch x86_64" |
| 93 | + export LDFLAGS="$LDFLAGS -arch x86_64" |
| 94 | + meson setup --prefix $INSTALL_DIR/output/x86_64 --default-library=static -Dzlib=internal -Dbzip2=disabled -Dpng=disabled -Dharfbuzz=disabled -Dbrotli=disabled ../.. |
| 95 | + ninja install |
| 96 | + ) |
| 97 | + popd |
| 98 | + mkdir arm64 |
| 99 | + pushd arm64 |
| 100 | + ( |
| 101 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/arm64/lib/pkgconfig |
| 102 | + export CFLAGS="$CFLAGS -arch arm64" |
| 103 | + export CXXFLAGS="$CXXFLAGS -arch arm64" |
| 104 | + export LDFLAGS="$LDFLAGS -arch arm64" |
| 105 | + meson setup --prefix $INSTALL_DIR/output/arm64 --default-library=static -Dzlib=disabled -Dbzip2=disabled -Dpng=disabled -Dharfbuzz=disabled -Dbrotli=disabled ../.. |
| 106 | + ninja install |
| 107 | + ) |
| 108 | + popd |
| 109 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libfreetype.a $INSTALL_DIR/output/arm64/lib/libfreetype.a -output $INSTALL_DIR/output/lib/libfreetype.a |
| 110 | + else |
| 111 | + ( |
| 112 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/lib/pkgconfig |
| 113 | + meson setup --prefix $INSTALL_DIR/output --default-library=static -Dzlib=disabled -Dbzip2=disabled -Dpng=disabled -Dharfbuzz=disabled -Dbrotli=disabled .. |
| 114 | + ninja install |
| 115 | + ) |
| 116 | + fi |
| 117 | +popd |
| 118 | + |
| 119 | +# harfbuzz |
| 120 | +echo "Build HarfBuzz" |
| 121 | +if [[ -d harfbuzz/build ]] ; then |
| 122 | + rm -fr harfbuzz/build |
| 123 | +fi |
| 124 | +mkdir harfbuzz/build |
| 125 | +pushd harfbuzz/build |
| 126 | + if [[ "$OS" == "mac" && -n "$MULTIARCH" ]] ; then |
| 127 | + mkdir x86_64 |
| 128 | + pushd x86_64 |
| 129 | + ( |
| 130 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/x86_64/lib/pkgconfig |
| 131 | + export CFLAGS="$CFLAGS -arch x86_64" |
| 132 | + export CXXFLAGS="$CXXFLAGS -arch x86_64" |
| 133 | + export LDFLAGS="$LDFLAGS -arch x86_64" |
| 134 | + meson setup --prefix $INSTALL_DIR/output/x86_64 --default-library=static -Dglib=disabled -Dgobject=disabled -Dcairo=disabled -Dchafa=disabled -Dicu=disabled -Dgraphite=disabled -Dgraphite2=disabled -Dgdi=disabled -Ddirectwrite=disabled -Dcoretext=disabled -Dwasm=disabled -Dtests=disabled -Dintrospection=disabled -Ddocs=disabled -Ddoc_tests=false -Dutilities=disabled ../.. |
| 135 | + ninja install |
| 136 | + ) |
| 137 | + popd |
| 138 | + mkdir arm64 |
| 139 | + pushd arm64 |
| 140 | + ( |
| 141 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/arm64/lib/pkgconfig |
| 142 | + export CFLAGS="$CFLAGS -arch arm64" |
| 143 | + export CXXFLAGS="$CXXFLAGS -arch arm64" |
| 144 | + export LDFLAGS="$LDFLAGS -arch arm64" |
| 145 | + meson setup --prefix $INSTALL_DIR/output/arm64 --default-library=static -Dglib=disabled -Dgobject=disabled -Dcairo=disabled -Dchafa=disabled -Dicu=disabled -Dgraphite=disabled -Dgraphite2=disabled -Dgdi=disabled -Ddirectwrite=disabled -Dcoretext=disabled -Dwasm=disabled -Dtests=disabled -Dintrospection=disabled -Ddocs=disabled -Ddoc_tests=false -Dutilities=disabled ../.. |
| 146 | + ninja install |
| 147 | + ) |
| 148 | + popd |
| 149 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libharfbuzz.a $INSTALL_DIR/output/arm64/lib/libharfbuzz.a -output $INSTALL_DIR/output/lib/libharfbuzz.a |
| 150 | + else |
| 151 | + ( |
| 152 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/lib/pkgconfig |
| 153 | + meson setup --prefix $INSTALL_DIR/output --default-library=static -Dglib=disabled -Dgobject=disabled -Dcairo=disabled -Dchafa=disabled -Dicu=disabled -Dgraphite=disabled -Dgraphite2=disabled -Dgdi=disabled -Ddirectwrite=disabled -Dcoretext=disabled -Dwasm=disabled -Dtests=disabled -Dintrospection=disabled -Ddocs=disabled -Ddoc_tests=false -Dutilities=disabled .. |
| 154 | + ninja install |
| 155 | + ) |
| 156 | + fi |
| 157 | +popd |
| 158 | + |
| 159 | +# ffmpeg |
| 160 | +echo "Build FFmpeg" |
| 161 | +if [[ -d ffmpeg/build ]] ; then |
| 162 | + rm -fr ffmpeg/build |
| 163 | +fi |
| 164 | +mkdir ffmpeg/build |
| 165 | +pushd ffmpeg/build |
| 166 | + if [[ "$OS" == "mac" && -n "$MULTIARCH" ]] ; then |
| 167 | + mkdir x86_64 |
| 168 | + pushd x86_64 |
| 169 | + ( |
| 170 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/x86_64/lib/pkgconfig |
| 171 | + ../../configure --arch=x86_64 --extra-cflags="-arch x86_64" --extra-ldflags="-arch x86_64" --prefix=$INSTALL_DIR/output/x86_64 "${FFMPEG_CONFIGURE_OPTS[@]}" |
| 172 | + make install |
| 173 | + ) |
| 174 | + popd |
| 175 | + mkdir arm64 |
| 176 | + pushd arm64 |
| 177 | + ( |
| 178 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/arm64/lib/pkgconfig |
| 179 | + ../../configure --arch=arm64 --extra-cflags="-arch arm64" --extra-ldflags="-arch arm64" --prefix=$INSTALL_DIR/output/arm64 "${FFMPEG_CONFIGURE_OPTS[@]}" |
| 180 | + make install |
| 181 | + ) |
| 182 | + popd |
| 183 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libavcodec.a $INSTALL_DIR/output/arm64/lib/libavcodec.a -output $INSTALL_DIR/output/lib/libavcodec.a |
| 184 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libavdevice.a $INSTALL_DIR/output/arm64/lib/libavdevice.a -output $INSTALL_DIR/output/lib/libavdevice.a |
| 185 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libavfilter.a $INSTALL_DIR/output/arm64/lib/libavfilter.a -output $INSTALL_DIR/output/lib/libavfilter.a |
| 186 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libavformat.a $INSTALL_DIR/output/arm64/lib/libavformat.a -output $INSTALL_DIR/output/lib/libavformat.a |
| 187 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libavutil.a $INSTALL_DIR/output/arm64/lib/libavutil.a -output $INSTALL_DIR/output/lib/libavutil.a |
| 188 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libpostproc.a $INSTALL_DIR/output/arm64/lib/libpostproc.a -output $INSTALL_DIR/output/lib/libpostproc.a |
| 189 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libswresample.a $INSTALL_DIR/output/arm64/lib/libswresample.a -output $INSTALL_DIR/output/lib/libswresample.a |
| 190 | + lipo -create $INSTALL_DIR/output/x86_64/lib/libswscale.a $INSTALL_DIR/output/arm64/lib/libswscale.a -output $INSTALL_DIR/output/lib/libswscale.a |
| 191 | + cp -r $INSTALL_DIR/output/x86_64/include $INSTALL_DIR/output |
| 192 | + else |
| 193 | + ( |
| 194 | + export PKG_CONFIG_PATH=$INSTALL_DIR/output/lib/pkgconfig |
| 195 | + ../configure --prefix=$INSTALL_DIR/output "${FFMPEG_CONFIGURE_OPTS[@]}" |
| 196 | + make install |
| 197 | + ) |
| 198 | + fi |
| 199 | +popd |
| 200 | + |
| 201 | +# qwt |
| 202 | +echo "Build Qwt" |
| 203 | +if [[ -d qwt/build ]] ; then |
| 204 | + rm -fr qwt/build |
| 205 | +fi |
| 206 | +mkdir qwt/build |
| 207 | +pushd qwt/build |
| 208 | +( |
| 209 | + git -C .. apply "$SCRIPT_DIR/qwt.patch" |
| 210 | + export QWT_STATIC=1 QWT_NO_SVG=1 QWT_NO_OPENGL=1 QWT_NO_DESIGNER=1 QWT_NO_EXAMPLES=1 QWT_NO_PLAYGROUND=1 QWT_NO_TESTS=1 QWT_INSTALL_PREFIX=$INSTALL_DIR/output |
| 211 | + $BINQMAKE "${QT_CONFIGURE_OPTS[@]}" .. |
| 212 | + make install |
| 213 | +) |
| 214 | +popd |
| 215 | + |
| 216 | +# qctools |
| 217 | +echo "Build QCTools" |
| 218 | +if [[ -d qctools/Project/QtCreator/build ]] ; then |
| 219 | + rm -fr qctools/Project/QtCreator/build |
| 220 | +fi |
| 221 | +mkdir qctools/Project/QtCreator/build |
| 222 | +pushd qctools/Project/QtCreator/build |
| 223 | +( |
| 224 | + export QWT_ROOT=$INSTALL_DIR/output FFMPEG=$INSTALL_DIR/output |
| 225 | + $BINQMAKE "${QT_CONFIGURE_OPTS[@]}" STATIC=1 .. |
| 226 | + make |
| 227 | +) |
| 228 | +popd |
| 229 | + |
| 230 | +echo QCTools binary is in $INSTALL_DIR/qctools/Project/QtCreator/build/qctools-gui |
| 231 | +echo qcli binary is in $INSTALL_DIR/qctools/Project/QtCreator/build/qctools-cli |
0 commit comments