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