@@ -31,14 +31,18 @@ installGit() {
3131 git version --build-options
3232}
3333
34- # Try to install libaom.
34+ # Install libaom.
3535#
3636# Arguments:
3737# $1: the version to be installed
38+ #
39+ # Return:
40+ # 0 in case of success
41+ # 1 in case of errors
3842installLibaom () {
39- if ! isCMakeAtLeastVersion ' 3.6 ' ; then
40- echo ' libaom not installed because cmake is too old ' >&2
41- return
43+ if ! isAvifSupported 2> /dev/null && ! isHeicSupported 2> /dev/null ; then
44+ echo ' libaom not installed because the system does not support neither AVIF nor HEIC ' >&2
45+ return 1
4246 fi
4347 installAptPackages ' ' ' cmake ninja-build nasm'
4448 printf ' Downloading libaom v%s... ' " $1 "
@@ -54,16 +58,21 @@ installLibaom() {
5458 ldconfig
5559 markPackagesAsInstalledByRegex ' ^(lib)?aom([0-9]|-dev)'
5660 pkg-config --list-all | grep -E ' ^(lib)?aom\s'
61+ return 0
5762}
5863
59- # Try to install libdav1d.
64+ # Install libdav1d.
6065#
6166# Arguments:
6267# $1: the version to be installed
68+ #
69+ # Return:
70+ # 0 in case of success
71+ # 1 in case of errors
6372installLibdav1d () {
64- if ! isMesonAtLeastVersion ' 0.44 ' ; then
65- echo ' libdav1d not installed because meson is too old ' >&2
66- return
73+ if ! isAvifSupported 2> /dev/null ; then
74+ echo ' libdav1d not installed because the system does not support AVIF ' >&2
75+ return 1
6776 fi
6877 installAptPackages ' ' ' meson ninja-build nasm'
6978 printf ' Downloading libdav1d v%s... ' " $1 "
@@ -82,16 +91,21 @@ installLibdav1d() {
8291 ldconfig
8392 markPackagesAsInstalledByRegex ' ^(lib)?dav1d([0-9]|-dev)'
8493 pkg-config --list-all | grep -E ' ^(lib)?dav1d\s'
94+ return 0
8595}
8696
87- # Try to install libyuv.
97+ # Install libyuv.
8898#
8999# Arguments:
90100# $1: the version to be installed
101+ #
102+ # Return:
103+ # 0 in case of success
104+ # 1 in case of errors
91105installLibyuv () {
92- if ! isGccAtLeastVersion ' 4.9.3 ' ; then
93- echo ' libyuv not installed because gcc is too old ' >&2
94- return
106+ if ! isAvifSupported 2> /dev/null && ! isHeicSupported 2> /dev/null ; then
107+ echo ' libyuv not installed because the system does not support neither AVIF nor HEIC ' >&2
108+ return 1
95109 fi
96110 installAptPackages ' ^libjpeg[0-9]*-turbo' ' cmake ^libjpeg[0-9]*-turbo-dev'
97111 printf ' Downloading libyuv... '
@@ -100,27 +114,60 @@ installLibyuv() {
100114 printf ' done.\n'
101115 mkdir " $installLibyuv_dir /build"
102116 cd " $installLibyuv_dir /build"
117+ printf ' \nconfigure_file(imaginepatch-libyuv.pc.in imaginepatch-libyuv.pc @ONLY)\n' >> ../CMakeLists.txt
118+ cat << 'EOT ' >../imaginepatch-libyuv.pc.in
119+ prefix=@CMAKE_INSTALL_PREFIX@
120+ exec_prefix=${prefix}
121+ includedir=${prefix}/include
122+ libdir=${prefix}/lib
123+
124+ Name: @CPACK_PACKAGE_NAME@
125+ Description: @CPACK_PACKAGE_DESCRIPTION@
126+ Version: @CPACK_PACKAGE_VERSION@
127+ Requires: @pc_req_public@
128+ Requires.private: @pc_req_private@
129+ Cflags: -I${includedir}
130+ Libs: -L${libdir} -llibyuv
131+ EOT
103132 cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -B. ..
104133 make -j$( nproc) install
134+ ldconfig
135+ if ! pkg-config --exists libyuv && ! pkg-config --exists yuv; then
136+ cp imaginepatch-libyuv.pc /usr/lib/pkgconfig/libyuv.pc
137+ ldconfig
138+ fi
105139 cd - > /dev/null
106140 rm -rf " $installLibyuv_dir "
107141 ldconfig
108142 markPackagesAsInstalledByRegex ' ^(lib)?yuv([0-9]|-dev)'
109- # pkg-config --list-all | grep -E '^(lib)?yuv\s'
143+ pkg-config --list-all | grep -E ' ^(lib)?yuv\s'
144+ return 0
110145}
111146
112- # Try to install libavif.
147+ # Install libavif.
113148#
114149# Arguments:
115150# $1: the version to be installed
151+ #
152+ # Return:
153+ # 0 in case of success
154+ # 1 in case of errors
116155installLibavif () {
156+ if ! isAvifSupported 2> /dev/null; then
157+ echo ' libavif not installed because the system does not support AVIF' >&2
158+ return 1
159+ fi
117160 if ! pkg-config --list-all | grep -E ' ^(lib)?aom\s' > /dev/null; then
118161 echo ' libavif not installed because libaom is not installed' >&2
119- return
162+ return 1
120163 fi
121- if ! isCMakeAtLeastVersion ' 3.5' ; then
122- echo ' libavif not installed because cmake is too old' >&2
123- return
164+ if ! pkg-config --list-all | grep -E ' ^(lib)?dav1d\s' > /dev/null; then
165+ echo ' libavif not installed because libdav1d is not installed' >&2
166+ return 1
167+ fi
168+ if ! pkg-config --list-all | grep -E ' ^(lib)?yuv\s' > /dev/null; then
169+ echo ' libavif not installed because libyuv is not installed' >&2
170+ return 1
124171 fi
125172 installAptPackages ' ' ' cmake'
126173 printf ' Downloading libavif v%s... ' " $1 "
@@ -136,17 +183,26 @@ installLibavif() {
136183 ldconfig
137184 markPackagesAsInstalledByRegex ' ^(lib)?avif([0-9]|-dev)'
138185 pkg-config --list-all | grep -E ' ^(lib)?avif\s'
186+ return 0
139187}
140188
141189# Install libde265.
142190#
143191# Arguments:
144192# $1: the version to be installed
145193#
194+ # Return:
195+ # 0 in case of success
196+ # 1 in case of errors
197+ #
146198# @todo:
147199# configure: WARNING: Did not find libvideogfx or libsdl, video output of dec265 will be disabled.
148200# configure: WARNING: Did not find libvideogfx or libswscale, compilation of sherlock265 will be disabled.
149201installLibde265 () {
202+ if ! isHeicSupported 2> /dev/null; then
203+ echo ' libde265 not installed because the system does not support HEIC' >&2
204+ return 1
205+ fi
150206 installAptPackages ' ' ' automake libtool'
151207 printf ' Downloading libde265 v%s... ' " $1 "
152208 installLibde265_dir=" $( mktemp -d) "
@@ -161,14 +217,31 @@ installLibde265() {
161217 ldconfig
162218 markPackagesAsInstalledByRegex ' ^(lib)?de265'
163219 pkg-config --list-all | grep -E ' ^(lib)?de265\s'
220+ return 0
164221}
165222
166223# Install libheif.
167224#
168225# Arguments:
169226# $1: the version to be installed
227+ #
228+ # Return:
229+ # 0 in case of success
230+ # 1 in case of errors
170231installLibheif () {
171- installAptPackages ' ^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$' ' automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev'
232+ if ! isHeicSupported 2> /dev/null; then
233+ echo ' libheif not installed because the system does not support HEIC' >&2
234+ return 1
235+ fi
236+ if ! pkg-config --list-all | grep -E ' ^(lib)?aom\s' > /dev/null; then
237+ echo ' libheif not installed because libaom is not installed' >&2
238+ return 1
239+ fi
240+ if ! pkg-config --list-all | grep -E ' ^(lib)?de265\s' > /dev/null; then
241+ echo ' libheif not installed because libde265 is not installed' >&2
242+ return 1
243+ fi
244+ installAptPackages ' ^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$ ^libx265(-[0-9\.\-]+)?$' ' automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev libx265-dev'
172245 printf ' Downloading libheif v%s... ' " $1 "
173246 installLibheif_dir=" $( mktemp -d) "
174247 curl -ksSLf -o - https://github.com/strukturag/libheif/releases/download/v$1 /libheif-$1 .tar.gz | tar xzm -C " $installLibheif_dir "
@@ -182,6 +255,59 @@ installLibheif() {
182255 ldconfig
183256 markPackagesAsInstalledByRegex ' ^libheif.*'
184257 pkg-config --list-all | grep -E ' ^(lib)?heif\s'
258+ return 0
259+ }
260+
261+ # Check if AVIF format is supported in this environment
262+ #
263+ # Output (stderr):
264+ # the reason (if any) why it's not supported
265+ #
266+ # Return:
267+ # 0: true
268+ # 1: false
269+ isAvifSupported () {
270+ if ! isCMakeAtLeastVersion ' 3.6' ; then
271+ echo ' AVIF support not provided since compiling libaom requires a more recent cmake version' >&2
272+ return 1
273+ fi
274+ if ! isMesonAtLeastVersion ' 0.44' ; then
275+ echo ' AVIF support not provided since compiling libdav1d requires a more recent meson version' >&2
276+ return 1
277+ fi
278+ if ! isGccAtLeastVersion ' 4.9.3' ; then
279+ echo ' AVIF support not provided since compiling libyuv requires a more recent gcc version' >&2
280+ return 1
281+ fi
282+ if ! isCMakeAtLeastVersion ' 3.5' ; then
283+ echo ' AVIF support not provided since compiling libavif requires a more recent cmake version' >&2
284+ return 1
285+ fi
286+ return 0
287+ }
288+
289+ # Check if HEIC format is supported in this environment
290+ #
291+ # Output (stderr):
292+ # the reason (if any) why it's not supported
293+ #
294+ # Return:
295+ # 0: true
296+ # 1: false
297+ isHeicSupported () {
298+ if ! isCMakeAtLeastVersion ' 3.6' ; then
299+ echo ' HEIC support not provided since compiling libaom requires a more recent cmake version' >&2
300+ return 1
301+ fi
302+ if [ -z " $( getAptPackageAvailableVersion ' libx265(-[0-9\.\-]+)?$' ) " ]; then
303+ echo ' HEIC support not provided since libx265 is not available'
304+ return 1
305+ fi
306+ if ! isGccAtLeastVersion ' 4.9.3' ; then
307+ echo ' HEIC support not provided since compiling libyuv requires a more recent gcc version' >&2
308+ return 1
309+ fi
310+ return 0
185311}
186312
187313# Install GraphicsMagick.
@@ -204,7 +330,7 @@ installGraphicsmagick() {
204330 curl -ksSLf -o - http://ftp.icm.edu.pl/pub/unix/graphics/GraphicsMagick/${1% .* } /GraphicsMagick-$1 .tar.gz | tar xzm -C " $installGraphicsmagick_dir "
205331 printf ' done.\n'
206332 cd " $installGraphicsmagick_dir /GraphicsMagick-$1 "
207- CFLAGS=' -Wno-misleading-indentation -Wno-unused-const-variable -Wno-pointer-compare -Wno-tautological-compare' ./configure --enable-shared
333+ CFLAGS=' -Wno-misleading-indentation -Wno-unused-const-variable -Wno-pointer-compare -Wno-tautological-compare' ./configure --disable-static -- enable-shared
208334 make V=0 -j$( nproc) install
209335 cd - > /dev/null
210336 rm -rf " $installGraphicsmagick_dir "
@@ -232,7 +358,7 @@ installImagemagick() {
232358 curl -ksSLf -o - https://www.imagemagick.org/download/releases/ImageMagick-$1 .tar.xz | tar xJm -C " $installImagemagick_dir "
233359 printf ' done.\n'
234360 cd " $installImagemagick_dir /ImageMagick-$1 "
235- ./configure --disable-docs
361+ ./configure --disable-docs --disable-static --enable-shared
236362 make V=0 -j$( nproc) install
237363 cd - > /dev/null
238364 rm -rf " $installImagemagick_dir "
@@ -242,13 +368,23 @@ installImagemagick() {
242368
243369if grep -Eq ' PRETTY_NAME.*jessie' /etc/os-release; then
244370 # https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1332440
245- ulimit -n 10000
371+ ulimit -n 10000 2> /dev/null || true
246372fi
247373
248374case " $1 " in
249375 git)
250376 installGit " $2 "
251377 ;;
378+ support-avif)
379+ if ! isAvifSupported; then
380+ return 1
381+ fi
382+ ;;
383+ support-heic)
384+ if ! isHeicSupported; then
385+ return 1
386+ fi
387+ ;;
252388 libaom)
253389 installLibaom " $2 "
254390 ;;
0 commit comments