File debian.rules of Package betterbird

#!/usr/bin/make -f

export MOZ_NOSPAM=1

%:
	dh $@

override_dh_auto_configure:
	# 1. Discover and EXPORT the patches folder
	@PATCHDIR_REL=$$(find . -type d -name "thunderbird-patches*" -not -path "*/.*" | head -n 1); \
	if [ -z "$$PATCHDIR_REL" ]; then \
		PATCHDIR_REL=$$(find .. -maxdepth 2 -type d -name "thunderbird-patches*" | head -n 1); \
	fi; \
	if [ -z "$$PATCHDIR_REL" ]; then echo "ERROR: Patches not found"; exit 1; fi; \
	export PATCHDIR=$$(readlink -f "$$PATCHDIR_REL"); \
	echo "FOUND PATCHDIR=$$PATCHDIR"; \
	\
	# 2. Apply Mozilla-Central patches
	echo "Applying Mozilla-Central patches..."; \
	cat "$$PATCHDIR/140/series-M-C" | while read p; do \
		[ -z "$$p" ] && continue; \
		case "$$p" in \#*) continue;; esac; \
		echo "Applying: $$p"; \
		patch -p1 < "$$PATCHDIR/140/$$p"; \
	done; \
	\
	# 3. Apply Betterbird Comm patches
	echo "Applying Betterbird Comm patches..."; \
	cd comm && cat "$$PATCHDIR/140/series" | while read p; do \
		[ -z "$$p" ] && continue; \
		case "$$p" in \#*) continue;; esac; \
		echo "Applying: $$p"; \
		patch -p1 < "$$PATCHDIR/140/$$p"; \
	done; \
	cd ..; \
	\
	# 4. Handle mozconfig
	echo "Installing mozconfig..."; \
	if [ -f ../debian.mozconfig ]; then cp ../debian.mozconfig .mozconfig; \
	elif [ -f debian/mozconfig ]; then cp debian/mozconfig .mozconfig; \
	elif [ -f ../mozconfig ]; then cp ../mozconfig .mozconfig; \
	elif [ -f mozconfig ]; then cp mozconfig .mozconfig; \
	else echo "ERROR: mozconfig not found"; exit 1; fi; \
	echo "Build configuration ready."

override_dh_auto_build:
	./mach build

override_dh_auto_install:
	# 1. Let mach install under debian/betterbird
	DESTDIR=$(CURDIR)/debian/betterbird ./mach install

	# 2. Create target dirs
	mkdir -p $(CURDIR)/debian/betterbird/usr/lib
	mkdir -p $(CURDIR)/debian/betterbird/usr/bin
	mkdir -p $(CURDIR)/debian/betterbird/usr/share/applications

	# 3. Detect and Move
	APPROOT="$(CURDIR)/debian/betterbird/usr/local/lib"; \
	if [ -d "$$APPROOT" ]; then \
	  cand=$$(find "$$APPROOT" -mindepth 1 -maxdepth 1 -type d | head -n1); \
	  if [ -n "$$cand" ]; then \
	    mv "$$cand" "$(CURDIR)/debian/betterbird/usr/lib/betterbird"; \
	  else \
	    exit 1; \
	  fi; \
	fi

	# 4. Rename binary (thunderbird -> betterbird)
	if [ -f "$(CURDIR)/debian/betterbird/usr/lib/betterbird/thunderbird" ]; then \
	    mv "$(CURDIR)/debian/betterbird/usr/lib/betterbird/thunderbird" "$(CURDIR)/debian/betterbird/usr/lib/betterbird/betterbird"; \
	fi

	# 5. Symlink
	ln -sf ../lib/betterbird/betterbird $(CURDIR)/debian/betterbird/usr/bin/betterbird

	# 6. Install desktop file (if present)
	if [ -f ../betterbird.desktop ]; then \
	    cp ../betterbird.desktop $(CURDIR)/debian/betterbird/usr/share/applications/; \
	fi

	# 7. Cleanup
	rm -rf $(CURDIR)/debian/betterbird/usr/local
openSUSE Build Service is sponsored by