The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,418 other followers

Perl: checking if makedepend is available without using File::Which

Posted by jpluimers on 2016/08/25

Long lasting open source projects often use makedepend to amend Makefiles with C header dependencies.

However, makedepend is old, not available on some systems (like Mac OS X or Windows) and can have different behaviour than the C compiler on those systems. The alternative usually is the -M switch on the C compiler.

In practice, either makedepend, or the alternative is available, so when prepping for a build you have to choose which one to use.

Some of those open source projects use Perl as a bootstrapper. I’ll write more about those boots trappers in the future, but first lets go back to the post title:

First detecting the availability of makedepend from Perl without relying on File::Which which isn’t installed by default on systems having Perl so a gated check-in build like this Travis build fails.

The trick I use is Perl backticks (aka qx) to try and execute makedepend merging the output of both stdout and stderr (using 2>&1 which is available on most shells). If there is no output, then the result is undef which means makedepend is not available.

# http://perldoc.perl.org/perlop.html#Quote-Like-Operators
# ensure to take the stdout and stderror so we get output like this:
# 'makedepend: error: cannot open "Makefile.makedepend"
#'.
my $makedepend_output = `makedepend -f Makefile.makedepend 2>&1`;
if (!$makedepend_output)
{
print "No makedepend executable found on your path.\n";
}
else
{
print "Output of makedepend: '$makedepend_output'.\n";
}

–jeroen

via:

One Response to “Perl: checking if makedepend is available without using File::Which”

  1. […] matching, the main Perl thing was to find if makedepend exists as an executable on the path. I wrote about that before, as the File::Which solution that I started with isn’t available in all Perl […]

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: