lin.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. #!/usr/bin/env bash
  2. set -e
  3. # Environment / working directories
  4. case ${PLATFORM} in
  5. linux*)
  6. LINUX=true
  7. DEPS=/deps
  8. TARGET=/target
  9. PACKAGE=/packaging
  10. ROOT=/root
  11. VIPS_CPP_DEP=libvips-cpp.so.42
  12. ;;
  13. darwin*)
  14. DARWIN=true
  15. DEPS=$PWD/deps
  16. TARGET=$PWD/target
  17. PACKAGE=$PWD
  18. ROOT=$PWD/darwin-x64
  19. VIPS_CPP_DEP=libvips-cpp.42.dylib
  20. ;;
  21. esac
  22. mkdir ${DEPS}
  23. mkdir ${TARGET}
  24. # Common build paths and flags
  25. export PKG_CONFIG_LIBDIR="${TARGET}/lib/pkgconfig"
  26. export PATH="${PATH}:${TARGET}/bin"
  27. export CPATH="${TARGET}/include"
  28. export LIBRARY_PATH="${TARGET}/lib"
  29. export LD_LIBRARY_PATH="${TARGET}/lib"
  30. export CFLAGS="${FLAGS}"
  31. export CXXFLAGS="${FLAGS}"
  32. export LDFLAGS="-L${TARGET}/lib"
  33. # On Linux, we need to create a relocatable library
  34. # Note: this is handled for macOS using the `install_name_tool` (see below)
  35. if [ "$LINUX" = true ]; then
  36. export LDFLAGS+=" -Wl,-rpath='\$\$ORIGIN/'"
  37. fi
  38. # On macOS, we need to explicitly link against the system libraries
  39. if [ "$DARWIN" = true ]; then
  40. export LDFLAGS+=" -framework CoreServices -framework CoreFoundation -framework Foundation -framework AppKit"
  41. fi
  42. # Run as many parallel jobs as there are available CPU cores
  43. if [ "$LINUX" = true ]; then
  44. export MAKEFLAGS="-j$(nproc)"
  45. elif [ "$DARWIN" = true ]; then
  46. export MAKEFLAGS="-j$(sysctl -n hw.logicalcpu)"
  47. fi
  48. # Optimise Rust code for binary size
  49. export CARGO_PROFILE_RELEASE_DEBUG=false
  50. export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
  51. export CARGO_PROFILE_RELEASE_INCREMENTAL=false
  52. export CARGO_PROFILE_RELEASE_LTO=true
  53. export CARGO_PROFILE_RELEASE_OPT_LEVEL=s
  54. export CARGO_PROFILE_RELEASE_PANIC=abort
  55. # We don't want to use any native libraries, so unset PKG_CONFIG_PATH
  56. unset PKG_CONFIG_PATH
  57. # Common options for curl
  58. CURL="curl --silent --location --retry 3 --retry-max-time 30"
  59. # Dependency version numbers
  60. VERSION_ZLIB=1.2.11
  61. VERSION_FFI=3.3
  62. VERSION_GLIB=2.67.0
  63. VERSION_XML2=2.9.10
  64. VERSION_GSF=1.14.47
  65. VERSION_EXIF=0.6.22
  66. VERSION_LCMS2=2.11
  67. VERSION_JPEG=2.0.90
  68. VERSION_PNG16=1.6.37
  69. VERSION_SPNG=0.6.1
  70. VERSION_WEBP=1.1.0
  71. VERSION_TIFF=4.1.0
  72. VERSION_ORC=0.4.32
  73. VERSION_GETTEXT=0.21
  74. VERSION_GDKPIXBUF=2.42.0
  75. VERSION_FREETYPE=2.10.4
  76. VERSION_EXPAT=2.2.10
  77. VERSION_FONTCONFIG=2.13.92
  78. VERSION_HARFBUZZ=2.7.2
  79. VERSION_PIXMAN=0.40.0
  80. VERSION_CAIRO=1.16.0
  81. VERSION_FRIBIDI=1.0.10
  82. VERSION_PANGO=1.48.0
  83. VERSION_SVG=2.50.2
  84. VERSION_GIF=5.1.4
  85. VERSION_AOM=2.0.0
  86. VERSION_HEIF=1.9.1
  87. VERSION_MOZJPEG=4.0.0
  88. # Remove patch version component
  89. without_patch() {
  90. echo "${1%.[[:digit:]]*}"
  91. }
  92. # Check for newer versions
  93. ALL_AT_VERSION_LATEST=true
  94. version_latest() {
  95. VERSION_LATEST=$($CURL https://release-monitoring.org/api/project/$3 | jq -r '.versions[]' | grep -E -m1 '^[0-9]+(.[0-9]+)*$')
  96. if [ "$VERSION_LATEST" != "$2" ]; then
  97. ALL_AT_VERSION_LATEST=false
  98. echo "$1 version $2 has been superseded by $VERSION_LATEST"
  99. fi
  100. }
  101. version_latest "zlib" "$VERSION_ZLIB" "5303"
  102. version_latest "ffi" "$VERSION_FFI" "1611"
  103. version_latest "glib" "$VERSION_GLIB" "10024"
  104. version_latest "xml2" "$VERSION_XML2" "1783"
  105. version_latest "gsf" "$VERSION_GSF" "1980"
  106. version_latest "exif" "$VERSION_EXIF" "1607"
  107. version_latest "lcms2" "$VERSION_LCMS2" "9815"
  108. version_latest "jpeg" "$VERSION_JPEG" "1648"
  109. version_latest "png" "$VERSION_PNG16" "1705"
  110. version_latest "spng" "$VERSION_SPNG" "24289"
  111. version_latest "webp" "$VERSION_WEBP" "1761"
  112. version_latest "tiff" "$VERSION_TIFF" "13521"
  113. version_latest "orc" "$VERSION_ORC" "2573"
  114. version_latest "gettext" "$VERSION_GETTEXT" "898"
  115. version_latest "gdkpixbuf" "$VERSION_GDKPIXBUF" "9533"
  116. version_latest "freetype" "$VERSION_FREETYPE" "854"
  117. version_latest "expat" "$VERSION_EXPAT" "770"
  118. version_latest "fontconfig" "$VERSION_FONTCONFIG" "827"
  119. version_latest "harfbuzz" "$VERSION_HARFBUZZ" "1299"
  120. version_latest "pixman" "$VERSION_PIXMAN" "3648"
  121. #version_latest "cairo" "$VERSION_CAIRO" "247" # latest version in release monitoring is unstable
  122. version_latest "fribidi" "$VERSION_FRIBIDI" "857"
  123. version_latest "pango" "$VERSION_PANGO" "11783"
  124. version_latest "svg" "$VERSION_SVG" "5420"
  125. #version_latest "gif" "$VERSION_GIF" "1158" # v5.1.5+ provides a Makefile only so will require custom cross-compilation setup
  126. #version_latest "aom" "$VERSION_AOM" "17628" # latest version in release monitoring does not exist
  127. version_latest "heif" "$VERSION_HEIF" "64439"
  128. if [ "$ALL_AT_VERSION_LATEST" = "false" ]; then exit 1; fi
  129. # Download and build dependencies from source
  130. if [ "${PLATFORM%-*}" == "linuxmusl" ] || [ "$DARWIN" = true ]; then
  131. mkdir ${DEPS}/gettext
  132. $CURL https://ftp.gnu.org/pub/gnu/gettext/gettext-${VERSION_GETTEXT}.tar.xz | tar xJC ${DEPS}/gettext --strip-components=1
  133. cd ${DEPS}/gettext/gettext-runtime
  134. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  135. --disable-libasprintf --disable-java --disable-native-java --disable-csharp
  136. make install-strip
  137. fi
  138. mkdir ${DEPS}/zlib
  139. $CURL https://zlib.net/zlib-${VERSION_ZLIB}.tar.xz | tar xJC ${DEPS}/zlib --strip-components=1
  140. cd ${DEPS}/zlib
  141. ./configure --prefix=${TARGET} ${LINUX:+--uname=linux} ${DARWIN:+--uname=darwin} --static
  142. make install
  143. mkdir ${DEPS}/ffi
  144. $CURL https://github.com/libffi/libffi/releases/download/v${VERSION_FFI}/libffi-${VERSION_FFI}.tar.gz | tar xzC ${DEPS}/ffi --strip-components=1
  145. cd ${DEPS}/ffi
  146. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  147. --disable-builddir --disable-multi-os-directory --disable-raw-api --disable-structs
  148. make install-strip
  149. mkdir ${DEPS}/glib
  150. $CURL https://download.gnome.org/sources/glib/$(without_patch $VERSION_GLIB)/glib-${VERSION_GLIB}.tar.xz | tar xJC ${DEPS}/glib --strip-components=1
  151. cd ${DEPS}/glib
  152. # Disable tests
  153. sed -i'.bak' "/build_tests =/ s/= .*/= false/" meson.build
  154. if [ "${PLATFORM%-*}" == "linuxmusl" ]; then
  155. #$CURL https://git.alpinelinux.org/aports/plain/main/glib/musl-libintl.patch | patch -p1 # not compatible with glib 2.65.0
  156. $CURL https://gist.github.com/kleisauke/f4bda6fc3030cf7b8a4fdb88e2ce8e13/raw/246ac97dfba72ad7607c69eed1810b2354cd2e86/musl-libintl.patch | patch -p1
  157. fi
  158. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  159. -Dinternal_pcre=true -Dinstalled_tests=false -Dlibmount=disabled -Dlibelf=disabled ${DARWIN:+-Dbsymbolic_functions=false}
  160. ninja -C _build
  161. ninja -C _build install
  162. mkdir ${DEPS}/xml2
  163. $CURL http://xmlsoft.org/sources/libxml2-${VERSION_XML2}.tar.gz | tar xzC ${DEPS}/xml2 --strip-components=1
  164. cd ${DEPS}/xml2
  165. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  166. --without-python --without-debug --without-docbook --without-ftp --without-html --without-legacy \
  167. --without-push --without-schematron --without-lzma --with-zlib=${TARGET}
  168. make install-strip
  169. mkdir ${DEPS}/gsf
  170. $CURL https://download.gnome.org/sources/libgsf/$(without_patch $VERSION_GSF)/libgsf-${VERSION_GSF}.tar.xz | tar xJC ${DEPS}/gsf --strip-components=1
  171. cd ${DEPS}/gsf
  172. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  173. --without-bz2 --without-gdk-pixbuf --with-zlib=${TARGET}
  174. make install-strip
  175. mkdir ${DEPS}/exif
  176. $CURL https://github.com/libexif/libexif/releases/download/libexif-${VERSION_EXIF//./_}-release/libexif-${VERSION_EXIF}.tar.xz | tar xJC ${DEPS}/exif --strip-components=1
  177. cd ${DEPS}/exif
  178. autoreconf -fiv
  179. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking
  180. make install-strip
  181. mkdir ${DEPS}/lcms2
  182. $CURL https://downloads.sourceforge.net/project/lcms/lcms/${VERSION_LCMS2}/lcms2-${VERSION_LCMS2}.tar.gz | tar xzC ${DEPS}/lcms2 --strip-components=1
  183. cd ${DEPS}/lcms2
  184. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking
  185. make install-strip
  186. mkdir ${DEPS}/aom
  187. $CURL https://aomedia.googlesource.com/aom/+archive/v${VERSION_AOM}.tar.gz | tar xzC ${DEPS}/aom
  188. cd ${DEPS}/aom
  189. mkdir aom_build
  190. cd aom_build
  191. AOM_AS_FLAGS="${FLAGS}" LDFLAGS=${LDFLAGS/\$/} cmake -G"Unix Makefiles" \
  192. -DCMAKE_TOOLCHAIN_FILE=${ROOT}/Toolchain.cmake -DCMAKE_INSTALL_PREFIX=${TARGET} -DCMAKE_INSTALL_LIBDIR=lib \
  193. -DENABLE_DOCS=0 -DENABLE_TESTS=0 -DENABLE_TESTDATA=0 -DENABLE_TOOLS=0 -DENABLE_EXAMPLES=0 \
  194. -DCONFIG_PIC=1 -DENABLE_NASM=1 ${WITHOUT_NEON:+-DENABLE_NEON=0} \
  195. ..
  196. make install/strip
  197. mkdir ${DEPS}/heif
  198. $CURL https://github.com/strukturag/libheif/releases/download/v${VERSION_HEIF}/libheif-${VERSION_HEIF}.tar.gz | tar xzC ${DEPS}/heif --strip-components=1
  199. cd ${DEPS}/heif
  200. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  201. --disable-gdk-pixbuf --disable-go --disable-examples --disable-libde265 --disable-x265
  202. sed -i'.bak' -e '/^Requires:/a\'$'\n''Requires.private: aom' libheif.pc # https://github.com/strukturag/libheif/pull/354
  203. make install-strip
  204. mkdir ${DEPS}/png16
  205. $CURL https://downloads.sourceforge.net/project/libpng/libpng16/${VERSION_PNG16}/libpng-${VERSION_PNG16}.tar.xz | tar xJC ${DEPS}/png16 --strip-components=1
  206. cd ${DEPS}/png16
  207. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking
  208. make install-strip
  209. mkdir ${DEPS}/mozjpeg
  210. curl -Ls https://github.com/mozilla/mozjpeg/archive/v${VERSION_MOZJPEG}.tar.gz | tar xzC ${DEPS}/mozjpeg --strip-components=1
  211. cd ${DEPS}/mozjpeg
  212. #autoreconf -fiv
  213. LDFLAGS=${LDFLAGS/\$/} cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=${ROOT}/Toolchain.cmake -DCMAKE_INSTALL_PREFIX=${TARGET} -DCMAKE_INSTALL_LIBDIR=${TARGET}/lib \
  214. -DENABLE_STATIC=TRUE -DENABLE_SHARED=FALSE -DWITH_JPEG8=1
  215. make install/strip
  216. mkdir ${DEPS}/jpeg
  217. $CURL https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION_JPEG}.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1
  218. cd ${DEPS}/jpeg
  219. LDFLAGS=${LDFLAGS/\$/} cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=${ROOT}/Toolchain.cmake -DCMAKE_INSTALL_PREFIX=${TARGET} -DCMAKE_INSTALL_LIBDIR=${TARGET}/lib \
  220. -DENABLE_STATIC=TRUE -DENABLE_SHARED=FALSE -DWITH_JPEG8=1 -DWITH_TURBOJPEG=FALSE
  221. make install/strip
  222. mkdir ${DEPS}/spng
  223. $CURL https://github.com/randy408/libspng/archive/v${VERSION_SPNG}.tar.gz | tar xzC ${DEPS}/spng --strip-components=1
  224. cd ${DEPS}/spng
  225. meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  226. -Dstatic_zlib=true
  227. ninja -C _build
  228. ninja -C _build install
  229. mkdir ${DEPS}/webp
  230. $CURL https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-${VERSION_WEBP}.tar.gz | tar xzC ${DEPS}/webp --strip-components=1
  231. cd ${DEPS}/webp
  232. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  233. --disable-neon --enable-libwebpmux --enable-libwebpdemux
  234. make install-strip
  235. mkdir ${DEPS}/tiff
  236. $CURL https://download.osgeo.org/libtiff/tiff-${VERSION_TIFF}.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1
  237. cd ${DEPS}/tiff
  238. if [ -n "${CHOST}" ]; then autoreconf -fiv; fi
  239. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  240. --disable-mdi --disable-pixarlog --disable-old-jpeg --disable-cxx --disable-lzma --disable-zstd \
  241. --with-jpeg-include-dir=${TARGET}/include --with-jpeg-lib-dir=${TARGET}/lib
  242. make install-strip
  243. mkdir ${DEPS}/orc
  244. $CURL https://gstreamer.freedesktop.org/data/src/orc/orc-${VERSION_ORC}.tar.xz | tar xJC ${DEPS}/orc --strip-components=1
  245. cd ${DEPS}/orc
  246. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  247. -Dorc-test=disabled -Dbenchmarks=disabled -Dexamples=disabled -Dgtk_doc=disabled -Dtests=disabled -Dtools=disabled
  248. ninja -C _build
  249. ninja -C _build install
  250. mkdir ${DEPS}/gdkpixbuf
  251. $CURL https://download.gnome.org/sources/gdk-pixbuf/$(without_patch $VERSION_GDKPIXBUF)/gdk-pixbuf-${VERSION_GDKPIXBUF}.tar.xz | tar xJC ${DEPS}/gdkpixbuf --strip-components=1
  252. cd ${DEPS}/gdkpixbuf
  253. # Disable tests and thumbnailer
  254. sed -i'.bak' "/subdir('tests')/{N;d;}" meson.build
  255. # Disable the built-in loaders for BMP, GIF, ICO, PNM, XPM, XBM, TGA, ICNS and QTIF
  256. sed -i'.bak' "/\[ 'bmp'/{N;N;N;d;}" gdk-pixbuf/meson.build
  257. sed -i'.bak' "/\[ 'pnm'/d" gdk-pixbuf/meson.build
  258. sed -i'.bak' "/\[ 'xpm'/{N;N;N;N;d;}" gdk-pixbuf/meson.build
  259. # Ensure meson can find libjpeg when cross-compiling
  260. sed -i'.bak' "s/has_header('jpeglib.h')/has_header('jpeglib.h', args: '-I\/target\/include')/g" meson.build
  261. sed -i'.bak' "s/cc.find_library('jpeg'/dependency('libjpeg'/g" meson.build
  262. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  263. -Dtiff=false -Dintrospection=disabled -Dinstalled_tests=false -Dgio_sniffing=false -Dman=false -Dbuiltin_loaders=png,jpeg
  264. ninja -C _build
  265. ninja -C _build install
  266. # Include libjpeg and libpng as a dependency of gdk-pixbuf, see: https://gitlab.gnome.org/GNOME/gdk-pixbuf/merge_requests/50
  267. sed -i'.bak' "s/^\(Requires:.*\)/\1 libjpeg, libpng16/" ${TARGET}/lib/pkgconfig/gdk-pixbuf-2.0.pc
  268. mkdir ${DEPS}/freetype
  269. $CURL https://download.savannah.gnu.org/releases/freetype/freetype-${VERSION_FREETYPE}.tar.xz | tar xJC ${DEPS}/freetype --strip-components=1
  270. cd ${DEPS}/freetype
  271. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  272. --without-bzip2 --without-png
  273. make install
  274. mkdir ${DEPS}/expat
  275. $CURL https://github.com/libexpat/libexpat/releases/download/R_${VERSION_EXPAT//./_}/expat-${VERSION_EXPAT}.tar.xz | tar xJC ${DEPS}/expat --strip-components=1
  276. cd ${DEPS}/expat
  277. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared \
  278. --disable-dependency-tracking --without-xmlwf --without-docbook --without-getrandom --without-sys-getrandom
  279. make install
  280. mkdir ${DEPS}/fontconfig
  281. $CURL https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.xz | tar xJC ${DEPS}/fontconfig --strip-components=1
  282. cd ${DEPS}/fontconfig
  283. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  284. --with-expat-includes=${TARGET}/include --with-expat-lib=${TARGET}/lib ${LINUX:+--sysconfdir=/etc} \
  285. ${DARWIN:+--sysconfdir=/usr/local/etc} --disable-docs
  286. make install-strip
  287. mkdir ${DEPS}/harfbuzz
  288. $CURL https://github.com/harfbuzz/harfbuzz/archive/${VERSION_HARFBUZZ}.tar.gz | tar xzC ${DEPS}/harfbuzz --strip-components=1
  289. cd ${DEPS}/harfbuzz
  290. # Disable utils
  291. sed -i'.bak' "/subdir('util')/d" meson.build
  292. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  293. -Dicu=disabled -Dtests=disabled -Dintrospection=disabled -Ddocs=disabled -Dbenchmark=disabled ${DARWIN:+-Dcoretext=enabled}
  294. ninja -C _build
  295. ninja -C _build install
  296. mkdir ${DEPS}/pixman
  297. $CURL https://cairographics.org/releases/pixman-${VERSION_PIXMAN}.tar.gz | tar xzC ${DEPS}/pixman --strip-components=1
  298. cd ${DEPS}/pixman
  299. # Disable tests and demos
  300. sed -i'.bak' "/subdir('test')/{N;d;}" meson.build
  301. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  302. -Dlibpng=disabled -Diwmmxt=disabled -Dgtk=disabled -Dopenmp=disabled
  303. ninja -C _build
  304. ninja -C _build install
  305. mkdir ${DEPS}/cairo
  306. $CURL https://cairographics.org/releases/cairo-${VERSION_CAIRO}.tar.xz | tar xJC ${DEPS}/cairo --strip-components=1
  307. cd ${DEPS}/cairo
  308. sed -i'.bak' "s/^\(Libs:.*\)/\1 @CAIRO_NONPKGCONFIG_LIBS@/" src/cairo.pc.in
  309. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  310. --disable-xlib --disable-xcb --disable-win32 --disable-egl --disable-glx --disable-wgl --disable-ps \
  311. --disable-trace --disable-interpreter ${LINUX:+--disable-quartz} ${DARWIN:+--enable-quartz-image} \
  312. LIBS="-lpixman-1 -lfreetype"
  313. make install-strip
  314. mkdir ${DEPS}/fribidi
  315. $CURL https://github.com/fribidi/fribidi/releases/download/v${VERSION_FRIBIDI}/fribidi-${VERSION_FRIBIDI}.tar.xz | tar xJC ${DEPS}/fribidi --strip-components=1
  316. cd ${DEPS}/fribidi
  317. # Disable tests
  318. sed -i'.bak' "/subdir('test')/d" meson.build
  319. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  320. -Ddocs=false
  321. ninja -C _build
  322. ninja -C _build install
  323. mkdir ${DEPS}/pango
  324. $CURL https://download.gnome.org/sources/pango/$(without_patch $VERSION_PANGO)/pango-${VERSION_PANGO}.tar.xz | tar xJC ${DEPS}/pango --strip-components=1
  325. cd ${DEPS}/pango
  326. # Disable utils, examples, tests and tools
  327. sed -i'.bak' "/subdir('utils')/{N;N;N;d;}" meson.build
  328. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  329. -Dgtk_doc=false -Dintrospection=disabled -Dfontconfig=enabled
  330. ninja -C _build
  331. ninja -C _build install
  332. mkdir ${DEPS}/svg
  333. $CURL https://download.gnome.org/sources/librsvg/$(without_patch $VERSION_SVG)/librsvg-${VERSION_SVG}.tar.xz | tar xJC ${DEPS}/svg --strip-components=1
  334. cd ${DEPS}/svg
  335. sed -i'.bak' "s/^\(Requires:.*\)/\1 cairo-gobject pangocairo/" librsvg.pc.in
  336. # Do not include debugging symbols
  337. sed -i'.bak' "/debug =/ s/= .*/= false/" Cargo.toml
  338. # LTO optimization does not work for staticlib+rlib compilation
  339. sed -i'.bak' "s/, \"rlib\"//" librsvg/Cargo.toml
  340. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  341. --disable-introspection --disable-tools --disable-pixbuf-loader ${DARWIN:+--disable-Bsymbolic}
  342. make install-strip
  343. mkdir ${DEPS}/gif
  344. $CURL https://downloads.sourceforge.net/project/giflib/giflib-${VERSION_GIF}.tar.gz | tar xzC ${DEPS}/gif --strip-components=1
  345. cd ${DEPS}/gif
  346. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking
  347. make install-strip
  348. mkdir ${DEPS}/vips
  349. $CURL https://github.com/libvips/libvips/releases/download/v${VERSION_VIPS}/vips-${VERSION_VIPS}.tar.gz | tar xzC ${DEPS}/vips --strip-components=1
  350. cd ${DEPS}/vips
  351. PKG_CONFIG="pkg-config --static" ./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
  352. --disable-debug --disable-deprecated --disable-introspection --without-analyze --without-cfitsio --without-fftw \
  353. --without-imagequant --without-magick --without-matio --without-nifti --without-OpenEXR \
  354. --without-openslide --without-pdfium --without-poppler --without-ppm --without-radiance \
  355. ${LINUX:+LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"}
  356. # https://docs.fedoraproject.org/en-US/packaging-guidelines/#_removing_rpath
  357. sed -i'.bak' 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
  358. make install-strip
  359. # Cleanup
  360. rm -rf ${TARGET}/lib/{pkgconfig,.libs,*.la,cmake}
  361. mkdir ${TARGET}/lib-filtered
  362. mv ${TARGET}/lib/glib-2.0 ${TARGET}/lib-filtered
  363. # Pack only the relevant libraries
  364. # Note: we can't use ldd on Linux, since that can only be executed on the target machine
  365. # Note 2: we modify all dylib dependencies to use relative paths on macOS
  366. function copydeps {
  367. local base=$1
  368. local dest_dir=$2
  369. cp -L $base $dest_dir/$base
  370. chmod 644 $dest_dir/$base
  371. if [ "$LINUX" = true ]; then
  372. local dependencies=$(readelf -d $base | grep NEEDED | awk '{ print $5 }' | tr -d '[]')
  373. elif [ "$DARWIN" = true ]; then
  374. local dependencies=$(otool -LX $base | awk '{print $1}' | grep $TARGET)
  375. install_name_tool -id @rpath/$base $dest_dir/$base
  376. fi
  377. for dep in $dependencies; do
  378. base_dep=$(basename $dep)
  379. [ ! -f "$PWD/$base_dep" ] && echo "$base_dep does not exist in $PWD" && continue
  380. echo "$base depends on $base_dep"
  381. if [ ! -f "$dest_dir/$base_dep" ]; then
  382. if [ "$DARWIN" = true ]; then
  383. install_name_tool -change $dep @rpath/$base_dep $dest_dir/$base
  384. fi
  385. # Call this function (recursive) on each dependency of this library
  386. copydeps $base_dep $dest_dir
  387. fi
  388. done;
  389. }
  390. cd ${TARGET}/lib
  391. copydeps ${VIPS_CPP_DEP} ${TARGET}/lib-filtered
  392. # Create JSON file of version numbers
  393. cd ${TARGET}
  394. printf "{\n\
  395. \"aom\": \"${VERSION_AOM}\",\n\
  396. \"cairo\": \"${VERSION_CAIRO}\",\n\
  397. \"exif\": \"${VERSION_EXIF}\",\n\
  398. \"expat\": \"${VERSION_EXPAT}\",\n\
  399. \"ffi\": \"${VERSION_FFI}\",\n\
  400. \"fontconfig\": \"${VERSION_FONTCONFIG}\",\n\
  401. \"freetype\": \"${VERSION_FREETYPE}\",\n\
  402. \"fribidi\": \"${VERSION_FRIBIDI}\",\n\
  403. \"gdkpixbuf\": \"${VERSION_GDKPIXBUF}\",\n\
  404. \"gettext\": \"${VERSION_GETTEXT}\",\n\
  405. \"gif\": \"${VERSION_GIF}\",\n\
  406. \"glib\": \"${VERSION_GLIB}\",\n\
  407. \"gsf\": \"${VERSION_GSF}\",\n\
  408. \"harfbuzz\": \"${VERSION_HARFBUZZ}\",\n\
  409. \"heif\": \"${VERSION_HEIF}\",\n\
  410. \"jpeg\": \"${VERSION_JPEG}\",\n\
  411. \"lcms\": \"${VERSION_LCMS2}\",\n\
  412. \"orc\": \"${VERSION_ORC}\",\n\
  413. \"pango\": \"${VERSION_PANGO}\",\n\
  414. \"pixman\": \"${VERSION_PIXMAN}\",\n\
  415. \"png\": \"${VERSION_PNG16}\",\n\
  416. \"svg\": \"${VERSION_SVG}\",\n\
  417. \"spng\": \"${VERSION_SPNG}\",\n\
  418. \"tiff\": \"${VERSION_TIFF}\",\n\
  419. \"vips\": \"${VERSION_VIPS}\",\n\
  420. \"webp\": \"${VERSION_WEBP}\",\n\
  421. \"xml\": \"${VERSION_XML2}\",\n\
  422. \"zlib\": \"${VERSION_ZLIB}\"\n\
  423. }" >versions.json
  424. printf "\"${PLATFORM}\"" >platform.json
  425. # Add third-party notices
  426. $CURL -O https://raw.githubusercontent.com/lovell/sharp-libvips/master/THIRD-PARTY-NOTICES.md
  427. # Create the tarball
  428. rm -rf lib
  429. mv lib-filtered lib
  430. tar chzf ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz \
  431. include \
  432. lib \
  433. *.json \
  434. THIRD-PARTY-NOTICES.md
  435. # Recompress using AdvanceCOMP, ~5% smaller
  436. advdef --recompress --shrink-insane ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz
  437. # Recompress using Brotli, ~15% smaller
  438. gunzip -c ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz | brotli -o ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.br
  439. # Allow tarballs to be read outside container
  440. chmod 644 ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.*