lin.sh 22 KB

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