git: 1aa0345b86c7 - stable/14 - pkgbase: create source package

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Thu, 07 Dec 2023 07:48:10 UTC
The branch stable/14 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=1aa0345b86c76dfd674d779fd7bcb2e95d2b895b

commit 1aa0345b86c76dfd674d779fd7bcb2e95d2b895b
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2023-11-17 16:19:39 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2023-12-07 07:47:16 +0000

    pkgbase: create source package
    
    FreeBSD-src for all the sources but the kernel
    FreeBSD-src-sys just for the kernel
    
    MFC After:              3 days
    Reviewed by:            manu
    Differential Revision:  https://reviews.freebsd.org/D42651
    
    (cherry picked from commit 99b8c0c35b0fcc633649209621243d678a13542a)
---
 Makefile                     |  4 ++--
 Makefile.inc1                | 54 +++++++++++++++++++++++++++++++++++++++++---
 release/packages/src-sys.ucl | 17 ++++++++++++++
 release/packages/src.ucl     | 17 ++++++++++++++
 4 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index b36e27e7f294..4a6f4bfd425e 100644
--- a/Makefile
+++ b/Makefile
@@ -175,8 +175,8 @@ TGTS=	all all-man buildenv buildenvvars buildetc buildkernel buildworld \
 	_build-tools _build-metadata _cross-tools _includes _libraries \
 	builddtb xdev xdev-build xdev-install \
 	xdev-links native-xtools native-xtools-install stageworld stagekernel \
-	stage-packages stage-packages-kernel stage-packages-world \
-	create-packages-world create-packages-kernel create-packages \
+	stage-packages stage-packages-kernel stage-packages-world stage-packages-source \
+	create-packages-world create-packages-kernel create-packages-source create-packages \
 	update-packages packages installconfig real-packages real-update-packages \
 	sign-packages package-pkg print-dir test-system-compiler test-system-linker \
 	test-includes
diff --git a/Makefile.inc1 b/Makefile.inc1
index b73b464be2a9..199a0f2ef0ee 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -1955,6 +1955,7 @@ stagekernel: .PHONY
 PORTSDIR?=	/usr/ports
 WSTAGEDIR?=	${OBJTOP}/worldstage
 KSTAGEDIR?=	${OBJTOP}/kernelstage
+SSTAGEDIR?=	${OBJTOP}/sourcestage
 REPODIR?=	${OBJROOT}repo
 PKG_FORMAT?=	tzst
 PKG_REPO_SIGNING_KEY?=	# empty
@@ -1962,6 +1963,7 @@ PKG_OUTPUT_DIR?=	${PKG_VERSION}
 
 .ORDER:		stage-packages create-packages
 .ORDER:		create-packages create-world-packages
+.ORDER:		create-packages create-source-packages
 .ORDER:		create-packages create-kernel-packages
 .ORDER:		create-packages sign-packages
 
@@ -1973,7 +1975,7 @@ _pkgbootstrap: .PHONY
 #
 # Determine PKG_ABI from newvers.sh if not already set.
 #
-.if !defined(PKG_ABI) && (make(create-world-packages-jobs) || make(create-kernel-packages*) || make(real-update-packages) || make(sign-packages))
+.if !defined(PKG_ABI) && (make(create-world-packages-jobs) || make(create-kernel-packages*) || make(real-update-packages) || make (create-source-packages) || make(sign-packages))
 PKG_ABI=${_TYPE}:${MAJOR_REVISION}:${TARGET_ARCH}
 .endif
 PKG_BIN_VERSION!=${PKG_CMD} --version </dev/null 2>/dev/null |\
