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,569 other followers

Modifying openssl to build on Mac without makedepend: using cc -M/gcc -M/clang -M

Posted by jpluimers on 2016/09/08

Coping with OpenSSL is frustrating on so many levels. It would be hilarious if not so many depended on it.

The main thing is that there is so much cruft in openssl but nobody seemingly to care enough about copying with that cruft. Though the intentions of the LibreSSL are great and it has far left cruft, it didn’t gain enough ground in the 2+ years it exists.

For me, the biggest problem was that OpenSSL would fail to build on “modern” OS X versions. These lack makedepend which was part of OS X, but got removed somewhere between 2006 and 8.0 in 2012. Luckily, the 2006 post also mentions the alternative: gcc -M.

Actually cc -M or clang -M work just as well as cc symlinks to clang and gcc calls clang with some parameters.

OpenSSL references makedepend in a lot of Makefiles (see list below). The good part is that config and Configure modify the Makefiles so most people use a manual workaround after running Configure or revert to a macports built or other binaries of makedepend or a homebrew formula.

That is not really an automated solution suitable for general use, let alone suitable for Continuous Integration, so I dug a bit deeper: config is a shell script and Configure is a sherl script: a cleverly crafted shell script starting with the below line invoking Perl with the rest of the script. The reason is that #! shebangs need an absolute location which for Perl can vary. A nice discussion on this trick is at Running Under Some Shell which contains a more elaborate how this works:

eval 'exec perl -S $0 ${1+"$@"}'

Drawback of that: syntax highlighting fails in most tools like GitHub, so you’re on your own when modifying and not really experienced in Perl.

Tough luck: I just got started on a quiet Saturday and came up with the solution below.

It took a while to get there. First I added some instrumentation to track what was going on with the MAKEDEPPROG lines which (because of regexes and unfamiliarity with Perl syntax) took some tries.

Perl -c syntax checking came in handy, but note the limitations mentioned at How to check if perl script doesn’t have any compilation errors? – Stack Overflow:

perl -c

Perl -d debugging was very valuable too, which has very different commands than what I am used to, so this page was of great help perldebug –

perl -d parameters

Apart from regex 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 installations.

After the Perl part, make depend would fail. Tracing that down required to see all command-lines that make would execute. This appeared to be a very simple SHELL setting mentioned at Making make print commands before executing when NOT using CMake – Stack Overflow:

make SHELL="/bin/bash -x" target

It revealed that util/domd was the culprit: it filtered out parameters clang would not understand, but only if it was executed as gcc, not as cc. The fix was yet another regex condition:

if expr "$MAKEDEPEND" : '.*gcc' > /dev/null; then

This is the full diff for the solution:

diff –git a/Configure b/Configure
index 5fb57cf..0f62f5d 100755
— a/Configure
+++ b/Configure
@@ -7,6 +7,7 @@ eval 'exec perl -S $0 ${1+"$@"}'
require 5.000;
use strict;
+use File::Which;
# see INSTALL for instructions.
@@ -1674,6 +1675,8 @@ if ($strict_warnings)
+my $makedepend_exe_path = which('makedepend');
open(IN,'<') || die "unable to read$!\n";
unlink("$") || die "unable to remove old $$!\n" if -e "$";
open(OUT,">$") || die "unable to create $$!\n";
@@ -1723,6 +1726,10 @@ while (<IN>)
s/^RANLIB=.*/RANLIB= $ranlib/;
s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/ if $cc eq "gcc";
+ if ($makedepend_exe_path eq "")
+ {
+ s/^MAKEDEPPROG=\s*makedepend.*$/MAKEDEPPROG= \$\(CC\) -v -M/;
+ }
s/^CFLAG=.*$/CFLAG= $cflags/;
s/^PEX_LIBS=.*$/PEX_LIBS= $prelflags/;
diff –git a/util/domd b/util/domd
index bab48cb..4a867c6 100755
— a/util/domd
+++ b/util/domd
@@ -14,7 +14,7 @@ if [ "$MAKEDEPEND" = "" ]; then MAKEDEPEND=makedepend; fi
cp Makefile
# fake the presence of Kerberos
touch $TOP/krb5.h
-if expr "$MAKEDEPEND" : '.*gcc$' > /dev/null; then
+if expr "$MAKEDEPEND" : '.*cc$' > /dev/null; then
while [ $# -gt 0 ]; do
if [ "$1" != "–" ]; then args="$args $1"; fi



makedepend dependencies:

RetinaMBPro1TB:openssl jeroenp$ grep -nrw makedepend .
./crypto/Makefile:12:MAKEDEPPROG= makedepend
./crypto/srp/Makefile:10:MAKEDEPPROG= makedepend
./crypto/ts/Makefile:13:MAKEDEPPROG= makedepend
./demos/tunala/Makefile:36:# Extra dependencies, should really use makedepend
./util/domd:2:# Do a makedepend, only leave out the standard headers
./util/domd:12:if [ "$MAKEDEPEND" = "" ]; then MAKEDEPEND=makedepend; fi

Leave a Reply

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

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