<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13430] CalendarServer/trunk/bin/_build.sh</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13430">13430</a></dd>
<dt>Author</dt> <dd>dre@apple.com</dd>
<dt>Date</dt> <dd>2014-05-03 09:54:05 -0700 (Sat, 03 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add C dependency on OpenSSL, add flexibility to the C dependency resolver function, tweak OpenLDAP config to ignore gnutls</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkbin_buildsh">CalendarServer/trunk/bin/_build.sh</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkbin_buildsh"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/bin/_build.sh (13429 => 13430)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/bin/_build.sh        2014-05-03 16:50:27 UTC (rev 13429)
+++ CalendarServer/trunk/bin/_build.sh        2014-05-03 16:54:05 UTC (rev 13430)
</span><span class="lines">@@ -69,6 +69,39 @@
</span><span class="cx">   fi;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+# openssl/opensslv.h defines its version number as something like 0x0090819fL.
+# Emit an integer representation of this value and return 0, or fail and
+# return 1
+find_openssl_version () {
+  # A small C program to print the hex version as an int.
+  # 'read' exits non-zero on EOF, which is required for heredoc input.
+  # However, bin/develop sets -e, so disable -e temporarily to prevent exit.
+  set +e
+  read -d '' PROG &lt;&lt;EOF
+  #include &lt;stdio.h&gt;
+  #include &lt;openssl/ssl.h&gt;
+  int main(void)
+  {
+    if(printf(&quot;%lu&quot;,OPENSSL_VERSION_NUMBER)) {return 0;}
+    return 1;
+  } 
+EOF
+  set -e
+  error=0
+  # Make an output file for cc, or bail
+  OUT=$(mktemp -t vcheck.XXXX) || return 1
+  # Compile the program, squelching stderr
+  echo &quot;$PROG&quot; | cc -x c -o $OUT - 2&gt; /dev/null
+  if [ $? -eq 0 ] ; then
+    # build succeeded; run the program. If it exits non-zero, set error status
+    ${OUT} || error=1 
+  else
+    # build failed
+    error=1
+  fi
+  rm ${OUT} || echo &quot;Couldn't remove tmp file: ${OUT}&quot;
+  return ${error}
+}
</ins><span class="cx"> 
</span><span class="cx"> # Initialize all the global state required to use this library.
</span><span class="cx"> init_build () {
</span><span class="lines">@@ -328,14 +361,26 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # Declare a dependency on a C project built with autotools.
</span><ins>+# Support for custom configure, prebuild, build, and install commands
+# prebuild_cmd, build_cmd, and install_cmd phases may be skipped by
+# passing the corresponding option with the empty string as the value.
+# By default, do: ./configure --prefix ... ; jmake ; make install
</ins><span class="cx"> c_dependency () {
</span><span class="cx">   local f_hash=&quot;&quot;;
</span><ins>+  local config_cmd=&quot;configure&quot;;
+  local prebuild_cmd=&quot;&quot;;
+  local build_cmd=&quot;jmake&quot;;
+  local install_cmd=&quot;make install&quot;;
</ins><span class="cx"> 
</span><span class="cx">   OPTIND=1;
</span><del>-  while getopts &quot;m:s:&quot; option; do
</del><ins>+  while getopts &quot;m:s:c:p:b:i:&quot; option; do
</ins><span class="cx">     case &quot;${option}&quot; in
</span><span class="cx">       'm') f_hash=&quot;-m ${OPTARG}&quot;; ;;
</span><span class="cx">       's') f_hash=&quot;-s ${OPTARG}&quot;; ;;
</span><ins>+      'c') config_cmd=&quot;${OPTARG}&quot;; ;;
+      'p') prebuild_cmd=&quot;${OPTARG}&quot;; ;;
+      'b') build_cmd=&quot;${OPTARG}&quot;; ;;
+      'i') install_cmd=&quot;${OPTARG}&quot;; ;;
</ins><span class="cx">     esac;
</span><span class="cx">   done;
</span><span class="cx">   shift $((${OPTIND} - 1));
</span><span class="lines">@@ -344,7 +389,7 @@
</span><span class="cx">   local path=&quot;$1&quot;; shift;
</span><span class="cx">   local  uri=&quot;$1&quot;; shift;
</span><span class="cx"> 
</span><del>-  # Extra arguments are processed below, as arguments to './configure'.
</del><ins>+  # Extra arguments are processed below, as arguments to config_cmd.
</ins><span class="cx"> 
</span><span class="cx">   mkdir -p &quot;${dep_sources}&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -369,9 +414,10 @@
</span><span class="cx">     if [ ! -d &quot;${dstroot}&quot; ]; then
</span><span class="cx">       echo &quot;Building ${name}...&quot;;
</span><span class="cx">       cd &quot;${srcdir}&quot;;
</span><del>-      ./configure --prefix=&quot;${dstroot}&quot; &quot;$@&quot;;
-      jmake;
-      jmake install;
</del><ins>+      ./${config_cmd} --prefix=&quot;${dstroot}&quot; &quot;$@&quot;;
+      [ &quot;${prebuild_cmd}&quot; ] &amp;&amp; eval ${prebuild_cmd};
+      [ &quot;${build_cmd}&quot; ] &amp;&amp; eval ${build_cmd};
+      [ &quot;${install_cmd}&quot; ] &amp;&amp; eval ${install_cmd};
</ins><span class="cx">       cd &quot;${wd}&quot;;
</span><span class="cx">     else
</span><span class="cx">       echo &quot;Using built ${name}.&quot;;
</span><span class="lines">@@ -411,7 +457,37 @@
</span><span class="cx"> 
</span><span class="cx">   export C_INCLUDE_PATH=&quot;${c_glue_include}:${C_INCLUDE_PATH:-}&quot;;
</span><span class="cx"> 
</span><ins>+  # The OpenSSL version number is special. Our strategy is to get the integer
+  # value of OPENSSL_VERSION_NUBMER for use in inequality comparison.
</ins><span class="cx">   ruler;
</span><ins>+  buildOpenSSL=1;
+  minSSLVersion=9470367;  # OpenSSL 0.9.8y
+  if find_header openssl/ssl.h; then
+    VER=$(find_openssl_version)
+    if [ ! -z ${VER} ]; then
+      if [ ${VER} -ge ${minSSLVersion} ]; then
+        if &quot;${do_setup}&quot;; then
+          using_system &quot;OpenSSL&quot;;
+        fi;
+        buildOpenSSL=0
+      fi;
+    fi;
+  fi;
+  if [ ${buildOpenSSL} -eq 1 ]; then
+    local v=&quot;0.9.8y&quot;;
+    local n=&quot;openssl&quot;;
+    local p=&quot;${n}-${v}&quot;;
+
+    # use 'config' instead of 'configure'; 'make' instead of 'jmake'.
+    # also pass 'shared' to config to build shared libs.
+    c_dependency -m &quot;47c7fb37f78c970f1d30aa2f9e9e26d8&quot; \
+      -c &quot;config&quot; \
+      -b &quot;make&quot; \
+      &quot;openssl&quot; &quot;${p}&quot; \
+      &quot;http://www.openssl.org/source/${p}.tar.gz&quot; &quot;shared&quot;
+  fi;
+
+  ruler;
</ins><span class="cx">   if find_header ffi.h; then
</span><span class="cx">     using_system &quot;libffi&quot;;
</span><span class="cx">   elif find_header ffi/ffi.h; then
</span><span class="lines">@@ -438,10 +514,14 @@
</span><span class="cx">     local n=&quot;openldap&quot;;
</span><span class="cx">     local p=&quot;${n}-${v}&quot;;
</span><span class="cx"> 
</span><ins>+    # OpenLDAP's configure needs --with-tls=openssl to avoid finding any system
+    # gnutls stuff. Also, we need to run 'make depend' before 'make' to pull in
+    # OpenSSL shared libraries.
</ins><span class="cx">     c_dependency -m &quot;39831848c731bcaef235a04e0d14412f&quot; \
</span><ins>+      -p &quot;make depend&quot; \
</ins><span class="cx">       &quot;OpenLDAP&quot; &quot;${p}&quot; \
</span><span class="cx">       &quot;http://www.openldap.org/software/download/OpenLDAP/${n}-release/${p}.tgz&quot; \
</span><del>-      --disable-bdb --disable-hdb;
</del><ins>+      --disable-bdb --disable-hdb --with-tls=openssl;
</ins><span class="cx">   fi;
</span><span class="cx"> 
</span><span class="cx">   ruler;
</span></span></pre>
</div>
</div>

</body>
</html>