Sunday, November 5, 2006

Cleaning up after yourself

A few interesting things came up on the .ports mailing list vis-a-vis cleaning up the ports. After you've done a make in the ports, a "work" folder is created. In here, the package is unzipped and then built, so there's a bunch of mostly wasted space, because chances are you don't care about the intermediary files. So if you do a # make clean after you've done the # make install, you'll clean up these temporary files.



But what if you forget to do the make clean? Or you don't normally do it, but at some point you want to clean it all up? JR Lenz posted the following shell script to do this for you:




#!/bin/sh
#
# remove_work.sh
# removes nasty, disk-hogging source code
# and compiled objects from ports tree
#
# J. Ralf Lenz
#

for i in `ls -Ad *`
do
if [ -d /usr/ports/$i ]; then
cd $i
DIR=`pwd`
DESIRED_PATH=/usr/ports/$i
if [ "${DIR}" = "${DESIRED_PATH}" ]; then
for j in `ls -Ad *`
do
if [ -d /usr/ports/$i/$j ]; then
cd /usr/ports/$i/$j
if [ -d /usr/ports/$i/$j/work ]; then
CUR_DIR=`pwd`
echo "Removing ${CUR_DIR}/work..."
rm -rf work
fi
cd /usr/ports/$i
fi
done
cd /usr/ports
fi
fi
done


While this is a usefully informative script, this also does the trick, albeit in a more arbitrary fashion:



# rm -rf /usr/ports/*/*/work


Boom - find all the port subfolders called 'work' and just remove them.



You can also change where the port system puts the work files by defining the WRKDIRPREFIX in /etc/make.conf (you can see other interesting variables for make.conf in the file /usr/ports/Mk/bsd.port.mk). WRKDIRPREFIX is explained thusly:



# WRKDIRPREFIX	- The place to root the temporary working directory
# hierarchy.


So if you don't want it to go into the port subfolder, just set it in /etc/make.conf. So to put the work folders into /usr/obj, add this:



WRKDIRPREFIX=/usr/obj

And, lastly, don't forget the 'portsclean' command. I guess the magic flags for this command would be:



# portsclean -CDLP

I don't see portsclean in the online man pages, so I'm not sure if it is a standard command or came in with some other port. As I generally use portmanager, which I believe does a clean, I don't worry about it. And if I do a make, I do a # make all && make install && make clean command.





1 comment:

  1. Yup, ya never know who might be quoting you!

    ReplyDelete