blob: 822a64698cfafda4698d082192e13ca26d817ef0 [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.
Jan Wassenberg1f9967a2021-06-09 11:49:33 +020016THIRD_PARTY_HIGHWAY="e2397743fe092df68b760d358253773699a16c93"
Ziemowit Zabawa6a3f0ce2021-10-06 17:28:44 +020017THIRD_PARTY_LODEPNG="8c6a9e30576f07bf470ad6f09458a2dcd7a6a84a"
jpegxl-botd5ab3c62020-11-14 01:52:03 +010018THIRD_PARTY_SKCMS="64374756e03700d649f897dbd98c95e78c30c7da"
19THIRD_PARTY_SJPEG="868ab558fad70fcbe8863ba4e85179eeb81cc840"
20
21# Download the target revision from GitHub.
22download_github() {
23 local path="$1"
24 local project="$2"
25
26 local varname="${path^^}"
27 varname="${varname/\//_}"
28 local sha
29 eval "sha=\${${varname}}"
30
31 local down_dir="${MYDIR}/downloads"
32 local local_fn="${down_dir}/${sha}.tar.gz"
33 if [[ -e "${local_fn}" && -d "${MYDIR}/${path}" ]]; then
34 echo "${path} already up to date." >&2
35 return 0
36 fi
37
38 local url
39 local strip_components=0
40 if [[ "${project:0:4}" == "http" ]]; then
41 # "project" is a googlesource.com base url.
42 url="${project}${sha}.tar.gz"
43 else
44 # GitHub files have a top-level directory
45 strip_components=1
46 url="https://github.com/${project}/tarball/${sha}"
47 fi
48
49 echo "Downloading ${path} version ${sha}..." >&2
50 mkdir -p "${down_dir}"
51 curl -L --show-error -o "${local_fn}.tmp" "${url}"
52 mkdir -p "${MYDIR}/${path}"
53 tar -zxf "${local_fn}.tmp" -C "${MYDIR}/${path}" \
54 --strip-components="${strip_components}"
55 mv "${local_fn}.tmp" "${local_fn}"
56}
57
58
59main() {
60 if git -C "${MYDIR}" rev-parse; then
61 cat >&2 <<EOF
Ziemowit Zabawa27d8a0f2021-07-01 16:45:13 +020062Current directory is a git repository, downloading dependencies via git:
jpegxl-botd5ab3c62020-11-14 01:52:03 +010063
64 git submodule update --init --recursive
65
66EOF
67 git -C "${MYDIR}" submodule update --init --recursive
68 return 0
69 fi
70
71 # Sources downloaded from a tarball.
jpegxl-botd5ab3c62020-11-14 01:52:03 +010072 download_github third_party/highway google/highway
73 download_github third_party/lodepng lvandeve/lodepng
74 download_github third_party/sjpeg webmproject/sjpeg
75 download_github third_party/skcms \
76 "https://skia.googlesource.com/skcms/+archive/"
77 echo "Done."
78}
79
80main "$@"