The Wiert Corner – irregular stream of stuff

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

  • My work

  • 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 1,798 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 yourperlprogram.pl

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 – perldoc.perl.org.

perl -d yourperlprogram.pl 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:

–jeroen

via:

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
./Makefile.org:73:MAKEDEPPROG=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:

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

 
%d bloggers like this: