+# On OS X the GnuTLS certtool is prefixed to avoid collision with the system certtool.
+my $certtool = $^O eq 'darwin' ? 'gnutls-certtool' : 'certtool';
+
+# Check whether the user has the required tools installed.
+my $has_gnutls = `$certtool --version v 2>/dev/null`;
+my $has_openssl = !system 'openssl version >/dev/null 2>&1';
+
+# The framework the user has specified.
+my $tool = lc $ARGV[0];
+
+# If the user has not explicitly specified a framework then detect one.
+if ($tool eq 'auto') {
+ if ($has_gnutls) {
+ $tool = 'gnutls';
+ } elsif ($has_openssl) {
+ $tool = 'openssl';
+ } else {
+ say STDERR "SSL generation failed: could not find $certtool or openssl in the PATH!";
+ exit 1;
+ }
+} elsif ($tool eq 'gnutls' && !$has_gnutls) {
+ say STDERR "SSL generation failed: could not find '$certtool' in the PATH!";
+ exit 1;
+} elsif ($tool eq 'openssl' && !$has_openssl) {
+ say STDERR 'SSL generation failed: could not find \'openssl\' in the PATH!';
+ exit 1;
+}
+
+# Harvest information needed to generate the certificate.