@@ -2050,7 +2052,10 @@ stage-packages-kernel: .PHONY
 	${_+_}@cd ${.CURDIR}; \
 		${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT stagekernel
 
-stage-packages: .PHONY stage-packages-world stage-packages-kernel
+stage-packages-source: .PHONY
+	@mkdir -p ${SSTAGEDIR};
+
+stage-packages: .PHONY stage-packages-world stage-packages-kernel stage-packages-source
 
 _repodir: .PHONY
 	@mkdir -p ${REPODIR}
@@ -2069,7 +2074,50 @@ create-packages-kernel:	_pkgbootstrap _repodir .PHONY
 			SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
 			create-kernel-packages
 
-create-packages: .PHONY create-packages-world create-packages-kernel
+create-packages-source:	_pkgbootstrap _repodir .PHONY
+	${_+_}@cd ${.CURDIR}; \
+		${MAKE} -f Makefile.inc1 \
+			DESTDIR=${SSTAGEDIR} \
+			PKG_VERSION=${PKG_VERSION} create-source-packages
+
+create-packages: .PHONY create-packages-world create-packages-kernel create-packages-source
+
+create-source-packages: _pkgbootstrap .PHONY
+	rm -f ${SSTAGEDIR}/*.plist 2>/dev/null || :
+.if !empty(GIT_CMD) && exists(${GIT_CMD}) && exists(${SRCDIR}/.git)
+	@cd ${SRCDIR}; \
+		( echo "@override_prefix /usr/src" ;  \
+		${GIT_CMD} ls-files ":!:sys/" ) > ${SSTAGEDIR}/src.plist
+	@cd ${SRCDIR}; \
+		( echo "@override_prefix /usr/src" ; \
+		${GIT_CMD} ls-files "sys/" ) > ${SSTAGEDIR}/src-sys.plist
+	sed -e "s/%VERSION%/${PKG_VERSION}/" \
+		-e "s/%DESC%/FreeBSD sources/" \
+		-e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
+		-e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
+		-e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
+		-e "s|%PKG_WWW%|${PKG_WWW}|" \
+		${SRCDIR}/release/packages/src.ucl \
+		> ${SSTAGEDIR}/src.ucl
+	sed -e "s/%VERSION%/${PKG_VERSION}/" \
+		-e "s/%DESC%/FreeBSD Kernel sources/" \
+		-e "s/ %VCS_REVISION%/${VCS_REVISION}/" \
+		-e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
+		-e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
+		-e "s|%PKG_WWW%|${PKG_WWW}|" \
+		${SRCDIR}/release/packages/src-sys.ucl \
+		> ${SSTAGEDIR}/src-sys.ucl
+	${PKG_CMD} -o ABI=${PKG_ABI} create -f ${PKG_FORMAT} \
+		-M ${SSTAGEDIR}/src.ucl \
+		-p ${SSTAGEDIR}/src.plist \
+		-r ${SRCDIR} \
+		-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
+	${PKG_CMD} -o ABI=${PKG_ABI} create -f ${PKG_FORMAT} \
+		-M ${SSTAGEDIR}/src-sys.ucl \
+		-p ${SSTAGEDIR}/src-sys.plist \
+		-r ${SRCDIR} \
+		-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
+.endif
 
 create-world-packages:	_pkgbootstrap .PHONY
 	@rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || :
diff --git a/release/packages/src-sys.ucl b/release/packages/src-sys.ucl
new file mode 100644
index 000000000000..ad37f5c5a5f1
--- /dev/null
+++ b/release/packages/src-sys.ucl
@@ -0,0 +1,17 @@
+#
+#
+
+name = "%PKG_NAME_PREFIX%-src-sys"
+origin = "base"
+version = "%VERSION%"
+comment = "FreeBSD Kernel Sources"
+categories = [ base ]
+maintainer = "%PKG_MAINTAINER%"
+www = "%PKG_WWW%"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+
diff --git a/release/packages/src.ucl b/release/packages/src.ucl
new file mode 100644
index 000000000000..899193085554
--- /dev/null
+++ b/release/packages/src.ucl
@@ -0,0 +1,17 @@
+#
+#
+
+name = "%PKG_NAME_PREFIX%-src"
+origin = "base"
+version = "%VERSION%"
+comment = "FreeBSD userland sources"
+categories = [ base ]
+maintainer = "%PKG_MAINTAINER%"
+www = "%PKG_WWW%"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+