blob: 9aaabba2e03a492066ef44a283bd42b88d92d85d [file] [log] [blame]
jpegxl-botd5ab3c62020-11-14 01:52:03 +01001#!/usr/bin/env bash
jpegxl-botbdde6442021-05-25 19:02:18 +02002# Copyright (c) the JPEG XL Project Authors. All rights reserved.
jpegxl-botd5ab3c62020-11-14 01:52:03 +01003#
jpegxl-botbdde6442021-05-25 19:02:18 +02004# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
jpegxl-botd5ab3c62020-11-14 01:52:03 +01006
7# This file downloads the dependencies needed to build JPEG XL into third_party.
8# These dependencies are normally pulled by gtest.
9
10set -eu
11
12MYDIR=$(dirname $(realpath "$0"))
13
14# Git revisions we use for the given submodules. Update these whenever you
jpegxl-bot945ad0c2021-01-21 20:27:02 +010015# update a git submodule.
Stephan T. Lavavejb219fd52022-03-31 06:49:07 -070016THIRD_PARTY_BROTLI="35ef5c554d888bef217d449346067de05e269b30"
Moritz Firschinga4d26322022-08-25 15:19:31 +020017THIRD_PARTY_HIGHWAY="22e3d7276f4157d4a47586ba9fd91dd6303f441a"
jpegxl-botd5ab3c62020-11-14 01:52:03 +010018THIRD_PARTY_SKCMS="64374756e03700d649f897dbd98c95e78c30c7da"
19THIRD_PARTY_SJPEG="868ab558fad70fcbe8863ba4e85179eeb81cc840"
Sami Boukorttf3fc83b2021-12-10 12:25:19 +010020THIRD_PARTY_ZLIB="cacf7f1d4e3d44d871b605da3b647f07d718623f"
21THIRD_PARTY_LIBPNG="a40189cf881e9f0db80511c382292a5604c3c3d1"
jpegxl-botd5ab3c62020-11-14 01:52:03 +010022
23# Download the target revision from GitHub.
24download_github() {
25 local path="$1"
26 local project="$2"
27
Evgenii Kliuchnikov28e3d062021-11-22 10:05:47 +000028 local varname=`echo "$path" | tr '[:lower:]' '[:upper:]'`
jpegxl-botd5ab3c62020-11-14 01:52:03 +010029 varname="${varname/\//_}"
30 local sha
31 eval "sha=\${${varname}}"
32
33 local down_dir="${MYDIR}/downloads"
34 local local_fn="${down_dir}/${sha}.tar.gz"
35 if [[ -e "${local_fn}" && -d "${MYDIR}/${path}" ]]; then
36 echo "${path} already up to date." >&2
37 return 0
38 fi
39
40 local url
41 local strip_components=0
42 if [[ "${project:0:4}" == "http" ]]; then
43 # "project" is a googlesource.com base url.
44 url="${project}${sha}.tar.gz"
45 else
46 # GitHub files have a top-level directory
47 strip_components=1
48 url="https://github.com/${project}/tarball/${sha}"
49 fi
50
51 echo "Downloading ${path} version ${sha}..." >&2
52 mkdir -p "${down_dir}"
53 curl -L --show-error -o "${local_fn}.tmp" "${url}"
54 mkdir -p "${MYDIR}/${path}"
55 tar -zxf "${local_fn}.tmp" -C "${MYDIR}/${path}" \
56 --strip-components="${strip_components}"
57 mv "${local_fn}.tmp" "${local_fn}"
58}
59
60
61main() {
62 if git -C "${MYDIR}" rev-parse; then
63 cat >&2 <<EOF
Ziemowit Zabawa27d8a0f2021-07-01 16:45:13 +020064Current directory is a git repository, downloading dependencies via git:
jpegxl-botd5ab3c62020-11-14 01:52:03 +010065
66 git submodule update --init --recursive
67
68EOF
Leo Izend2b77142022-01-05 09:27:37 -050069 git -C "${MYDIR}" submodule update --init --recursive --depth 1 --recommend-shallow
jpegxl-botd5ab3c62020-11-14 01:52:03 +010070 return 0
71 fi
72
73 # Sources downloaded from a tarball.
Stephan T. Lavavejb219fd52022-03-31 06:49:07 -070074 download_github third_party/brotli google/brotli
jpegxl-botd5ab3c62020-11-14 01:52:03 +010075 download_github third_party/highway google/highway
jpegxl-botd5ab3c62020-11-14 01:52:03 +010076 download_github third_party/sjpeg webmproject/sjpeg
77 download_github third_party/skcms \
78 "https://skia.googlesource.com/skcms/+archive/"
Sami Boukorttf3fc83b2021-12-10 12:25:19 +010079 download_github third_party/zlib madler/zlib
80 download_github third_party/libpng glennrp/libpng
jpegxl-botd5ab3c62020-11-14 01:52:03 +010081 echo "Done."
82}
83
84main "$@"