summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorYuri Victorovich <yuri@FreeBSD.org>2023-01-16 12:56:41 -0800
committerYuri Victorovich <yuri@FreeBSD.org>2023-01-16 13:07:27 -0800
commit1eba137b81f9c3e322da49764244d17c5c7c59b2 (patch)
tree0894ca657eec531dfe86c0d962563d29d965dd01 /Tools
parentcad/antimony: New port: CAD from a parallel universe (diff)
Tools/scripts: Add add-port-to-category-makefile.sh, command that adds new port to category's Makefile
PR: 268737
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/scripts/add-port-to-category-makefile.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/Tools/scripts/add-port-to-category-makefile.sh b/Tools/scripts/add-port-to-category-makefile.sh
new file mode 100755
index 000000000000..691b21fff996
--- /dev/null
+++ b/Tools/scripts/add-port-to-category-makefile.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# MAINTAINER: yuri@FreeBSD.org
+
+PORT="$1"
+
+set -e
+set -o pipefail
+
+##
+## add-port-to-category-makefile.sh: adds a new port to {category}/Makefile
+##
+
+
+# sanity checks
+[ -z "$PORT" ] && echo "this command requires the <port> argument" && exit 1
+(echo "$PORT" | grep -q "/") && echo "port's name can't contain slash" && exit 1
+! [ -f Makefile ] && echo "no Makefile found, are you in the ports tree?" && exit 1
+! grep -q "^ SUBDIR += " Makefile && echo "this command can only be run from the ports tree category directory" && exit 1
+! grep -q "^\\.include <bsd\\.port\\.subdir\\.mk>$" Makefile && echo "this command can only be run from the ports tree category directory" && exit 1
+! [ -d "$PORT" ] && echo "the '$PORT' directory is missing" && exit 1
+! [ -f "$PORT/Makefile" ] && echo "'$PORT/Makefile' is missing" && exit 1
+grep -q "^ SUBDIR += $PORT$" Makefile && echo "port '$PORT' is already added" && exit 1
+
+
+# add port to Makefile
+/usr/bin/awk '
+BEGIN {
+ done = 0
+ seen = 0
+ str = " SUBDIR += '$PORT'"
+}
+/^ SUBDIR \+= / {
+ if (!done && str < $0) {
+ print str
+ done = 1
+ }
+ print $0;
+ seen = seen + 1
+}
+!/^ SUBDIR \+= / {
+ if (seen > 0 && !done) {
+ print str
+ done = 1
+ }
+ print $0
+}' < Makefile > Makefile.new &&
+/bin/mv Makefile.new Makefile