[pacman-dev] [PATCH 2/2] Split prepare_buildenv() to libmakepkg scripts

Que Quotion quequotion at gmail.com
Sun Nov 4 14:35:10 UTC 2018


From: Que Quotion <quequotion at gmail.com>

Being misled by git's documentation, my attempt to attach this patch
to the previous mail was foiled. That's really, really frustrating.

Signed-off-by: Que Quotion <quequotion at gmail.com>
---
 scripts/Makefile.am                           |  4 +--
 scripts/libmakepkg/buildenv.sh.in             | 13 ++------
 scripts/libmakepkg/buildenv/buildflags.sh.in  |  1 +
 .../buildenv/{ccache.sh.in => compiler.sh.in} | 27 +++++++++++++---
 .../{distcc.sh.in => debugflags.sh.in}        | 31 +++++++------------
 scripts/libmakepkg/buildenv/makeflags.sh.in   |  1 +
 scripts/libmakepkg/buildenv/meson.build       |  4 +--
 7 files changed, 43 insertions(+), 38 deletions(-)
 rename scripts/libmakepkg/buildenv/{ccache.sh.in => compiler.sh.in} (69%)
 rename scripts/libmakepkg/buildenv/{distcc.sh.in => debugflags.sh.in} (56%)

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 8e669f71..adced908 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -53,8 +53,8 @@ LIBMAKEPKGDIRS = \
 LIBMAKEPKG_IN = \
 	libmakepkg/buildenv.sh \
 	libmakepkg/buildenv/buildflags.sh \
-	libmakepkg/buildenv/ccache.sh \
-	libmakepkg/buildenv/distcc.sh \
+	libmakepkg/buildenv/compiler.sh \
+	libmakepkg/buildenv/debugflags.sh \
 	libmakepkg/buildenv/makeflags.sh \
 	libmakepkg/integrity.sh \
 	libmakepkg/integrity/generate_checksum.sh \
diff --git a/scripts/libmakepkg/buildenv.sh.in b/scripts/libmakepkg/buildenv.sh.in
index a14a3a9a..9c1f02f4 100644
--- a/scripts/libmakepkg/buildenv.sh.in
+++ b/scripts/libmakepkg/buildenv.sh.in
@@ -28,28 +28,21 @@ source "$LIBRARY/util/message.sh"
 source "$LIBRARY/util/option.sh"
 
 
-declare -a build_options
+declare -a build_options build_macros
 
 for lib in "$LIBRARY/buildenv/"*.sh; do
 	source "$lib"
 done
 
-readonly -a build_options
+readonly -a build_options build_macros
 
 prepare_buildenv() {
 	msg "$(gettext "Preparing build environment...")"
 
-	for func in ${build_options[@]}; do
+	for func in ${build_macros[@]}; do
 		$func
 	done
 
-	if check_option "debug" "y"; then
-		DEBUG_CFLAGS+=" -fdebug-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}"
-		DEBUG_CXXFLAGS+=" -fdebug-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}"
-		CFLAGS+=" $DEBUG_CFLAGS"
-		CXXFLAGS+=" $DEBUG_CXXFLAGS"
-	fi
-
 	# ensure all necessary build variables are exported
 	export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
 }
diff --git a/scripts/libmakepkg/buildenv/buildflags.sh.in b/scripts/libmakepkg/buildenv/buildflags.sh.in
index fb49a85c..55d7fbce 100644
--- a/scripts/libmakepkg/buildenv/buildflags.sh.in
+++ b/scripts/libmakepkg/buildenv/buildflags.sh.in
@@ -26,6 +26,7 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 source "$LIBRARY/util/option.sh"
 
 build_options+=('buildflags')
