aboutsummaryrefslogtreecommitdiff
path: root/tools/depends
diff options
context:
space:
mode:
authorwsnipex <wsnipex@a1.net>2022-01-22 08:42:03 +0100
committerwsnipex <wsnipex@a1.net>2022-02-07 06:24:58 +0100
commit51de0c6ca714396b98df466698f870c3afd77e04 (patch)
tree67d225dcb2368f3b1767ac0e6ae3590d4808fb46 /tools/depends
parentca78545b83ad98f481b77b7c15398c4c62e1f292 (diff)
[depends] add helper for tarball download and hash sum verification
Diffstat (limited to 'tools/depends')
-rw-r--r--tools/depends/Makefile.include.in5
-rw-r--r--tools/depends/configure.ac18
-rw-r--r--tools/depends/download-files.include39
3 files changed, 61 insertions, 1 deletions
diff --git a/tools/depends/Makefile.include.in b/tools/depends/Makefile.include.in
index 14bd871d52..e53404c3e3 100644
--- a/tools/depends/Makefile.include.in
+++ b/tools/depends/Makefile.include.in
@@ -30,6 +30,10 @@ AAPT=@AAPT@
DX=@DX@
D8=@D8@
ZIPALIGN=@ZIPALIGN@
+SHA512SUM=@SHA512SUM@
+SHA256SUM=@SHA256SUM@
+SHASUM=@SHASUM@
+HASH_TOOL_FLAGS=-c --status
HAS_ZLIB=@has_zlib@
NEED_LIBICONV=@need_libiconv@
@@ -124,4 +128,3 @@ export LIBTOOLIZE=@prefix@/@tool_dir@/bin/libtoolize
export AUTORECONF=@prefix@/@tool_dir@/bin/autoreconf
export JSON_BUILDER=$(NATIVEPREFIX)/bin/JsonSchemaBuilder
-
diff --git a/tools/depends/configure.ac b/tools/depends/configure.ac
index 341fe395de..734cf843c4 100644
--- a/tools/depends/configure.ac
+++ b/tools/depends/configure.ac
@@ -197,6 +197,24 @@ case $build in
AC_MSG_ERROR(unsupported native build platform: $build)
esac
+
+if test "x$build_os" = "xosx"; then
+ AC_PATH_PROG(SHASUM,shasum,"no")
+ if test "x$SHASUM" = "xno" ; then
+ AC_MSG_ERROR("Missing program: shasum")
+ fi
+else
+ AC_PATH_PROG(SHA512SUM,sha512sum,"no")
+ if test "x$SHA512SUM" = "xno" ; then
+ AC_MSG_ERROR("Missing program: sha512sum")
+ fi
+
+ AC_PATH_PROG(SHA256SUM,sha256sum,"no")
+ if test "x$SHA256SUM" = "xno" ; then
+ AC_MSG_ERROR("Missing program: sha256sum")
+ fi
+fi
+
if test -n $use_build_toolchain; then
PATH_FOR_BUILD=$use_build_toolchain:$use_build_toolchain/usr/bin:$use_toolchain/bin:$PATH
else
diff --git a/tools/depends/download-files.include b/tools/depends/download-files.include
new file mode 100644
index 0000000000..de5bf438bb
--- /dev/null
+++ b/tools/depends/download-files.include
@@ -0,0 +1,39 @@
+#
+HASH_FOUND = yes
+ifneq ($(SHA512),)
+ HASH_TYPE = sha512
+ HASH_TOOL ?= $(SHA512SUM)
+else ifneq ($(SHA256),)
+ HASH_TYPE = sha256
+ HASH_TOOL ?= $(SHA256SUM)
+else
+ HASH_FOUND = no
+ HASH_TYPE = sha512
+ HASH_TOOL = sha512sum
+endif
+
+SED_FLAG = -i
+ifeq ($(NATIVE_OS), osx)
+ HASH_TOOL = $(SHASUM) -a $(shell echo $(HASH_TYPE) | sed 's/^sha//')
+ SED_FLAG = -i ''
+endif
+
+HASH_SUM = $($(shell echo $(HASH_TYPE) | tr '[:lower:]' '[:upper:]'))
+
+.PHONY: $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE)
+all: $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE)
+
+$(TARBALLS_LOCATION)/$(ARCHIVE):
+ cd $(TARBALLS_LOCATION); $(RETRIEVE_TOOL) $(RETRIEVE_TOOL_FLAGS) $(BASE_URL)/$(ARCHIVE)
+
+$(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE): $(TARBALLS_LOCATION)/$(ARCHIVE)
+ifeq ($(HASH_FOUND),no)
+ cd $(TARBALLS_LOCATION); $(HASH_TOOL) $(ARCHIVE) > $(ARCHIVE).$(HASH_TYPE)
+ $(HASH_TYPE)=$$(cat $(TARBALLS_LOCATION)/$(ARCHIVE).$(HASH_TYPE) | cut -d ' ' -f 1) && \
+ sed $(SED_FLAG) -e "s/#SHA512#/SHA512=$${sha512}/" -e "s/#SHA256#/SHA256=$${sha256}/" Makefile
+endif
+ifeq ($(HASH_FOUND),yes)
+# we really need 2 spaces between sha hash and file name!
+ @cd $(TARBALLS_LOCATION); echo "$(HASH_SUM) $(ARCHIVE)" > $(ARCHIVE).$(HASH_TYPE) && $(HASH_TOOL) $(HASH_TOOL_FLAGS) $(ARCHIVE).$(HASH_TYPE) \
+ || { echo "Error: failed to verify hash sum of $(ARCHIVE), expected type: $(HASH_TYPE) value $(HASH_SUM)"; exit 3; }
+endif