From 2f250c14d4e0728130955cfea32dcabc53740c8e Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
Date: Tue, 9 Mar 2021 11:38:10 -0500
Subject: [PATCH] build.py: Build contribs with multiple cores and with debug
 symbols.

This hastens the build when using the ./build.py script.  The
debug symbols are now also kept for the built contribs when the
--debug option is provided along --install.

Change-Id: Ia5a68456213e8984f5ac8f050131356b324d9777
---
 build.py           | 12 ++++++++----
 scripts/install.sh | 33 ++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/build.py b/build.py
index 791a2745..3dc73a11 100755
--- a/build.py
+++ b/build.py
@@ -369,10 +369,12 @@ def run_install(args):
         install_args.append('-s')
     if args.global_install:
         install_args.append('-g')
-    if args.prefix is not None:
+    if args.prefix:
         install_args += ('-P', args.prefix)
     if not args.priv_install:
         install_args.append('-u')
+    if args.debug:
+        install_args.append('-d')
 
     if args.distribution == OSX_DISTRIBUTION_NAME:
         # The `universal_newlines` parameter has been renamed to `text` in
@@ -396,6 +398,7 @@ def run_install(args):
             install_args += ("-q", args.qtver)
             install_args += ("-Q", args.qt)
 
+    print(f'info: Invoking scripts/install.sh with arguments: {install_args}')
     return subprocess.run(["./scripts/install.sh"] + install_args, env=environ, check=True)
 
 
@@ -498,8 +501,8 @@ def run_run(args):
 def run_stop(args):
     client_suffix = "qt" if (args.qt is not None) else "gnome"
     STOP_SCRIPT = [
-        'xargs kill < daemon.pid',
-        'xargs kill < jami-' + client_suffix + '.pid'
+        'xargs kill < jami-' + client_suffix + '.pid',
+        'xargs kill < daemon.pid'
     ]
     execute_script(STOP_SCRIPT)
 
@@ -586,7 +589,8 @@ def parse_args():
     ap.add_argument('--prefix')
     ap.add_argument('--static', default=False, action='store_true')
     ap.add_argument('--global-install', default=False, action='store_true')
-    ap.add_argument('--debug', default=False, action='store_true')
+    ap.add_argument('--debug', default=False, action='store_true',
+                    help='Build with debug support; run in GDB')
     ap.add_argument('--background', default=False, action='store_true')
     ap.add_argument('--no-priv-install', dest='priv_install',
                     default=True, action='store_false')
diff --git a/scripts/install.sh b/scripts/install.sh
index 7c4f90c0..0a6bc466 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -16,6 +16,7 @@ set -ex
 # Qt_MIN_VER required for client-qt
 QT5_MIN_VER="5.14"
 
+debug=
 global=false
 static=''
 client=''
@@ -23,7 +24,7 @@ qt5ver=''
 qt5path=''
 proc='1'
 priv_install=true
-while getopts gsc:q:Q:P:p:u OPT; do
+while getopts gsc:dq:Q:P:p:u OPT; do
   case "$OPT" in
     g)
       global='true'
@@ -34,6 +35,9 @@ while getopts gsc:q:Q:P:p:u OPT; do
     c)
       client="${OPTARG}"
     ;;
+    d)
+      debug=true
+    ;;
     q)
       qt5ver="${OPTARG}"
     ;;
@@ -78,22 +82,22 @@ else
 fi
 
 # dring
-cd "${TOP}/daemon"
-DAEMON="$(pwd)"
-cd contrib
-mkdir -p native
-cd native
-if [ "${prefix+set}" ]; then
-    ../bootstrap --prefix="${prefix}"
-else
-    ../bootstrap
-fi
-make
-cd "${DAEMON}"
+DAEMON=${TOP}/daemon
+cd "$DAEMON"
+
+# Build the contribs.
+mkdir -p contrib/native
+(
+    cd contrib/native
+    ../bootstrap ${prefix:+"--prefix=$prefix"} ${debug:+"--enable-debug"}
+    make -j"${proc}"
+)
+
+# Build the daemon itself.
 ./autogen.sh
 
-#keep shared Lib on MAC OSX
 if [[ "$OSTYPE" != "darwin"* ]]; then
+    # Keep the shared libaries on MAC OSX.
     sharedLib="--disable-shared"
 fi
 
@@ -109,7 +113,6 @@ fi
 make -j"${proc}"
 make_install "${global}" "${priv_install}"
 
-
 # For the client-qt, verify system's version if no path provided
 if [ "${client}" = "client-qt" ] && [ -z "$qt5path" ]; then
     sys_qt5ver=""
-- 
GitLab