+build_macros+=('buildflags')
 
 buildflags() {
 	if check_option "buildflags" "n"; then
diff --git a/scripts/libmakepkg/buildenv/ccache.sh.in b/scripts/libmakepkg/buildenv/compiler.sh.in
similarity index 69%
rename from scripts/libmakepkg/buildenv/ccache.sh.in
rename to scripts/libmakepkg/buildenv/compiler.sh.in
index 122033a9..dec19ac8 100644
--- a/scripts/libmakepkg/buildenv/ccache.sh.in
+++ b/scripts/libmakepkg/buildenv/compiler.sh.in
@@ -26,11 +26,12 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 source "$LIBRARY/util/message.sh"
 source "$LIBRARY/util/option.sh"
 
-build_options+=('ccache')
+build_options+=('ccache' 'distcc')
+build_macros+=('use_ccache' 'use_distcc')
 
-local ccache=0
+using_ccache=0
 
-ccache() {
+use_ccache() {
 	if check_buildoption "ccache" "y"; then
 		if ! type -p ccache >/dev/null; then
 			error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache"
@@ -39,7 +40,25 @@ ccache() {
 
 		if [ -d /usr/lib/ccache/bin ]; then
 			export PATH="/usr/lib/ccache/bin:$PATH"
-			ccache=1
+			using_ccache=1
 		fi
 	fi
 }
+
+use_distcc() {
+	if check_buildoption "distcc" "y"; then
+		if ! type -p distcc >/dev/null; then
+			error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
+			return 1
+		fi
+
+		if (( using_ccache )); then
+			export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc"
+			export CCACHE_BASEDIR="$srcdir"
+		elif [[ -d /usr/lib/distcc/bin ]]; then
+			export PATH="/usr/lib/distcc/bin:$PATH"
+		fi
+
+		export DISTCC_HOSTS
+	fi
+}
diff --git a/scripts/libmakepkg/buildenv/distcc.sh.in b/scripts/libmakepkg/buildenv/debugflags.sh.in
similarity index 56%
rename from scripts/libmakepkg/buildenv/distcc.sh.in
rename to scripts/libmakepkg/buildenv/debugflags.sh.in
index f7580705..8627e242 100644
--- a/scripts/libmakepkg/buildenv/distcc.sh.in
+++ b/scripts/libmakepkg/buildenv/debugflags.sh.in
@@ -1,6 +1,7 @@
 #!/usr/bin/bash
 #
-#   distcc.sh - Distribute compliation to reduce compilation time
+#   debugflags.sh - Specify flags for building a package with debugging
+#   symbols
 #
 #   Copyright (c) 2018 Pacman Development Team <pacman-dev at archlinux.org>
 #
@@ -18,30 +19,20 @@
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-[[ -n "$LIBMAKEPKG_BUILDENV_DISTCC_SH" ]] && return
-LIBMAKEPKG_BUILDENV_DISTCC_SH=1
+[[ -n "$LIBMAKEPKG_BUILDENV_MAKEFLAGS_SH" ]] && return
+LIBMAKEPKG_BUILDENV_MAKEFLAGS_SH=1
 
 LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 
-source "$LIBRARY/util/message.sh"
 source "$LIBRARY/util/option.sh"
 
-build_options+=('distcc')
+build_macros+=('debugflags')
 
-distcc() {
-	if check_buildoption "distcc" "y"; then
-		if ! type -p distcc >/dev/null; then
-			error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
-			return 1
-		fi
-
-		if (( ccache )); then
-			export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc"
-			export CCACHE_BASEDIR="$srcdir"
-		elif [[ -d /usr/lib/distcc/bin ]]; then
-			export PATH="/usr/lib/distcc/bin:$PATH"
-		fi
-
-		export DISTCC_HOSTS
+debugflags() {
+	if check_option "debug" "y"; then
+		DEBUG_CFLAGS+=" -fdebug-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}"
+		DEBUG_CXXFLAGS+=" -fdebug-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}"
+		CFLAGS+=" $DEBUG_CFLAGS"
+		CXXFLAGS+=" $DEBUG_CXXFLAGS"
 	fi
 }
diff --git a/scripts/libmakepkg/buildenv/makeflags.sh.in b/scripts/libmakepkg/buildenv/makeflags.sh.in
index 53ac1e4c..b0c438d2 100644
--- a/scripts/libmakepkg/buildenv/makeflags.sh.in
+++ b/scripts/libmakepkg/buildenv/makeflags.sh.in
@@ -26,6 +26,7 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 source "$LIBRARY/util/option.sh"
 
 build_options+=('makeflags')
+build_macros+=('makeflags')
 
 makeflags() {
 	if check_option "makeflags" "n"; then
diff --git a/scripts/libmakepkg/buildenv/meson.build b/scripts/libmakepkg/buildenv/meson.build
index e0d07287..34d4ba7b 100644
--- a/scripts/libmakepkg/buildenv/meson.build
+++ b/scripts/libmakepkg/buildenv/meson.build
@@ -2,8 +2,8 @@ libmakepkg_module = 'buildenv'
 
 sources = [
   'buildflags.sh.in',
-  'ccache.sh.in',
-  'distcc.sh.in',
+  'compiler.sh.in',
+  'debugflags.sh.in',
   'makeflags.sh.in',
 ]
 
-- 
2.19.1


More information about the pacman-dev mailing list