Some ports' Makefiles contain line-continuations making it non-trivial to find dependencies etc.
These lines end in a '\' so an OPT_USE could be on one line whereas the mysql may appear on a different line
To counter this, use
perl -pe 's/\\\n/ /' {} \;
to remove line-continuations.
Finding in (all) files is a lot easier with textproc/the_silver_searcher. To find all relevant files containing references to mysql as a first filter use
ag --ignore 'pkg-*' --ignore 'distinfo' --ignore 'patch-*' mysql
Silver Searcher will perform a case-insensitive search by default
This example is used to refactor the MySQL part from Mk/bsd.databases.mk to Mk/Uses/mysql.mk
To find all files requiring MySQL, you could use something like
for file in `ag --ignore 'pkg-*' --ignore 'distinfo' --ignore 'patch-*' -l mysql` ; do perl -pe 's/\\\n/ /' $file \ | grep -iE '(USE_MYSQL|_USE.*mysql)' \ | sed -ne "/[Mm][Yy][Ss][Qq][Ll]/s|^|${file}:|p" done
Breaking this down
193 ports contain USE_MYSQL
Mk/bsd.databases.mk defines values as client/server/embedded yet only server and embedded are handled specifically, everything else therefor is client
Found in ports: USE_MYSQL=([45]1+|[Yy][Ee][Ss]|client|compat|embedded|server)
| server | 12 |
| embedded | 1 |
| client | 188 |
| total | 201 |
USE_MYSQL=\([ ]*\)server to USES+=\1mysql:server
USE_MYSQL=\([ ]*\)embedded to USES+=\1mysql:embedded
USE_MYSQL=\([ ]*\)([45]1+|[Yy][Ee][Ss]|client|compat) to USES+=\1mysql
Often shown as OPT_USE= mysql=yes
There may already be a OPT_USES= line in the Makefile, take that into account
OPT_USE= [Mm][Yy][Ss][Qq][Ll]=([Yy][Ee][Ss]|client|compat|server
There may be multiple OPT_USE= variables
OPT_USE= MYSQL=client PHP=mysql,pdo_mysql
There's a USE_OFF awell
MYSQLD_USE_OFF= MYSQL=client
\([A-Z_]*\)_USE=\([ ]*\)[Mm][Yy][Ss][Qq][Ll]=[Yy][Ee][Ss] to \1_USES=\2mysql
git diffs need to be transformed to use in ports.
--- a/src/openssl-dtls.c +++ b/openssl-dtls.c
needs to be transformed into
--- src/openssl-dtls.c.orig +++ src/openssl-dtls.c
This can easily be achieved with sed
sed -e 's|^--- a/\(.*\)|--- \1.orig|;s|^+++ b/|+++ |' patch-LibreSSL