From 6e01f3179880704f38552c398c25b0509f58394a Mon Sep 17 00:00:00 2001
From: Travis Cross <tc@traviscross.com>
Date: Sat, 5 May 2012 20:59:09 +0000
Subject: [PATCH] debian: add a utility to output build dependencies for
 aptitude

---
 debian/util.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/debian/util.sh b/debian/util.sh
index 3b45ec391f..6deed193e9 100755
--- a/debian/util.sh
+++ b/debian/util.sh
@@ -2,6 +2,20 @@
 ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
 ##### Author: Travis Cross <tc@traviscross.com>
 
+err () {
+  echo "$0 error: $1" >&2
+  exit 1
+}
+
+xread () {
+  local xIFS="$IFS"
+  IFS=''
+  read $@
+  local ret=$?
+  IFS="$xIFS"
+  return $ret
+}
+
 create_dbg_pkgs () {
   for x in debian/*; do
     test ! -d $x && continue
@@ -13,9 +27,37 @@ create_dbg_pkgs () {
   done
 }
 
+list_build_depends () {
+  test -f debian/.stamp-bootstrap || (cd debian && ./bootstrap.sh)
+  local deps="" found=false
+  while xread l; do
+    if [ "${l%%:*}" = "Build-Depends" ]; then
+      deps="${l#*:}"
+      found=true
+      continue
+    elif $found; then
+      if [ -z "$l" ]; then
+        # is newline
+        break
+      elif [ -z "${l##\#*}" ]; then
+        # is comment
+        continue
+      elif [ -z "${l## *}" ]; then
+        # is continuation line
+        deps="$deps $(echo "$l" | sed -e 's/^ *//' -e 's/ *([^)]*)//g' -e 's/,//g')"
+      else
+        # is a new header
+        break
+      fi
+    fi
+  done < debian/control
+  echo "${deps# }"
+}
+
 cmd="$1"
 shift
 case "$cmd" in
   create-dbg-pkgs) create_dbg_pkgs ;;
+  list-build-depends) list_build_depends ;;
 esac