For those who need to Lint large projects.

For certain reasons, I had to lint a rather large autoconf based project. While running splint *.c is trivial for a small project, things can get rather convoluted with autoconf‘s intervention, notably when it comes to mentioning include directories on the command line.

The (rather obvious) solution I used was to have make invoke a shell-script instead of the C compiler directly and have the script run splint and redirect its output to some temporary file I could later open. Here is the script, just in case anyone else finds it useful:

#!/bin/zsh

splint_args=""
for arg in "$@"; do
	if [[ $arg =~ '(.*.c)|(-I.*)' ]]; then
		splint_args="$arg $splint_args"
	fi
done
if [[ -n $splint_args ]]; then
	$splint_args="$splint_args"
	splint $=splint_args &>> /tmp/splint-output
fi
cc $@

Using the script is easy, instead of ./configure --foo=bar --disable-baz, do a CC=/path/to/script LD=ld ./configure --foo=bar --disable-baz. Also, don’t forget to chmod +x the script. Happy Hacking! 🙂

Advertisements
This entry was posted in Computers and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s