From a85660738779248ea2c2cd44a11b7f4602875671 Mon Sep 17 00:00:00 2001
From: sbwml <admin@cooluc.com>
Date: Fri, 4 Oct 2024 10:46:49 +0800
Subject: [PATCH 02/10] rootfs: add upx compression support

* When the upx_list.txt file exists in the source code root directory,
  it will be compressed by upx.

* fill in the binary path with rootfs as the absolute path, like this:

/usr/bin/xray
/usr/bin/xray-plugin
/usr/sbin/haproxy

Signed-off-by: sbwml <admin@cooluc.com>
---
 include/rootfs.mk | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/rootfs.mk b/include/rootfs.mk
index e6cadc5..574e3fe 100644
--- a/include/rootfs.mk
+++ b/include/rootfs.mk
@@ -120,6 +120,11 @@ define prepare_rootfs
 		$(1)/usr/lib/opkg/info/*.postinst* \
 		$(1)/usr/lib/opkg/lists/* \
 		$(1)/var/lock/*.lock
+	@if [ -f "$(TOPDIR)/upx_list.txt" ]; then \
+		while IFS= read -r file; do \
+			$(STAGING_DIR_HOST)/bin/upx --lzma --best "$(1)$$file" || true; \
+		done < "$(TOPDIR)/upx_list.txt"; \
+	fi
 	$(call clean_ipkg,$(1))
 	$(call mklibs,$(1))
 	$(if $(SOURCE_DATE_EPOCH),find $(1)/ -mindepth 1 -execdir touch -hcd "@$(SOURCE_DATE_EPOCH)" "{}" +)
-- 
2.43.5

