blob: cdd82b247fb20c96a22a74b5081d4c4cfadcacb7 [file] [log] [blame]
jpegxl-botd5ab3c62020-11-14 01:52:03 +01001#!/usr/bin/env bash
2# Copyright (c) the JPEG XL Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This file downloads the dependencies needed to build JPEG XL into third_party.
17# These dependencies are normally pulled by gtest.
18
19set -eu
20
21MYDIR=$(dirname $(realpath "$0"))
22
23# Git revisions we use for the given submodules. Update these whenever you
jpegxl-bot945ad0c2021-01-21 20:27:02 +010024# update a git submodule.
jpegxl-botb1c6fdc2021-03-05 18:32:15 +010025THIRD_PARTY_HIGHWAY="946a1b40233438a1b0363598a6deaa1628a01003"
jpegxl-botd5ab3c62020-11-14 01:52:03 +010026THIRD_PARTY_LODEPNG="48e5364ef48ec2408f44c727657ac1b6703185f8"
27THIRD_PARTY_SKCMS="64374756e03700d649f897dbd98c95e78c30c7da"
28THIRD_PARTY_SJPEG="868ab558fad70fcbe8863ba4e85179eeb81cc840"
29
30# Download the target revision from GitHub.
31download_github() {
32 local path="$1"
33 local project="$2"
34
35 local varname="${path^^}"
36 varname="${varname/\//_}"
37 local sha
38 eval "sha=\${${varname}}"
39
40 local down_dir="${MYDIR}/downloads"
41 local local_fn="${down_dir}/${sha}.tar.gz"
42 if [[ -e "${local_fn}" && -d "${MYDIR}/${path}" ]]; then
43 echo "${path} already up to date." >&2
44 return 0
45 fi
46
47 local url
48 local strip_components=0
49 if [[ "${project:0:4}" == "http" ]]; then
50 # "project" is a googlesource.com base url.
51 url="${project}${sha}.tar.gz"
52 else
53 # GitHub files have a top-level directory
54 strip_components=1
55 url="https://github.com/${project}/tarball/${sha}"
56 fi
57
58 echo "Downloading ${path} version ${sha}..." >&2
59 mkdir -p "${down_dir}"
60 curl -L --show-error -o "${local_fn}.tmp" "${url}"
61 mkdir -p "${MYDIR}/${path}"
62 tar -zxf "${local_fn}.tmp" -C "${MYDIR}/${path}" \
63 --strip-components="${strip_components}"
64 mv "${local_fn}.tmp" "${local_fn}"
65}
66
67
68main() {
69 if git -C "${MYDIR}" rev-parse; then
70 cat >&2 <<EOF
71Currenty directory is a git repository, downloading dependencies via git:
72
73 git submodule update --init --recursive
74
75EOF
76 git -C "${MYDIR}" submodule update --init --recursive
77 return 0
78 fi
79
80 # Sources downloaded from a tarball.
jpegxl-botd5ab3c62020-11-14 01:52:03 +010081 download_github third_party/highway google/highway
82 download_github third_party/lodepng lvandeve/lodepng
83 download_github third_party/sjpeg webmproject/sjpeg
84 download_github third_party/skcms \
85 "https://skia.googlesource.com/skcms/+archive/"
86 echo "Done."
87}
88
89main "$@"