git: 24d5194306b5 - main - build: Emit a warning for build targets run as root

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Fri, 09 Oct 2026 15:04:46 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=24d5194306b573bf3396858b4c0aa5d420c37c91

commit 24d5194306b573bf3396858b4c0aa5d420c37c91
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-05-14 15:23:42 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-10-09 15:02:30 +0000

    build: Emit a warning for build targets run as root
    
    Build targets should generally be run as an unprivileged user.  Even
    though building as root is discouraged many users do so, so just start
    with a warning.
    
    Reviewed by:    brooks
    Differential Revision: https://reviews.freebsd.org/D50352
---
 Makefile.inc1 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Makefile.inc1 b/Makefile.inc1
index c1dd1fe836d3..6a228a29ed5d 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -375,6 +375,10 @@ test-system-${_t}: .PHONY
 .elif ${MK_LLD_BOOTSTRAP} == "yes"
 .info SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.
 .endif
+BUILD_USER!=	id -u
+.if ${BUILD_USER} == 0
+.warning Warning: ${.TARGETS} should not be run as root
+.endif
 .endif
 
 # End WITH_SYSTEM_COMPILER / WITH_SYSTEM_LD