Find dependencies

Continued lines ('\')

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 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


This example is used to refactor the MySQL part from Mk/ to Mk/Uses/

To find all files requiring MySQL, you could use something like

   1 for file in `ag --ignore 'pkg-*' --ignore 'distinfo' --ignore 'patch-*' -l mysql` ; do
   2    perl -pe 's/\\\n/ /' $file \
   3      | grep -iE '(USE_MYSQL|_USE.*mysql)' \
   4      | sed -ne "/[Mm][Yy][Ss][Qq][Ll]/s|^|${file}:|p"
   5 done

Breaking this down

  1. Fast finding in files, limits the number of files that we need to process and many forks
  2. Concatenate continued lines so we can use grep
  3. 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
  4. We want to know what file this appears in, so add it again using sed

More info



193 ports contain USE_MYSQL
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)










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


\([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

BernardSpil/PortingNotes (last edited 2017-05-14 07:55:24 by BernardSpil)