View | Details | Raw Unified | Return to bug 268737 | Differences between
and this patch

Collapse All | Expand All

(-)b/Tools/scripts/add-port-to-category-makefile.sh (+48 lines)
Added Link Here
1
#!/bin/sh
2
#
3
# MAINTAINER: yuri@FreeBSD.org
4
5
set -e
6
set -o pipefail
7
8
##
9
## add-port-to-category-makefile.sh: adds a new port to {category}/Makefile
10
##
11
12
PORT="$1"
13
14
15
# sanity checks
16
[ -z "$PORT" ] && echo "this command requires the <port> argument" && exit 1
17
(echo "$PORT" | grep -q "/") && echo "port's name can't contain slash" && exit 1
18
! [ -f Makefile ] && echo "no Makefile found, are you in the ports tree?" && exit 1
19
! grep -q "^    SUBDIR += " Makefile && echo "this command can only be run from the ports tree category directory" && exit 1
20
! grep -q "^\\.include <bsd\\.port\\.subdir\\.mk>$" Makefile && echo "this command can only be run from the ports tree category directory" && exit 1
21
! [ -d "$PORT" ] && echo "the '$PORT' directory is missing" && exit 1
22
! [ -f "$PORT/Makefile" ] && echo "'$PORT/Makefile' is missing" && exit 1
23
grep -q "^    SUBDIR += $PORT$" Makefile && echo "port '$PORT' is already added" && exit 1
24
25
26
# add port to Makefile
27
/usr/bin/awk '
28
BEGIN {
29
	done = 0
30
	seen = 0
31
	str = "    SUBDIR += '$PORT'"
32
}
33
/^    SUBDIR \+= / {
34
	if (!done && str < $0) {
35
		print str
36
		done = 1
37
	}
38
	print $0;
39
	seen = seen + 1
40
}
41
!/^    SUBDIR \+= / {
42
	if (seen > 0 && !done) {
43
		print str
44
		done = 1
45
	}
46
	print $0
47
}' < Makefile > Makefile.new &&
48
/bin/mv Makefile.new Makefile

Return to bug 268737