====== Find dependencies ======
=== Continued lines ('\') ===
Some ports' ''%%Makefile%%''s 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 files ===
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
=== Example ===
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
- Fast finding in files, limits the number of files that we need to process and many forks
- Concatenate continued lines so we can use grep
- Depenencies come in two forms that we need to find (USE_MYSQL and OPT_USE are always caps but the latter allows for mixed case values) - USE_MYSQL= boolean:option - OPT_USE= mysql=option
- We want to know what file this appears in, so add it again using sed
=== More info ===
https://people.freebsd.org/~ak/gettext/
====== Mk/Uses/mysql.mk ======
==== USE_MYSQL ====
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 |
=== Transformations ===
''%%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%%''
==== OPT_USE= mysql ====
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%%''
=== Transformations ===
\([A-Z_]*\)_USE=\([ ]*\)[Mm][Yy][Ss][Qq][Ll]=[Yy][Ee][Ss] to \1_USES=\2mysql
==== Convert git diff ====
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