From 51de0c6ca714396b98df466698f870c3afd77e04 Mon Sep 17 00:00:00 2001 From: wsnipex Date: Sat, 22 Jan 2022 08:42:03 +0100 Subject: [depends] add helper for tarball download and hash sum verification --- tools/depends/Makefile.include.in | 5 ++++- tools/depends/configure.ac | 18 +++++++++++++++++ tools/depends/download-files.include | 39 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tools/depends/download-files.include (limited to 'tools/depends') 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 -- cgit v1.2.3