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 (+47 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
! [ -f Makefile ] && echo "no Makefile found, are you in the ports tree?" && exit 1
17
! grep "^    SUBDIR += " Makefile >/dev/null && echo "this command can only be run from the category directory" && exit 1
18
! grep "^\\.include <bsd\\.port\\.subdir\\.mk>$" Makefile >/dev/null && echo "this command can only be run from the category directory" && exit 1
19
[ -z "$PORT" ] && echo "this command requires the <port> argument" && exit 1
20
! [ -d "$PORT" ] && echo "the '$PORT' directory is missing" && exit 1
21
! [ -f "$PORT/Makefile" ] && echo "'$PORT/Makefile' is missing" && exit 1
22
grep "^    SUBDIR += $PORT$" Makefile >/dev/null && echo "port '$PORT' is already added" && exit 1
23
24
25
# add port to Makefile
26
/usr/bin/awk '
27
BEGIN {
28
	done = 0
29
	seen = 0
30
	str = "    SUBDIR += '$PORT'"
31
}
32
/^    SUBDIR \+= / {
33
	if (!done && str < $0) {
34
		print str
35
		done = 1
36
	}
37
	print $0;
38
	seen = seen + 1
39
}
40
!/^    SUBDIR \+= / {
41
	if (seen > 0 && !done) {
42
		print str
43
		done = 1
44
	}
45
	print $0
46
}' < Makefile > Makefile.new &&
47
/bin/mv Makefile.new Makefile

Return to bug 268737