From c4f9d59c62454d255af4a5c3933eebf6942dbd99 Mon Sep 17 00:00:00 2001
From: ctyunsystem <ctyuncommiter05@chinatelecom.cn>
Date: Wed, 11 May 2022 10:32:45 +0800
Subject: [PATCH 4/5] fix probably restore cc symbol link fail when kill patch
 building uncourteous

---
 src/libcare-patch-make | 45 ++++--------------------------------------
 1 file changed, 4 insertions(+), 41 deletions(-)

diff --git a/src/libcare-patch-make b/src/libcare-patch-make
index 03aa1d6..41e5926 100755
--- a/src/libcare-patch-make
+++ b/src/libcare-patch-make
@@ -83,32 +83,6 @@ restore_origs() {
 
 trap "restore_origs" 0
 
-replace_qemu_ld_flags() {
-	local qemu_ld_flags_old=$1
-	ret=$(echo $qemu_ld_flags_old | grep "\-Wl,-q")
-	if [[ "$ret" == "" ]]; then
-		local qemu_ld_flags="${qemu_ld_flags_old} -Wl,-q"
-		echo "replace QEMU_LDFLAGS to '${qemu_ld_flags}'"
-		sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak
-	fi
-}
-
-recover_qemu_ld_flags() {
-	local qemu_ld_flags=$1
-	echo "recover QEMU_LDFLAGS to '${qemu_ld_flags}'"
-	sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak
-}
-
-replace_cc_symbolink() {
-	unlink $SYMBOLINK_CC
-	ln -s $LIBCARE_CC $SYMBOLINK_CC
-}
-
-recover_cc_symbolink() {
-	unlink $SYMBOLINK_CC
-	ln -s $REAL_CC $SYMBOLINK_CC
-}
-
 build_objects() {
 	restore_origs
 
@@ -124,7 +98,8 @@ build_objects() {
 	export KPCC_DBGFILTER_ARGS=""
 
 	echo "${green}BUILDING ORIGINAL CODE${reset}"
-	make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1
+	local lp_make_env_original="CC=${CC}"
+	make $LPMAKEFILE $JOBS_MAKE ${lp_make_env_original} >$MAKE_OUTPUT 2>&1
 
 	echo "${green}INSTALLING ORIGINAL OBJECTS INTO $LPMAKE_ORIGINAL_DIR${reset}"
 	make $LPMAKEFILE $JOBS_MAKE install			\
@@ -149,20 +124,14 @@ build_objects() {
 	export KPATCH_STAGE=patched
 	export KPCC_APPEND_ARGS="-Wl,-q"
 
-	qemu_ld_flags_bak=$(grep "^QEMU_LDFLAGS=" config-host.mak)
-	#add '-Wl,-q' to LD_FLAGS
-	replace_qemu_ld_flags "$qemu_ld_flags_bak"
-
 	echo "${green}BUILDING PATCHED CODE${reset}"
-	make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1
+	local lp_make_env_patched="CC=${CC}"
+	make $LPMAKEFILE $JOBS_MAKE ${lp_make_env_patched} >$MAKE_OUTPUT 2>&1
 
 	echo "${green}INSTALLING PATCHED OBJECTS INTO $LPMAKE_PATCHED_DIR${reset}"
 	make $LPMAKEFILE $JOBS_MAKE install			\
 		"$destdir=$LPMAKE_PATCHED_DIR"			\
 		>$MAKE_OUTPUT 2>&1
-
-	# recover LD_FLAGS
-	recover_qemu_ld_flags "$qemu_ld_flags_bak"
 }
 
 build_kpatches() {
@@ -274,16 +243,10 @@ main() {
 
 	prepare_env
 
-	# replace cc
-	replace_cc_symbolink
-
 	if test -z "$only_update"; then
 		build_objects "$@"
 	fi
 	build_kpatches
-
-	# recover cc
-	recover_cc_symbolink
 }
 
 main "$@"
-- 
2.27.0

