# HG changeset patch
# User t_mrc-ct@users.osdn.jp
# Date 1441713509 -32400
#      Tue Sep 08 20:58:29 2015 +0900
# Branch THUNDERBIRD3880_2016050308_RELBRANCH
# Node ID e09b2d73c67a9045d24050ca6326b0b14ef1a20e
# Parent  f393a9f2d06553b16c0afc4dbd5c7c7f2d0bae27
Lightning addon build fix

diff --git a/104distro.sh b/104distro.sh
--- a/104distro.sh
+++ b/104distro.sh
@@ -4,60 +4,81 @@
 
 libgcc_dylibs="libstdc++.6.dylib libgcc_s.1.dylib"
 
 local_prefix="/opt/local"
 
 if [ $# -ne 3 ]
 then
 	echo "usage:" >&2
-	echo "$0 libgcc_dir source_app dest_app" >&2
+	echo "$0 libgcc_dir source_dir dest_dir" >&2
+	echo "	Skip copying libgcc dylibs if libgcc_dir is empty string" >&2
 	exit 1
 fi
 
-_pwd="${PWD}"
-cd "$1"
-libgcc_dir="${PWD}"
-cd "${_pwd}"
+if [  -n "$1" ]
+then
+	_pwd="${PWD}"
+	cd "$1"
+	libgcc_dir="${PWD}"
+	cd "${_pwd}"
+else
+	libgcc_dir=""
+fi
 
-src_app=$2
-dest_app=$3
-
-dest_dir="${dest_app}/Contents"
+src_dir=$2
+dest_dir=$3
 
 function exit_err() {
 	cnt=$1
 	msg=$2
 	echo "Error count: ${cnt}" >&2
 	echo "${msg}" >&2
 	exit $1
 }
 
-if [ -e "${dest_app}" ]
+if [ -e "${dest_dir}" ]
 then
-	exit_err 1 "destination directory already existed: ${dest_app}"
+	exit_err 1 "destination directory already existed: ${dest_dir}"
 fi
 
-cp -RL "${src_app}" "${dest_app}" || exit
-test -e "${dest_dir}" || exit
+cp -RL "${src_dir}" "${dest_dir}"
+if [ $? -ne 0 ]
+then
+	echo "Failed to copy directory:" >&2
+	echo "	from: ${src_dir}" >&2
+	echo "	to: ${dest_dir}" >&2
+	exit 1
+fi
+test -d "${dest_dir}" || exit_err 1 "'${dest_dir}' is not directory."
 
-for dylib in ${libgcc_dylibs}
-do
-	ditto -v "${libgcc_dir}/${dylib}" "${dest_dir}/MacOS" || exit
-	install_name_tool -change "${libgcc_dir}/${dylib}" "@executable_path/${dylib}" \
-		-id "@executable_path/${dylib}" \
-		"${dest_dir}/MacOS/${dylib}" || exit
-done
+if [ -n "${libgcc_dir}" ]
+then
+	bin_dir="${dest_dir}/Contents/MacOS"
+	if [ ! -d "${bin_dir}" ]
+	then
+		echo "Failed to copy dylibs" >&2
+		echo "Can't find directory: ${dest_dir}/Contents/MacOS" >&2
+		exit 1
+	fi
 
-libgcc_prefix=`otool -L "${dest_dir}/MacOS/XUL" | sed -E -e 's#^[[:space:]]*(/opt/[^/]+/lib/[^/]*gcc[^/]*)/.+$#\1#p' -e d | head -1`
+	for dylib in ${libgcc_dylibs}
+	do
+		ditto -v "${libgcc_dir}/${dylib}" "${bin_dir}" || exit_err 1 "Failed to copy dylib: ${libgcc_dir}/${dylib}"
+		install_name_tool -change "${libgcc_dir}/${dylib}" "@executable_path/${dylib}" -id "@executable_path/${dylib}" "${bin_dir}/${dylib}"
+		if [ $? -ne 0 ]
+		then
+			echo "Failed to change dylib install names:" >&2
+			echo "	id: @executable_path/${dylib}" >&2
+			echo "	change: '${libgcc_dir}/${dylib}' '@executable_path/${dylib}'" >&2
+			exit 1
+		fi
+	done
+fi
 
-if [ -z "${libgcc_prefix}" ]
-then
-	exit_err 1 "${src_app} does not use gcc in '/opt/*' "
-fi
 
 function change_sharelib() {
 	errcnt=0
 	while read file
 	do
 		libs=`otool -L "${file}" | sed -E -e 's/[[:space:]]+([^[:space:]](.+[^[:space:]])?)[[:space:]]+\([^(]+/\1/p' -e d`
 		if [ -z "${libs}" ]
 		then
@@ -68,25 +89,30 @@
 
 		if [ -n "${opt_libs}" ]
 		then
 			echo "file: ${file}"
 		else
 			continue
 		fi
 
-		for dylib in ${libgcc_dylibs}
-		do
-			if [ -n "`echo "${opt_libs}" | grep -xF "${libgcc_prefix}/${dylib}"`" ]
-			then
-				echo "  change: ${libgcc_prefix}/${dylib}"
-				install_name_tool -change "${libgcc_prefix}/${dylib}" "@executable_path/${dylib}" "${file}"
-				opt_libs=`echo "${opt_libs}" | grep -vxF "${libgcc_prefix}/${dylib}"`
-			fi
-		done
+		libgcc_prefix=`echo "${opt_libs}" | sed -E -e 's#^[[:space:]]*(/opt/[^/]+/lib/[^/]*gcc[^/]*)/.+$#\1#p' -e d | head -1`
+
+		if [ -n "${libgcc_prefix}" ]
+		then
+			for dylib in ${libgcc_dylibs}
+			do
+				if [ -n "`echo "${opt_libs}" | grep -xF "${libgcc_prefix}/${dylib}"`" ]
+				then
+					echo "  change: ${libgcc_prefix}/${dylib}"
+					install_name_tool -change "${libgcc_prefix}/${dylib}" "@executable_path/${dylib}" "${file}"
+					opt_libs=`echo "${opt_libs}" | grep -vxF "${libgcc_prefix}/${dylib}"`
+				fi
+			done
+		fi
 
 		if [ -n "${opt_libs}" ]
 		then
 			errcnt=$(($errcnt + 1))
 			echo "error: unknown shared libraries found" >&2
 			echo "  file: ${file}" >&2
 			echo "${opt_libs}" | sed -E -e 's/.+/   shared_lib: &/p' -e d >&2
 
diff --git a/calendar/lightning/Makefile.in b/calendar/lightning/Makefile.in
--- a/calendar/lightning/Makefile.in
+++ b/calendar/lightning/Makefile.in
@@ -90,16 +90,17 @@
 DEFINES += -DTHUNDERBIRD_VERSION=$(THUNDERBIRD_VERSION) \
            -DTHUNDERBIRD_MAXVERSION=$(THUNDERBIRD_MAXVERSION) \
            -DAB_CD=$(AB_CD) \
            -DSEAMONKEY_VERSION=$(SEAMONKEY_VERSION) \
            -DSEAMONKEY_MAXVERSION=$(SEAMONKEY_MAXVERSION) \
            -DLIGHTNING_VERSION=$(LIGHTNING_VERSION) \
            -DTARGET_PLATFORM=$(OS_TARGET)_$(TARGET_XPCOM_ABI) \
            -DXPI_EM_ID="$(XPI_EM_ID)" \
+           -DMOZ_APP_DISPLAYNAME="$(MOZ_APP_DISPLAYNAME)" \
            $(NULL)
 
 GRE_BUILDID = $(shell $(PYTHON) $(MOZILLA_SRCDIR)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/application.ini App BuildID)
 DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
 
 libs::
 	$(NSINSTALL) -m 0644 $(srcdir)/../timezones/zones.json $(FINAL_TARGET)/timezones
 
diff --git a/calendar/lightning/install.rdf b/calendar/lightning/install.rdf
--- a/calendar/lightning/install.rdf
+++ b/calendar/lightning/install.rdf
@@ -25,19 +25,19 @@
         <!-- seamonkey -->
         <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
         <em:minVersion>@SEAMONKEY_VERSION@</em:minVersion>
         <em:maxVersion>@SEAMONKEY_MAXVERSION@</em:maxVersion>
       </Description>
     </em:targetApplication>
 
     <em:id>@XPI_EM_ID@</em:id>
-    <em:name>Lightning</em:name>
+    <em:name>Lightning for @MOZ_APP_DISPLAYNAME@</em:name>
     <em:version>@LIGHTNING_VERSION@</em:version> <!-- BuildID=@GRE_BUILDID@ -->
-    <em:description>An integrated calendar for Thunderbird</em:description>
+    <em:description>An integrated calendar for @MOZ_APP_DISPLAYNAME@@APP_TUNED@</em:description>
 #ifdef LIGHTNING_PRERELEASE_VERSION
     <em:developer>Build ID: @GRE_BUILDID@</em:developer>
 #endif
     <em:creator>Mozilla Calendar Project</em:creator>
     <em:homepageURL>https://www.mozilla.org/projects/calendar/</em:homepageURL>
     <em:iconURL>chrome://calendar/skin/cal-icon32.png</em:iconURL>
     <em:optionsURL>chrome://messenger/content/preferences/preferences.xul</em:optionsURL>
     <em:targetPlatform>@TARGET_PLATFORM@</em:targetPlatform>
