-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.jl
117 lines (103 loc) · 4.61 KB
/
build.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using BinDeps, Compat
@BinDeps.setup
function cleanup()
base_path = dirname(@__FILE__)
downpath = joinpath(base_path, "downloads")
usrpath = joinpath(base_path, "usr")
depspath = joinpath(base_path, "deps.jl")
versioninfopath = joinpath(base_path, "versioninfo.jl")
isdir(downpath) && try rm(downpath, recursive=true) end # its not strictly necessary to succeed and there are too many factors for this to error
isdir(usrpath) && try rm(usrpath, recursive=true) end
isfile(depspath) && try rm(depspath) end
isfile(versioninfopath) && try rm(versioninfopath) end
end
cleanup()
mpath = get(ENV, "MAGICK_HOME", "") # If MAGICK_HOME is defined, add to library search path
if !isempty(mpath)
push!(DL_LOAD_PATH, mpath)
push!(DL_LOAD_PATH, joinpath(mpath,"lib"))
end
libnames = ["libMagickWand", "CORE_RL_wand_"]
suffixes = ["", "-Q16", "-6.Q16", "-Q8"]
options = ["", "HDRI"]
extensions = ["", ".so.2", ".so.4", ".so.5"]
aliases = vec(libnames.*transpose(suffixes).*reshape(options,(1,1,length(options))).*reshape(extensions,(1,1,1,length(extensions))))
libwand = library_dependency("libwand", aliases = aliases)
@linux_only begin
kwargs = Any[(:onload, "ccall((:MagickWandGenesis,libwand), Void, ())"), (:preload, "magick_hooks() = nothing")]
provides(AptGet, "libmagickwand4", libwand; kwargs...)
provides(AptGet, "libmagickwand5", libwand; kwargs...)
provides(AptGet, "libmagickwand-6.q16-2", libwand; kwargs...)
provides(Pacman, "imagemagick", libwand; kwargs...)
provides(Yum, "ImageMagick", libwand; kwargs...)
end
# TODO: remove me when upstream is fixed
@windows_only push!(BinDeps.defaults, BuildProcess)
@windows_only begin
const OS_ARCH = (WORD_SIZE == 64) ? "x64" : "x86"
# TODO: checksums: we have gpg
# Extract the appropriate filename to download
magick_base = "http://www.imagemagick.org/download/binaries"
binariesfn = download(magick_base)
str = readall(binariesfn)
pattern = "ImageMagick-6.9.*?-Q16-$(OS_ARCH)-dll.exe"
m = match(Regex(pattern), str)
magick_exe = convert(ASCIIString, m.match)
magick_tmpdir = BinDeps.downloadsdir(libwand)
magick_url = "$(magick_base)/$(magick_exe)"
magick_libdir = joinpath(BinDeps.libdir(libwand), OS_ARCH)
innounp_url = "https://bintray.com/artifact/download/julialang/generic/innounp.exe"
provides(BuildProcess,
(@build_steps begin
CreateDirectory(magick_tmpdir)
CreateDirectory(magick_libdir)
FileDownloader(magick_url, joinpath(magick_tmpdir, magick_exe))
FileDownloader(innounp_url, joinpath(magick_tmpdir, "innounp.exe"))
@build_steps begin
ChangeDirectory(magick_tmpdir)
info("Installing ImageMagick library")
`innounp.exe -q -y -b -e -x -d$(magick_libdir) $(magick_exe)`
end
end),
libwand,
os = :Windows,
unpacked_dir = magick_libdir,
preload =
"""
function magick_hooks()
ENV["MAGICK_CONFIGURE_PATH"] = \"$(escape_string(magick_libdir))\"
ENV["MAGICK_CODER_MODULE_PATH"] = \"$(escape_string(magick_libdir))\"
end
""",
onload = "ccall((:MagickWandGenesis,libwand), Void, ())")
end
@osx_only begin
if Pkg.installed("Homebrew") === nothing
error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")")
end
using Homebrew
provides( Homebrew.HB, "imagemagick", libwand, os = :Darwin, onload =
"""
function magick_hooks()
println(\"called magick hooks\")
ENV["MAGICK_CONFIGURE_PATH"] = joinpath("$(Homebrew.prefix("imagemagick"))","lib","ImageMagick","config-Q16")
ENV["MAGICK_CODER_MODULE_PATH"] = joinpath("$(Homebrew.prefix("imagemagick"))", "lib","ImageMagick","modules-Q16","coders")
ENV["PATH"] = joinpath("$(Homebrew.prefix("imagemagick"))", "bin") * ":" * ENV["PATH"]
ccall((:MagickWandGenesis,libwand), Void, ())
println(\"success\")
end
""" )
end
@BinDeps.install Dict([(:libwand, :libwand)])
# Save the library version; by checking this now, we avoid a runtime dependency on libwand
# See https://github.com/timholy/Images.jl/issues/184#issuecomment-55643225
module CheckVersion
using Compat
include("deps.jl")
magick_hooks()
p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8},), "LIB_VERSION_NUMBER")
vstr = string("v\"", join(split(bytestring(p), ',')[1:3], '.'), "\"")
open(joinpath(dirname(@__FILE__),"versioninfo.jl"), "w") do file
write(file, "const libversion = $vstr\n")
end
end