This is an old revision of the document!
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
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