From 0a50536aa837cd18a5744962e8ca49a22f71bc63 Mon Sep 17 00:00:00 2001
From: Travis Cross <tc@traviscross.com>
Date: Tue, 28 May 2013 21:58:36 +0000
Subject: [PATCH] Add generic mechanism for building non-DFSG packages

---
 debian/bootstrap.sh | 17 ++++++++++++++++-
 debian/util.sh      | 29 ++++++++++++++++++-----------
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh
index 602e30e81a..aa852937f3 100755
--- a/debian/bootstrap.sh
+++ b/debian/bootstrap.sh
@@ -1068,10 +1068,23 @@ genmodctl_mod () {
   echo
 }
 
+set_modules_non_dfsg () {
+  local len=${#avoid_mods}
+  for ((i=0; i<len; i++)); do
+    case "${avoid_mods[$i]}" in
+      codecs/mod_siren|codecs/mod_ilbc)
+        unset avoid_mods[$i]
+        ;;
+    esac
+  done
+}
+
 codename="sid"
-while getopts "c:" o; do
+modulelist_opt=""
+while getopts "c:m:" o; do
   case "$o" in
     c) codename="$OPTARG" ;;
+    m) modulelist_opt="$OPTARG" ;;
   esac
 done
 shift $(($OPTIND-1))
@@ -1080,6 +1093,8 @@ echo "Bootstrapping debian/ for ${codename}" >&2
 echo >&2
 echo "Please wait, this takes a few seconds..." >&2
 
+test -z "$modulelist_opt" || set_modules_${modulelist_opt/-/_}
+
 echo "Adding any new modules to control-modules..." >&2
 parse_dir=control-modules.parse
 map_fs_modules ':' 'genmodctl_new_cat' 'genmodctl_new_mod' >> control-modules
diff --git a/debian/util.sh b/debian/util.sh
index 55e58b0d28..7f53073830 100755
--- a/debian/util.sh
+++ b/debian/util.sh
@@ -153,10 +153,11 @@ create_orig () {
   {
     set -e
     local OPTIND OPTARG
-    local uver="" hrev="" bundle_deps=false zl=9e
-    while getopts 'bnv:z:' o "$@"; do
+    local uver="" hrev="" bundle_deps=false modules_list="" zl=9e
+    while getopts 'bm:nv:z:' o "$@"; do
       case "$o" in
         b) bundle_deps=true;;
+        m) modules_list="$OPTARG";;
         n) uver="nightly";;
         v) uver="$OPTARG";;
         z) zl="$OPTARG";;
@@ -173,9 +174,9 @@ create_orig () {
     check_repo_clean
     git reset --hard "$treeish"
     mv .gitattributes .gitattributes.orig
-    grep .gitattributes.orig \
-      -e '\bdebian-ignore\b' \
-      -e '\bdfsg-nonfree\b' \
+    local -a args=(-e '\bdebian-ignore\b')
+    test "$modules_list" = "non-dfsg" || args+=(-e '\bdfsg-nonfree\b')
+    grep .gitattributes.orig "${args[@]}" \
       | while xread l; do
       echo "$l export-ignore" >> .gitattributes
     done
@@ -226,10 +227,13 @@ create_dsc () {
     if [ -n "$modules_conf" ]; then
       cp $modules_conf debian/modules.conf
     fi
+    local bootstrap_args=""
     if [ -n "$modules_list" ]; then
-      set_modules_${modules_list}
+      if [ "$modules_list" = "non-dfsg" ]; then
+        bootstrap_args="-mnon-dfsg"
+      else set_modules_${modules_list}; fi
     fi
-    (cd debian && ./bootstrap.sh -c $distro)
+    (cd debian && ./bootstrap.sh -c $distro $bootstrap_args)
     case "$speed" in
       paranoid) sed -i ./debian/rules \
         -e '/\.stamp-bootstrap:/{:l2 n; /\.\/bootstrap.sh -j/{s/ -j//; :l3 n; b l3}; b l2};' ;;
@@ -238,7 +242,8 @@ create_dsc () {
     esac
     [ "$zl" -ge "1" ] || zl=1
     git add debian/rules
-    git rm -rf --ignore-unmatch libs/libg722_1 libs/ilbc
+    [ "$modules_list" = "non-dfsg" ] \
+      || git rm -rf --ignore-unmatch libs/libg722_1 libs/ilbc
     dch -b -m -v "$dver" --force-distribution -D "$suite" "Nightly build."
     git add debian/changelog && git commit -m "nightly v$orig_ver"
     dpkg-source -i.* -Zxz -z${zl} -b .
@@ -324,7 +329,7 @@ build_all () {
       d) deb_opts="$deb_opts -d";;
       f) dsc_opts="$dsc_opts -f$OPTARG";;
       j) par=true;;
-      m) dsc_opts="$dsc_opts -m$OPTARG";;
+      m) orig_opts="$orig_opts -m$OPTARG"; dsc_opts="$dsc_opts -m$OPTARG";;
       n) orig_opts="$orig_opts -n";;
       o) orig="$OPTARG";;
       s) dsc_opts="$dsc_opts -s$OPTARG";;
@@ -390,7 +395,7 @@ commands:
     -f <modules.conf>
       Build only modules listed in this file
     -j Build debs in parallel
-    -m [ quicktest ]
+    -m [ quicktest | non-dfsg ]
       Choose custom list of modules to build
     -n Nightly build
     -o <orig-file>
@@ -414,7 +419,7 @@ commands:
 
     -f <modules.conf>
       Build only modules listed in this file
-    -m [ quicktest ]
+    -m [ quicktest | non-dfsg ]
       Choose custom list of modules to build
     -s [ paranoid | reckless ]
       Set FS bootstrap/build -j flags
@@ -423,6 +428,8 @@ commands:
   create-orig <treeish>
 
     -b Bundle downloaded libraries in source package
+    -m [ quicktest | non-dfsg ]
+      Choose custom list of modules to build
     -n Nightly build
     -v Set version
     -z Set compression level