Path: blob/main/Tools/scripts/add-port-to-category-makefile.sh
16462 views
#!/bin/sh1#2# MAINTAINER: [email protected]34PORT="$1"56set -e7set -o pipefail89export LC_ALL=C1011##12## add-port-to-category-makefile.sh: adds a new port to {category}/Makefile13##141516# sanity checks17[ -z "$PORT" ] && echo "this command requires the <port> argument" && exit 118(echo "$PORT" | grep -q "/") && echo "port's name can't contain slash" && exit 119! [ -f Makefile ] && echo "no Makefile found, are you in the ports tree?" && exit 120! grep -q "^ SUBDIR += " Makefile && echo "this command can only be run from the ports tree category directory" && exit 121! grep -q "^\\.include <bsd\\.port\\.subdir\\.mk>$" Makefile && echo "this command can only be run from the ports tree category directory" && exit 122! [ -d "$PORT" ] && echo "the '$PORT' directory is missing" && exit 123! [ -f "$PORT/Makefile" ] && echo "'$PORT/Makefile' is missing" && exit 124grep -q "^ SUBDIR += $PORT$" Makefile && echo "port '$PORT' is already added" && exit 1252627# add port to Makefile28/usr/bin/awk '29BEGIN {30done = 031seen = 032str = " SUBDIR += '$PORT'"33}34/^ SUBDIR \+= / {35if (!done && str < $0) {36print str37done = 138}39print $0;40seen = seen + 141}42!/^ SUBDIR \+= / {43if (seen > 0 && !done) {44print str45done = 146}47print $048}' < Makefile > Makefile.new &&49/bin/mv Makefile.new Makefile505152