lin.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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.6
  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.1
  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}/mozjpeg
  205. curl -Ls https://github.com/mozilla/mozjpeg/archive/v${VERSION_MOZJPEG}.tar.gz | tar xzC ${DEPS}/mozjpeg --strip-components=1
  206. cd ${DEPS}/mozjpeg
  207. autoreconf -fiv
  208. ./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-jpeg8
  209. make install-strip
  210. mkdir ${DEPS}/jpeg
  211. $CURL https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION_JPEG}.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1
  212. cd ${DEPS}/jpeg
  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 -DWITH_TURBOJPEG=FALSE
  215. make install/strip
  216. mkdir ${DEPS}/png16
  217. $CURL https://downloads.sourceforge.net/project/libpng/libpng16/${VERSION_PNG16}/libpng-${VERSION_PNG16}.tar.xz | tar xJC ${DEPS}/png16 --strip-components=1
  218. cd ${DEPS}/png16
  219. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking
  220. make install-strip
  221. mkdir ${DEPS}/spng
  222. $CURL https://github.com/randy408/libspng/archive/v${VERSION_SPNG}.tar.gz | tar xzC ${DEPS}/spng --strip-components=1
  223. cd ${DEPS}/spng
  224. meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  225. -Dstatic_zlib=true
  226. ninja -C _build
  227. ninja -C _build install
  228. mkdir ${DEPS}/webp
  229. $CURL https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-${VERSION_WEBP}.tar.gz | tar xzC ${DEPS}/webp --strip-components=1
  230. cd ${DEPS}/webp
  231. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  232. --disable-neon --enable-libwebpmux --enable-libwebpdemux
  233. make install-strip
  234. mkdir ${DEPS}/tiff
  235. $CURL https://download.osgeo.org/libtiff/tiff-${VERSION_TIFF}.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1
  236. cd ${DEPS}/tiff
  237. if [ -n "${CHOST}" ]; then autoreconf -fiv; fi
  238. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  239. --disable-mdi --disable-pixarlog --disable-old-jpeg --disable-cxx --disable-lzma --disable-zstd \
  240. --with-jpeg-include-dir=${TARGET}/include --with-jpeg-lib-dir=${TARGET}/lib
  241. make install-strip
  242. mkdir ${DEPS}/orc
  243. $CURL https://gstreamer.freedesktop.org/data/src/orc/orc-${VERSION_ORC}.tar.xz | tar xJC ${DEPS}/orc --strip-components=1
  244. cd ${DEPS}/orc
  245. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  246. -Dorc-test=disabled -Dbenchmarks=disabled -Dexamples=disabled -Dgtk_doc=disabled -Dtests=disabled -Dtools=disabled
  247. ninja -C _build
  248. ninja -C _build install
  249. mkdir ${DEPS}/gdkpixbuf
  250. $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
  251. cd ${DEPS}/gdkpixbuf
  252. # Disable tests and thumbnailer
  253. sed -i'.bak' "/subdir('tests')/{N;d;}" meson.build
  254. # Disable the built-in loaders for BMP, GIF, ICO, PNM, XPM, XBM, TGA, ICNS and QTIF
  255. sed -i'.bak' "/\[ 'bmp'/{N;N;N;d;}" gdk-pixbuf/meson.build
  256. sed -i'.bak' "/\[ 'pnm'/d" gdk-pixbuf/meson.build
  257. sed -i'.bak' "/\[ 'xpm'/{N;N;N;N;d;}" gdk-pixbuf/meson.build
  258. # Ensure meson can find libjpeg when cross-compiling
  259. sed -i'.bak' "s/has_header('jpeglib.h')/has_header('jpeglib.h', args: '-I\/target\/include')/g" meson.build
  260. sed -i'.bak' "s/cc.find_library('jpeg'/dependency('libjpeg'/g" meson.build
  261. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  262. -Dtiff=false -Dintrospection=disabled -Dinstalled_tests=false -Dgio_sniffing=false -Dman=false -Dbuiltin_loaders=png,jpeg
  263. ninja -C _build
  264. ninja -C _build install
  265. # Include libjpeg and libpng as a dependency of gdk-pixbuf, see: https://gitlab.gnome.org/GNOME/gdk-pixbuf/merge_requests/50
  266. sed -i'.bak' "s/^\(Requires:.*\)/\1 libjpeg, libpng16/" ${TARGET}/lib/pkgconfig/gdk-pixbuf-2.0.pc
  267. mkdir ${DEPS}/freetype
  268. $CURL https://download.savannah.gnu.org/releases/freetype/freetype-${VERSION_FREETYPE}.tar.xz | tar xJC ${DEPS}/freetype --strip-components=1
  269. cd ${DEPS}/freetype
  270. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  271. --without-bzip2 --without-png
  272. make install
  273. mkdir ${DEPS}/expat
  274. $CURL https://github.com/libexpat/libexpat/releases/download/R_${VERSION_EXPAT//./_}/expat-${VERSION_EXPAT}.tar.xz | tar xJC ${DEPS}/expat --strip-components=1
  275. cd ${DEPS}/expat
  276. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared \
  277. --disable-dependency-tracking --without-xmlwf --without-docbook --without-getrandom --without-sys-getrandom
  278. make install
  279. mkdir ${DEPS}/fontconfig
  280. $CURL https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.xz | tar xJC ${DEPS}/fontconfig --strip-components=1
  281. cd ${DEPS}/fontconfig
  282. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  283. --with-expat-includes=${TARGET}/include --with-expat-lib=${TARGET}/lib ${LINUX:+--sysconfdir=/etc} \
  284. ${DARWIN:+--sysconfdir=/usr/local/etc} --disable-docs
  285. make install-strip
  286. mkdir ${DEPS}/harfbuzz
  287. $CURL https://github.com/harfbuzz/harfbuzz/archive/${VERSION_HARFBUZZ}.tar.gz | tar xzC ${DEPS}/harfbuzz --strip-components=1
  288. cd ${DEPS}/harfbuzz
  289. # Disable utils
  290. sed -i'.bak' "/subdir('util')/d" meson.build
  291. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  292. -Dicu=disabled -Dtests=disabled -Dintrospection=disabled -Ddocs=disabled -Dbenchmark=disabled ${DARWIN:+-Dcoretext=enabled}
  293. ninja -C _build
  294. ninja -C _build install
  295. mkdir ${DEPS}/pixman
  296. $CURL https://cairographics.org/releases/pixman-${VERSION_PIXMAN}.tar.gz | tar xzC ${DEPS}/pixman --strip-components=1
  297. cd ${DEPS}/pixman
  298. # Disable tests and demos
  299. sed -i'.bak' "/subdir('test')/{N;d;}" meson.build
  300. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  301. -Dlibpng=disabled -Diwmmxt=disabled -Dgtk=disabled -Dopenmp=disabled
  302. ninja -C _build
  303. ninja -C _build install
  304. mkdir ${DEPS}/cairo
  305. $CURL https://cairographics.org/releases/cairo-${VERSION_CAIRO}.tar.xz | tar xJC ${DEPS}/cairo --strip-components=1
  306. cd ${DEPS}/cairo
  307. sed -i'.bak' "s/^\(Libs:.*\)/\1 @CAIRO_NONPKGCONFIG_LIBS@/" src/cairo.pc.in
  308. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  309. --disable-xlib --disable-xcb --disable-win32 --disable-egl --disable-glx --disable-wgl --disable-ps \
  310. --disable-trace --disable-interpreter ${LINUX:+--disable-quartz} ${DARWIN:+--enable-quartz-image} \
  311. LIBS="-lpixman-1 -lfreetype"
  312. make install-strip
  313. mkdir ${DEPS}/fribidi
  314. $CURL https://github.com/fribidi/fribidi/releases/download/v${VERSION_FRIBIDI}/fribidi-${VERSION_FRIBIDI}.tar.xz | tar xJC ${DEPS}/fribidi --strip-components=1
  315. cd ${DEPS}/fribidi
  316. # Disable tests
  317. sed -i'.bak' "/subdir('test')/d" meson.build
  318. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  319. -Ddocs=false
  320. ninja -C _build
  321. ninja -C _build install
  322. mkdir ${DEPS}/pango
  323. $CURL https://download.gnome.org/sources/pango/$(without_patch $VERSION_PANGO)/pango-${VERSION_PANGO}.tar.xz | tar xJC ${DEPS}/pango --strip-components=1
  324. cd ${DEPS}/pango
  325. # Disable utils, examples, tests and tools
  326. sed -i'.bak' "/subdir('utils')/{N;N;N;d;}" meson.build
  327. LDFLAGS=${LDFLAGS/\$/} meson setup _build --default-library=static --buildtype=release --strip --prefix=${TARGET} ${MESON} \
  328. -Dgtk_doc=false -Dintrospection=disabled -Dfontconfig=enabled
  329. ninja -C _build
  330. ninja -C _build install
  331. mkdir ${DEPS}/svg
  332. $CURL https://download.gnome.org/sources/librsvg/$(without_patch $VERSION_SVG)/librsvg-${VERSION_SVG}.tar.xz | tar xJC ${DEPS}/svg --strip-components=1
  333. cd ${DEPS}/svg
  334. sed -i'.bak' "s/^\(Requires:.*\)/\1 cairo-gobject pangocairo/" librsvg.pc.in
  335. # Do not include debugging symbols
  336. sed -i'.bak' "/debug =/ s/= .*/= false/" Cargo.toml
  337. # LTO optimization does not work for staticlib+rlib compilation
  338. sed -i'.bak' "s/, \"rlib\"//" librsvg/Cargo.toml
  339. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking \
  340. --disable-introspection --disable-tools --disable-pixbuf-loader ${DARWIN:+--disable-Bsymbolic}
  341. make install-strip
  342. mkdir ${DEPS}/gif
  343. $CURL https://downloads.sourceforge.net/project/giflib/giflib-${VERSION_GIF}.tar.gz | tar xzC ${DEPS}/gif --strip-components=1
  344. cd ${DEPS}/gif
  345. ./configure --host=${CHOST} --prefix=${TARGET} --enable-static --disable-shared --disable-dependency-tracking
  346. make install-strip
  347. mkdir ${DEPS}/vips
  348. $CURL https://github.com/libvips/libvips/releases/download/v${VERSION_VIPS}/vips-${VERSION_VIPS}.tar.gz | tar xzC ${DEPS}/vips --strip-components=1
  349. cd ${DEPS}/vips
  350. PKG_CONFIG="pkg-config --static" ./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
  351. --disable-debug --disable-deprecated --disable-introspection --without-analyze --without-cfitsio --without-fftw \
  352. --without-imagequant --without-magick --without-matio --without-nifti --without-OpenEXR \
  353. --without-openslide --without-pdfium --without-poppler --without-ppm --without-radiance \
  354. ${LINUX:+LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"}
  355. # https://docs.fedoraproject.org/en-US/packaging-guidelines/#_removing_rpath
  356. sed -i'.bak' 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
  357. make install-strip
  358. # Cleanup
  359. rm -rf ${TARGET}/lib/{pkgconfig,.libs,*.la,cmake}
  360. mkdir ${TARGET}/lib-filtered
  361. mv ${TARGET}/lib/glib-2.0 ${TARGET}/lib-filtered
  362. # Pack only the relevant libraries
  363. # Note: we can't use ldd on Linux, since that can only be executed on the target machine
  364. # Note 2: we modify all dylib dependencies to use relative paths on macOS
  365. function copydeps {
  366. local base=$1
  367. local dest_dir=$2
  368. cp -L $base $dest_dir/$base
  369. chmod 644 $dest_dir/$base
  370. if [ "$LINUX" = true ]; then
  371. local dependencies=$(readelf -d $base | grep NEEDED | awk '{ print $5 }' | tr -d '[]')
  372. elif [ "$DARWIN" = true ]; then
  373. local dependencies=$(otool -LX $base | awk '{print $1}' | grep $TARGET)
  374. install_name_tool -id @rpath/$base $dest_dir/$base
  375. fi
  376. for dep in $dependencies; do
  377. base_dep=$(basename $dep)
  378. [ ! -f "$PWD/$base_dep" ] && echo "$base_dep does not exist in $PWD" && continue
  379. echo "$base depends on $base_dep"
  380. if [ ! -f "$dest_dir/$base_dep" ]; then
  381. if [ "$DARWIN" = true ]; then
  382. install_name_tool -change $dep @rpath/$base_dep $dest_dir/$base
  383. fi
  384. # Call this function (recursive) on each dependency of this library
  385. copydeps $base_dep $dest_dir
  386. fi
  387. done;
  388. }
  389. cd ${TARGET}/lib
  390. copydeps ${VIPS_CPP_DEP} ${TARGET}/lib-filtered
  391. # Create JSON file of version numbers
  392. cd ${TARGET}
  393. printf "{\n\
  394. \"aom\": \"${VERSION_AOM}\",\n\
  395. \"cairo\": \"${VERSION_CAIRO}\",\n\
  396. \"exif\": \"${VERSION_EXIF}\",\n\
  397. \"expat\": \"${VERSION_EXPAT}\",\n\
  398. \"ffi\": \"${VERSION_FFI}\",\n\
  399. \"fontconfig\": \"${VERSION_FONTCONFIG}\",\n\
  400. \"freetype\": \"${VERSION_FREETYPE}\",\n\
  401. \"fribidi\": \"${VERSION_FRIBIDI}\",\n\
  402. \"gdkpixbuf\": \"${VERSION_GDKPIXBUF}\",\n\
  403. \"gettext\": \"${VERSION_GETTEXT}\",\n\
  404. \"gif\": \"${VERSION_GIF}\",\n\
  405. \"glib\": \"${VERSION_GLIB}\",\n\
  406. \"gsf\": \"${VERSION_GSF}\",\n\
  407. \"harfbuzz\": \"${VERSION_HARFBUZZ}\",\n\
  408. \"heif\": \"${VERSION_HEIF}\",\n\
  409. \"jpeg\": \"${VERSION_JPEG}\",\n\
  410. \"lcms\": \"${VERSION_LCMS2}\",\n\
  411. \"orc\": \"${VERSION_ORC}\",\n\
  412. \"pango\": \"${VERSION_PANGO}\",\n\
  413. \"pixman\": \"${VERSION_PIXMAN}\",\n\
  414. \"png\": \"${VERSION_PNG16}\",\n\
  415. \"svg\": \"${VERSION_SVG}\",\n\
  416. \"spng\": \"${VERSION_SPNG}\",\n\
  417. \"tiff\": \"${VERSION_TIFF}\",\n\
  418. \"vips\": \"${VERSION_VIPS}\",\n\
  419. \"webp\": \"${VERSION_WEBP}\",\n\
  420. \"xml\": \"${VERSION_XML2}\",\n\
  421. \"zlib\": \"${VERSION_ZLIB}\"\n\
  422. }" >versions.json
  423. printf "\"${PLATFORM}\"" >platform.json
  424. # Add third-party notices
  425. $CURL -O https://raw.githubusercontent.com/lovell/sharp-libvips/master/THIRD-PARTY-NOTICES.md
  426. # Create the tarball
  427. rm -rf lib
  428. mv lib-filtered lib
  429. tar chzf ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz \
  430. include \
  431. lib \
  432. *.json \
  433. THIRD-PARTY-NOTICES.md
  434. # Recompress using AdvanceCOMP, ~5% smaller
  435. advdef --recompress --shrink-insane ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz
  436. # Recompress using Brotli, ~15% smaller
  437. gunzip -c ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz | brotli -o ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.br
  438. # Allow tarballs to be read outside container
  439. chmod 644 ${PACKAGE}/libvips-${VERSION_VIPS}-${PLATFORM}.tar.*