Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New code

  • Loading branch information...
commit c66584ed6bc30cf0d27da6d67bead0b4b62cd337 1 parent 4229d21
@felixge authored
Showing with 192 additions and 0 deletions.
  1. +22 −0 env.sh
  2. +10 −0 lib.mk
  3. +160 −0 lib.sh
View
22 env.sh
@@ -0,0 +1,22 @@
+# The directory depmake is installed in
+export DM_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+# The parent directory, which should have a 'packets' and 'build' dir, private
+DM_DEPS_DIR="$( dirname ${DM_DIR} )"
+# The directory containing the packet install bash scripts
+export DM_PACKETS_DIR="${DM_DEPS_DIR}/packets"
+# The directory where we build / install our packets
+export DM_BUILD_DIR="${DM_DEPS_DIR}/build"
+# The directory where the stack will be linked into
+export DM_STACK_DIR="${DM_ROOT_DIR}/stack"
+# The number of cpu cores on this machine
+export DM_CPU_CORES=`nproc`
+
+# The $PATH before it was manipulated by depmake
+export DM_ORIGINAL_PATH=${DM_ORIGINAL_PATH:-$PATH}
+# Add our stack/bin dir to the $PATH
+export PATH="${DM_STACK_DIR}/bin:${DM_STACK_DIR}/sbin:${DM_ORIGINAL_PATH}"
+# Set other paths that impact builds and shared library loading
+export LD_LIBRARY_PATH="${DM_STACK_DIR}/lib"
+export CPPFLAGS="-I${DM_STACK_DIR}/include"
+export LDFLAGS="-L${DM_STACK_DIR}/lib"
+export PKG_CONFIG_PATH="${DM_STACK_DIR}/lib/pkgconfig"
View
10 lib.mk
@@ -0,0 +1,10 @@
+SHELL := /bin/bash
+
+define dm_packets
+PACKETS := $(basename $(notdir $(wildcard $(DM_PACKETS_DIR)/*.sh)))
+ALL: $$(PACKETS)
+$$(PACKETS):
+ @source $(DM_DIR)/lib.sh && dm_build $$@ $$^
+
+.PHONY: ALL $$(PACKETS)
+endef
View
160 lib.sh
@@ -0,0 +1,160 @@
+#!/bin/bash
+
+# Stop on errors or when encountering unset variables being references
+set -eu
+
+# Conventions:
+#
+# * private methods start with '_dm_' ('dm' stands for depmake)
+# * public functions start with 'dm_'
+
+
+###################
+# Private methods #
+###################
+
+_dm_packet_file() {
+ local packet=${1}
+ echo ${DM_PACKETS_DIR}/${packet}.sh
+}
+
+_dm_build_dir() {
+ local packet=${1}
+ echo ${DM_BUILD_DIR}/${packet}
+}
+
+_dm_sha1() {
+ openssl sha1 ${1} | cut -d ' ' -f 2
+}
+
+_dm_verify_sha1() {
+ local path=${1}
+ local expected_sha1=${2}
+
+ if [[ ! -f "${path}" ]]; then
+ echo "Error: cannot verify sha1 for non-existing file: ${path}"
+ return 1
+ fi
+
+ local actual_sha1=`_dm_sha1 ${path}`
+
+ if [ "${actual_sha1}" != "${expected_sha1}" ]; then
+ echo "Error: expected sha1: ${expected_sha1}, but got: ${actual_sha1} for ${path}"
+ return 1
+ fi
+}
+
+_dm_verify_fingerprint() {
+ local packet=${1}
+ local deps=${@:2}
+
+ expected_fingerprint=`_dm_calculate_fingerprint ${packet} ${deps}`
+ actual_fingerprint=`_dm_read_fingerprint ${packet}`
+
+ if [ "${actual_fingerprint}" != "${expected_fingerprint}" ]; then
+ return 1
+ fi
+}
+
+_dm_calculate_fingerprint() {
+ local packet=${1}
+ local deps=${@:2}
+ local packet_file=`_dm_packet_file ${packet}`
+ local fingerprint="${packet}-`_dm_sha1 ${packet_file}`"
+
+ for dep in ${deps[@]}
+ do
+ local dep_fingerprint=`_dm_read_fingerprint ${dep}`
+ fingerprint="${fingerprint}:${dep_fingerprint}"
+ done
+
+ echo ${fingerprint}
+}
+
+_dm_read_fingerprint() {
+ local packet=${1}
+ cat `_dm_fingerprint_path ${packet}`
+}
+
+_dm_fingerprint_path() {
+ local packet=${1}
+ echo "`_dm_build_dir ${packet}`/build.fingerprint"
+}
+
+_dm_write_fingerprint() {
+ local packet=${1}
+ local deps=${@:2}
+
+ local fingerprint_path=`_dm_fingerprint_path ${packet}`
+ local fingerprint=`_dm_calculate_fingerprint ${packet} ${deps}`
+
+ echo ${fingerprint} > ${fingerprint_path}
+}
+
+##################
+# Public methods #
+##################
+dm_build() {
+ local packet=${1}
+ local deps=${@:2}
+
+ local packet_file=`_dm_packet_file ${packet}`
+ local build_dir=`_dm_build_dir ${packet}`
+
+ source ${packet_file}
+
+ echo "========== Building ${packet} =========="
+
+ if _dm_verify_fingerprint ${packet} ${deps}; then
+ echo "Not rebuilding, fingerprint is current."
+ else
+ mkdir -p ${build_dir}
+ cd ${build_dir}
+ time build ${DM_STACK_DIR}
+ _dm_write_fingerprint ${packet} ${deps}
+ fi
+}
+
+dm_download_file() {
+ local filename=${1}
+ local url=${2}
+ local sha1=${3}
+
+ if _dm_verify_sha1 ${filename} ${sha1}; then
+ echo "Sha1 for ${filename} matches, no need to re-download"
+ return 0
+ fi
+
+ echo "Downloading ${filename} from ${url} ..."
+ curl --fail -L -o ${filename} ${url}
+
+ _dm_verify_sha1 ${filename} ${sha1}
+}
+
+dm_download_git() {
+ local repo=${1}
+ local ref=${2}
+ local clone_dir=${3}
+
+ code=`cd ${clone_dir} && git reset ${ref} -q --hard; echo $?`
+ if [ ${code} -eq 0 ]; then
+ return 0
+ fi
+
+ code=`cd ${clone_dir} && git fetch && git reset ${ref} -q --hard; echo $?`
+ if [ ${code} -eq 0 ]; then
+ return 0
+ fi
+
+ rm -rf ${clone_dir}
+ git clone ${repo} ${clone_dir}
+ ( cd ${clone_dir} && git reset ${ref} -q --hard )
+}
+
+dm_download_svn() {
+ local repo=${1}
+ local ref=${2}
+ local checkout_dir=${3}
+
+ svn checkout -r ${ref} ${repo} ${checkout_dir}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.