@@ -23,32 +23,73 @@ class Freeimage < Formula
2323 sha256 cellar : :any_skip_relocation , x86_64_linux : "a6c63d08f4adf2395f983ad5f8a51f36ac1e749de9fe6428d056859b199ac6e6"
2424 end
2525
26+ depends_on "pkgconf" => :build
27+ depends_on "imath"
28+ depends_on "jpeg-turbo"
29+ depends_on "jxrlib"
30+ depends_on "libpng"
31+ depends_on "libraw"
32+ depends_on "libtiff"
33+ depends_on "openexr"
34+ depends_on "openjpeg"
35+ depends_on "webp"
36+
37+ uses_from_macos "zlib"
38+
2639 patch do
27- on_macos do
28- url "https://raw.githubusercontent.com/Homebrew/formula-patches/4dcf528/freeimage/3.17.0.patch"
29- sha256 "8ef390fece4d2166d58e739df76b5e7996c879efbff777a8a94bcd1dd9a313e2"
30- end
31- on_linux do
32- url "https://raw.githubusercontent.com/Homebrew/formula-patches/696e313c1f89925a8d04f00282d3b6c204a64f48/freeimage/3.17.0-linux.patch"
33- sha256 "537a4045d31a3ce1c3bab2736d17b979543758cf2081e97fff4d72786f1830dc"
34- end
40+ # Apply Debian patches to unbundle libraries and other fixes
41+ url "https://deb.debian.org/debian/pool/main/f/freeimage/freeimage_3.18.0+ds2-11.debian.tar.xz"
42+ sha256 "4ebd3a84c696dd650d756a43ec60fe22f5b2e591bc5cf8df94a605c5d740c904"
43+ apply "patches/Disable-vendored-dependencies.patch" ,
44+ "patches/Use-system-dependencies.patch" ,
45+ "patches/Fix-macro-redefinition-for-64-bit-integer-types.patch" ,
46+ "patches/Fix_compilation_external-static.patch" ,
47+ "patches/Use-system-jpeg_read_icc_profile.patch" ,
48+ "patches/Fix-libraw-compilation.patch" ,
49+ "patches/Fix-libraw-compilation-2.patch" ,
50+ "patches/build-without-root.patch" ,
51+ "patches/CVE-2019-12211-13.patch"
3552 end
3653
3754 def install
38- # Temporary workaround for ARM. Upstream tracking issue:
39- # https://sourceforge.net/p/freeimage/bugs/325/
40- # https://sourceforge.net/p/freeimage/discussion/36111/thread/cc4cd71c6e/
41- ENV [ "CFLAGS" ] = "-O3 -fPIC -fexceptions -fvisibility=hidden -DPNG_ARM_NEON_OPT=0" if Hardware ::CPU . arm?
55+ # Avoid overlinking with `little-cms2`
56+ as_needed = OS . mac? ? "-dead_strip_dylibs" : "--as-needed"
57+ ENV . append "LDFLAGS" , "-Wl,#{ as_needed } "
58+
59+ # Update jxrlib path from Debian patch to work with Homebrew's jxrlib
60+ inreplace "Makefile.gnu" , "-I/usr/include/jxrlib" , "-I#{ Formula [ "jxrlib" ] . opt_include } /jxrlib"
61+
62+ # Update to fix build with OpenEXR 3 on macOS where type has changed
63+ inreplace "Source/FreeImage/PluginEXR.cpp" , /\b Imath::Int64\b / , "uint64_t"
64+
65+ # Remove the bundled libraries and regenerate some Makefiles
66+ rm_r ( [ *Dir [ "Source/Lib*" ] , "Source/ZLib" , "Source/OpenEXR" ] )
67+ system "bash" , "gensrclist.sh"
68+ system "bash" , "genfipsrclist.sh"
69+
70+ args = [ "INCDIR=#{ include } " , "INSTALLDIR=#{ lib } " ]
71+ if OS . mac?
72+ # Make the Linux Makefiles compatible with macOS
73+ args += %w[
74+ SHAREDLIB=lib$(TARGET).$(VER_MAJOR).$(VER_MINOR).dylib
75+ LIBNAME=lib$(TARGET).dylib
76+ VERLIBNAME=lib$(TARGET).$(VER_MAJOR).dylib
77+ ]
78+ ld_version_args = "-current_version $(VER_MAJOR).$(VER_MINOR) -compatibility_version $(VER_MAJOR)"
79+ inreplace [ "Makefile.gnu" , "Makefile.fip" ] do |s |
80+ s . gsub! "-shared -Wl,-soname,$(VERLIBNAME)" , "-dynamiclib -install_name $(VERLIBNAME) #{ ld_version_args } "
81+
82+ # Update Debian patch to include `pkgconf ... libwebp`
83+ s . gsub! " libwebpmux " , " libwebp libwebpmux "
84+ end
85+ end
4286
43- # Fix compile with newer Clang
44- ENV . append_to_cflags "-Wno-implicit-function-declaration" if DevelopmentTools . clang_build_version >= 1403
87+ system "make" , "-f" , "Makefile.gnu" , * args
88+ system "make" , "-f" , "Makefile.gnu" , "install" , * args
4589
46- # Fix build error on Linux: ImathVec.h:771:37: error: ISO C++17 does not allow dynamic exception specifications
47- ENV [ "CXXFLAGS" ] = "-std=c++98" if OS . linux?
48- system "make" , "-f" , "Makefile.gnu"
49- system "make" , "-f" , "Makefile.gnu" , "install" , "PREFIX=#{ prefix } "
50- system "make" , "-f" , "Makefile.fip"
51- system "make" , "-f" , "Makefile.fip" , "install" , "PREFIX=#{ prefix } "
90+ ENV . append "LDFLAGS" , "-L#{ lib } -lfreeimage"
91+ system "make" , "-f" , "Makefile.fip" , *args
92+ system "make" , "-f" , "Makefile.fip" , "install" , *args
5293 end
5394
5495 test do
0 commit comments