From c049d1c3b267c6a139807885cbdd126ae2ba1d63 Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Tue, 15 Aug 2017 15:15:58 -0500
Subject: [PATCH] configure: Check cache for valid pjproject tarball before
 downloading.

On a fresh Asterisk source directory, the bundled pjproject tarball is
unconditionally downloaded even if the tarball is already in a specified
cache directory.

* Made check if the pjproject tarball is valid in the cache directory
before downloading the tarball on a fresh source directory.

Change-Id: Ic7ec842d3c97ecd8dafbad6f056b7fdbce41cae5
---
 third-party/pjproject/Makefile | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile
index a5b5508425..7a42edcde2 100644
--- a/third-party/pjproject/Makefile
+++ b/third-party/pjproject/Makefile
@@ -86,6 +86,11 @@ SHELL_ECHO_PREFIX := echo '[pjproject] '
 
 _all: $(TARGETS)
 
+define tarball_exists
+	(if [ -f $(TARBALL) -a -f $(PJMD5SUM) ] ; then exit 0 ;\
+	else exit 1; fi; )
+endef
+
 define verify_tarball
 	($(SHELL_ECHO_PREFIX) Verifying $(TARBALL) &&\
 	tarball_sum=$$($(CAT) $(TARBALL) | $(MD5) | $(SED) -n -r -e "s/^([^ ]+)\s+.*/\1/gp") ;\
@@ -111,11 +116,12 @@ TARBALL_URL = $(PJPROJECT_URL)/$(TARBALL_FILE)
 PJMD5SUM = $(patsubst %.tar.bz2,%.md5,$(TARBALL))
 
 $(TARBALL): ../versions.mak
-	$(CMD_PREFIX) $(download_from_pjproject) || (rm -rf $@ ;\
+	$(CMD_PREFIX) ($(tarball_exists) && $(verify_tarball) && touch $@) || (rm -rf $@ ;\
+	$(download_from_pjproject)) || (rm -rf $@ ;\
 	$(SHELL_ECHO_PREFIX) Retrying download ; $(download_from_pjproject))
 
 source/.unpacked: $(DOWNLOAD_DIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
-	($(verify_tarball)) || (rm -rf $@ ;\
+	$(CMD_PREFIX) $(verify_tarball) || (rm -rf $@ ;\
 	$(SHELL_ECHO_PREFIX) Retrying download ; $(download_from_pjproject))
 	$(ECHO_PREFIX) Unpacking $<
 	-@rm -rf source pjproject-* >/dev/null 2>&1
-- 
GitLab