using BinaryProvider
# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
products = Product[
    # Instantiate products here, e.g.:
    LibraryProduct(prefix, "libgumbo", :libgumbo),
 ]
# Download binaries from hosted location
bin_prefix = "https://github.com/JuliaWeb/GumboBuilder/releases/download/v0.1.0"
# Listing of files generated by BinaryBuilder:
download_info = Dict(
    BinaryProvider.Linux(:aarch64, :glibc) => ("$bin_prefix/Gumbo.aarch64-linux-gnu.tar.gz", "14e50e3705352ead8e189375c93886028b3a947e61e31b0e8f8068d8f6a7e84b"),
    BinaryProvider.Linux(:armv7l, :glibc) => ("$bin_prefix/Gumbo.arm-linux-gnueabihf.tar.gz", "d76c42f3f3a8f75ab8fa976f8e309bc7bd30e2f2188844df785c4b36462545fb"),
    BinaryProvider.Linux(:i686, :glibc) => ("$bin_prefix/Gumbo.i686-linux-gnu.tar.gz", "0d1de0621fc6f23ae3119f2fc8102f0af83bc1f82287e943d23159f60ab0c503"),
    BinaryProvider.Windows(:i686) => ("$bin_prefix/Gumbo.i686-w64-mingw32.tar.gz", "48f80a41d504775a7d79acffd597d5921bf3fd14f2d046f229f643c43656c9ce"),
    BinaryProvider.Linux(:powerpc64le, :glibc) => ("$bin_prefix/Gumbo.powerpc64le-linux-gnu.tar.gz", "7b7862ee7d0192dd139e75342c00993cb78c9b5b1237bf0d20a42fde855fcaf0"),
    BinaryProvider.MacOS() => ("$bin_prefix/Gumbo.x86_64-apple-darwin14.tar.gz", "717b52a0361a70e7f7637ad5cbc970f8c3648777cf382e609631319adef6abc0"),
    BinaryProvider.Linux(:x86_64, :glibc) => ("$bin_prefix/Gumbo.x86_64-linux-gnu.tar.gz", "6cf72df5dbbea1de1e0b777c70f88b9ac41a0ef728a22940aed3b910713d3ccc"),
    BinaryProvider.Windows(:x86_64) => ("$bin_prefix/Gumbo.x86_64-w64-mingw32.tar.gz", "7a2994a966ae4a408c34df408a9721760836e0115839dc42e6c3b140f9b509a8"),
)
# First, check to see if we're all satisfied
if any(!satisfied(p; verbose=verbose) for p in products)
    if haskey(download_info, platform_key())
        # Download and install binaries
        url, tarball_hash = download_info[platform_key()]
        install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
    else
        # If we don't have a BinaryProvider-compatible .tar.gz to download, complain.
        # Alternatively, you could attempt to install from a separate provider,
        # build from source or something more even more ambitious here.
        error("Your platform $(Sys.MACHINE) is not supported by this package!")
    end
end
# Write out a deps.jl file that will contain mappings for our products
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)

