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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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:






Modifying openssl to build on Mac without makedepend: using cc -M/gcc -M/clang -M « The Wiert Corner – irregular stream of stuff said
[…] 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 […]