Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
build: added new support files to help with handling static lib builds
This will include potential to fetch cached builds and to post builds (if BINTRAY_PASS is set in the environment).
- Loading branch information
1 parent
a46818c
commit 408d7d0
Showing
2 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # | ||
| # Copyright (C) 2008-2014 Tvheadend Foundation CIC | ||
| # | ||
| # This file is part of Tvheadend | ||
| # | ||
| # Tvheadend is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Tvheadend is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with Tvheadend. If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
| # For more details, including opportunities for alternative licensing, | ||
| # please read the LICENSE file. | ||
| # | ||
| # ############################################################################ | ||
|
|
||
| # ############################################################################ | ||
| # Generic makefile for handling static 3rd party libraries | ||
| # ############################################################################ | ||
|
|
||
| # | ||
| # Required inputs | ||
| # | ||
| # LIB_NAME - The name of the library used in files uploaded/downloaded | ||
| # LIB_FILES - The files to be packaged | ||
| # | ||
| # Optional inputs | ||
| # | ||
| # BINTRAY_USER - The bintray user account for uploads | ||
| # BINTRAY_PASS - The bintray password | ||
| # BINTRAY_REPO - The repo to upload to | ||
| # | ||
|
|
||
| MAKEFILE ?= $(firstword $(MAKEFILE_LIST)) | ||
|
|
||
| default: liball | ||
|
|
||
| # Setup environment for scripts | ||
| export ARCH | ||
| export CODENAME | ||
| export ROOTDIR | ||
| export BUILDDIR | ||
| export LIBDIR | ||
| export BINTRAY_USER | ||
| export BINTRAY_PASS | ||
| export BINTRAY_REPO | ||
|
|
||
| # Download cache | ||
| .PHONY: libcacheget | ||
| libcacheget: | ||
| @($(ROOTDIR)/support/lib.sh download $(LIB_NAME) &&\ | ||
| $(ROOTDIR)/support/lib.sh unpack $(LIB_NAME) ) || true | ||
|
|
||
| # Upload | ||
| .PHONY: libcacheput | ||
| libcacheput: build | ||
| @$(ROOTDIR)/support/lib.sh upload $(LIB_NAME) $(LIB_FILES) | ||
|
|
||
| # Do it all | ||
| .PHONY: liball | ||
| liball: libcacheget libcacheput | ||
|
|
||
| # ############################################################################ | ||
| # Helper routines | ||
| # ############################################################################ | ||
|
|
||
| define DOWNLOAD | ||
| @mkdir -p $(LIB_ROOT)/build | ||
| @if test -z "$${TVHEADEND_FILE_CACHE}"; then \ | ||
| printf "WGET $(1)\n"; \ | ||
| wget --no-verbose -O $(2) $(1); \ | ||
| else \ | ||
| file=$$(basename $(2)); \ | ||
| cp "$$TVHEADEND_FILE_CACHE/$$(file)" $(2); \ | ||
| fi | ||
| @{ \ | ||
| sum=$$(sha1sum $(2) | cut -d ' ' -f 1); \ | ||
| printf "SHA1SUM test '$${sum}' == '$(3)': "; \ | ||
| test "y$${sum}" = "y$(3)"; \ | ||
| } | ||
| @echo "OK" | ||
| endef | ||
|
|
||
| define UNTAR | ||
| @{ \ | ||
| printf "UNTAR $(1)\n"; \ | ||
| tar x -C $(LIB_ROOT) -$(2)f $(LIB_ROOT)/$(1); \ | ||
| } | ||
| endef | ||
|
|
||
| # ############################################################################ | ||
| # Editor Configuration | ||
| # | ||
| # vim:sts=2:ts=2:sw=2:et! | ||
| # ############################################################################ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Copyright (C) 2008-2014 Tvheadend Foundation CIC | ||
| # | ||
| # This file is part of Tvheadend | ||
| # | ||
| # Tvheadend is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Tvheadend is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with Tvheadend. If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
| # For more details, including opportunities for alternative licensing, | ||
| # please read the LICENSE file. | ||
| # | ||
| # ############################################################################ | ||
|
|
||
| # ############################################################################ | ||
| # 3rd Party library processing support | ||
| # | ||
| # Provides support routine for the management of 3rd party libraries for | ||
| # which we include our own static build to simplify integration. | ||
| # ############################################################################ | ||
|
|
||
| #set -x | ||
|
|
||
| # ############################################################################ | ||
| # Config | ||
| # ############################################################################ | ||
|
|
||
| [ -z "$BINTRAY_REPO" ] && BINTRAY_REPO=tvheadend/misc | ||
| [ -z "$ARCH" ] && ARCH=$(uname -m) | ||
| if [ -z "$CODENAME" ]; then | ||
| if [ -f /etc/lsb-release ]; then | ||
| . /etc/lsb-release | ||
| CODENAME=${DISTRIB_CODENAME} | ||
| fi | ||
| # TODO: support more than debian | ||
| fi | ||
|
|
||
| # ############################################################################ | ||
| # Config | ||
| # ############################################################################ | ||
|
|
||
|
|
||
| # ############################################################################ | ||
| # Functions | ||
| # ############################################################################ | ||
|
|
||
| function hash () | ||
| { | ||
| LIB_NAME=$1 | ||
| T=" | ||
| $(cat ${ROOTDIR}/Makefile.${LIB_NAME}) | ||
| $(grep ^CONFIG_ ${ROOTDIR}/.config.mk) | ||
| " | ||
| H=$(echo ${T} | sha1sum | cut -d' ' -f1) | ||
| echo ${H} | ||
| } | ||
|
|
||
| # | ||
| # Attempt to download | ||
| # | ||
| function download | ||
| { | ||
| LIB_NAME=$1 | ||
| LIB_HASH=$(hash ${LIB_NAME}) | ||
| P=${BUILDDIR}/.${LIB_NAME}-${LIB_HASH}.tgz | ||
|
|
||
| # Cleanup | ||
| rm -f ${BUILDDIR}/.${LIB_NAME}*.tmp | ||
|
|
||
| # Already downloaded | ||
| [ -f ${P} ] && return 0 | ||
|
|
||
| # Create directory | ||
| [ ! -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR} | ||
|
|
||
| # Attempt to fetch | ||
| N=staticlib/${CODENAME}/${ARCH}/${LIB_NAME}-${LIB_HASH}.tgz | ||
| URL="https://dl.bintray.com/${BINTRAY_REPO}/${N}" | ||
| echo "DOWNLOAD ${URL}" | ||
| wget -O ${P}.tmp "${URL}" | ||
| R=$? | ||
| # Don't know why but having weird issue with curl not returning data | ||
|
|
||
| # Failed | ||
| if [ ${R} -ne 0 ]; then | ||
| rm -f ${P}.tmp | ||
| return ${R} | ||
| fi | ||
|
|
||
| # Move tmp file | ||
| mv ${P}.tmp ${P} | ||
|
|
||
| return ${R} | ||
| } | ||
|
|
||
| # | ||
| # Unpack tarball | ||
| # | ||
| function unpack | ||
| { | ||
| LIB_NAME=$1 | ||
| LIB_HASH=$(hash ${LIB_NAME}) | ||
| P=${BUILDDIR}/.${LIB_NAME}-${LIB_HASH}.tgz | ||
| U=${BUILDDIR}/.${LIB_NAME}.unpack | ||
|
|
||
| # Not downloaded | ||
| [ ! -f ${P} ] && return 1 | ||
|
|
||
| # Already unpacked? | ||
| if [ -f ${U} ]; then | ||
| H=$(cat ${U}) | ||
| [ "${LIB_HASH}" = ${H} ] && return 0 | ||
| fi | ||
|
|
||
| # Cleanup | ||
| rm -rf ${BUILDDIR}/${LIB_NAME} | ||
| mkdir -p ${BUILDDIR}/${LIB_NAME} | ||
|
|
||
| # Unpack | ||
| echo "UNPACK ${P}" | ||
| tar -C ${BUILDDIR}/${LIB_NAME} -xf ${P} | ||
|
|
||
| # Record | ||
| echo ${LIB_HASH} > ${U} | ||
| } | ||
|
|
||
| # | ||
| # Upload | ||
| # | ||
| function upload | ||
| { | ||
| LIB_NAME=$1; shift | ||
| LIB_FILES=$* | ||
| LIB_HASH=$(hash ${LIB_NAME}) | ||
| P=${BUILDDIR}/.${LIB_NAME}-${LIB_HASH}.tgz | ||
|
|
||
| # Can't upload | ||
| [ -z "${BINTRAY_USER}" -o -z "${BINTRAY_PASS}" ] && return 0 | ||
|
|
||
| # Don't need to upload | ||
| [ -f "${P}" ] && return 0 | ||
|
|
||
| # Make relative paths | ||
| LIB_FILES=$(echo "${LIB_FILES}" | sed "s#${BUILDDIR}/${LIB_NAME}/##g") | ||
|
|
||
| # Build temporary file | ||
| echo "PACK ${P} [${LIB_FILES}]" | ||
| tar -C ${BUILDDIR}/${LIB_NAME} -zcf ${P}.tmp ${LIB_FILES} | ||
|
|
||
| # Upload | ||
| N=staticlib/${CODENAME}/${ARCH}/${LIB_NAME}-${LIB_HASH}.tgz | ||
| URL="https://api.bintray.com/content/${BINTRAY_REPO}/staticlib/${LIB_NAME}-${LIB_HASH}/${N};publish=1" | ||
| echo "UPLOAD ${URL}" | ||
| curl -s -T ${P}.tmp -u${BINTRAY_USER}:${BINTRAY_PASS} "${URL}" || return 1 | ||
|
|
||
| # Done | ||
| mv ${P}.tmp ${P} | ||
| } | ||
|
|
||
| # Run command | ||
| C=$1; shift | ||
| case "${C}" in | ||
| hash) | ||
| hash $* | ||
| ;; | ||
| download) | ||
| download $* | ||
| ;; | ||
| unpack) | ||
| unpack $* | ||
| ;; | ||
| upload) | ||
| upload $* | ||
| ;; | ||
| esac | ||
|
|
||
| # ############################################################################ | ||
| # Editor Configuration | ||
| # | ||
| # vim:sts=2:ts=2:sw=2:et | ||
| # ############################################################################ |