Files
sing-box-rr-edition/sing-box-rr/Makefile
T

121 lines
3.4 KiB
Makefile

include $(TOPDIR)/rules.mk
PROJECT_DIR:=$(CURDIR)
PKG_NAME:=sing-box-rr
PKG_VERSION:=$(shell cat $(CURDIR)/../VERSION 2>/dev/null || echo 0.0.0-unknown)
PKG_RELEASE:=2
PKG_SOURCE_DATE_EPOCH:=$(shell cat $(CURDIR)/../SOURCE_DATE_EPOCH 2>/dev/null || date +%s)
PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=LICENSE
PKG_MAINTAINER:=RR Edition
PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16
GO_BIN?=/usr/local/go/bin/go
SINGBOX_RR_BUILT_BINARY=$(PKG_BUILD_DIR)/sing-box
SINGBOX_RR_GOCACHE?=$(TMP_DIR)/sing-box-rr-go-build
SINGBOX_RR_GOMODCACHE?=$(DL_DIR)/sing-box-rr-go-mod
SINGBOX_RR_TAGS:=$(shell tr -d '\n' < $(PROJECT_DIR)/release/DEFAULT_BUILD_TAGS_OTHERS 2>/dev/null)
SINGBOX_RR_BASE_LDFLAGS:=$(shell tr -d '\n' < $(PROJECT_DIR)/release/LDFLAGS 2>/dev/null)
SINGBOX_RR_LDFLAGS:=$(strip $(SINGBOX_RR_BASE_LDFLAGS) -X github.com/sagernet/sing-box/constant.Version=$(PKG_VERSION) -s -w)
ifeq ($(ARCH),aarch64)
SINGBOX_RR_GOARCH:=arm64
endif
ifeq ($(ARCH),x86_64)
SINGBOX_RR_GOARCH:=amd64
SINGBOX_RR_GOENV_EXTRA:=GOAMD64=v1
endif
include $(INCLUDE_DIR)/package.mk
define Package/sing-box-rr
TITLE:=Sing-box RR edition
SECTION:=net
CATEGORY:=Network
URL:=https://git.my-handbook.ru/fresa/sing-box-rr-edition
DEPENDS:=@(aarch64||x86_64) +ca-bundle +kmod-inet-diag +kmod-tun
PROVIDES:=sing-box sing-box-tiny
CONFLICTS:=sing-box
USERID:=sing-box=5566:sing-box=5566
endef
define Package/sing-box-rr/description
Trimmed OpenWrt build of the sing-box RR Edition fork.
Keeps the network-oriented runtime and preserves XHTTP and mKCP.
endef
define Build/Prepare
rm -rf $(PKG_BUILD_DIR)
mkdir -p $(PKG_BUILD_DIR)
( \
cd "$(PROJECT_DIR)" && \
tar \
--exclude=.git \
--exclude=.codex \
--exclude=BUILD.md \
--exclude=Makefile \
--exclude=Makefile.sing-box \
-cf - . \
) | (cd "$(PKG_BUILD_DIR)" && tar -xf -)
endef
define Build/Compile
[ -x "$(GO_BIN)" ] || { echo "external Go not found at $(GO_BIN)"; exit 1; }
[ -n "$(SINGBOX_RR_GOARCH)" ] || { echo "unsupported OpenWrt ARCH: $(ARCH)"; exit 1; }
mkdir -p "$(SINGBOX_RR_GOCACHE)" "$(SINGBOX_RR_GOMODCACHE)"
( \
cd "$(PKG_BUILD_DIR)" && \
PATH="$(dir $(GO_BIN)):$$$$PATH" \
GOTOOLCHAIN=local \
GOCACHE="$(SINGBOX_RR_GOCACHE)" \
GOMODCACHE="$(SINGBOX_RR_GOMODCACHE)" \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH="$(SINGBOX_RR_GOARCH)" \
$(SINGBOX_RR_GOENV_EXTRA) \
"$(GO_BIN)" build \
-buildvcs=false \
-trimpath \
-tags "$(SINGBOX_RR_TAGS)" \
-ldflags "$(SINGBOX_RR_LDFLAGS)" \
-o "$(SINGBOX_RR_BUILT_BINARY)" \
./cmd/sing-box \
)
endef
define Package/sing-box-rr/conffiles
/etc/config/sing-box
/etc/sing-box/config.json
endef
define Package/sing-box-rr/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(SINGBOX_RR_BUILT_BINARY) $(1)/usr/bin/sing-box
$(INSTALL_DIR) $(1)/etc/sing-box
$(INSTALL_DATA) $(PKG_BUILD_DIR)/release/config/config.json $(1)/etc/sing-box/config.json
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) $(PKG_BUILD_DIR)/release/config/openwrt.conf $(1)/etc/config/sing-box
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) $(PKG_BUILD_DIR)/release/config/openwrt.init $(1)/etc/init.d/sing-box
$(INSTALL_DIR) $(1)/lib/upgrade/keep.d
$(INSTALL_DATA) $(PKG_BUILD_DIR)/release/config/openwrt.keep $(1)/lib/upgrade/keep.d/sing-box
endef
define Package/sing-box-rr/prerm
#!/bin/sh
[ -n "$${IPKG_INSTROOT}" ] && exit 0
[ "$$PKG_UPGRADE" = "1" ] && exit 0
/etc/init.d/sing-box stop 2>/dev/null || true
exit 0
endef
$(eval $(call BuildPackage,sing-box-rr))