Skip to content

Instantly share code, notes, and snippets.

@gomisc
Last active February 19, 2018 03:41
Show Gist options
  • Select an option

  • Save gomisc/1c0e563746350e63bf6cef9210304523 to your computer and use it in GitHub Desktop.

Select an option

Save gomisc/1c0e563746350e63bf6cef9210304523 to your computer and use it in GitHub Desktop.
libdill HomeBrew formula with optional tls
class Libdill < Formula
desc "Structured concurrency in C"
homepage "http://libdill.org/"
url "https://github.com/sustrik/libdill/archive/2.4.tar.gz"
sha256 "ebef0b53db2312702beb11b2493cbbfb320859a60a44d0bb6aab0132ea83ba73"
bottle do
cellar :any
sha256 "b573af4d120876e43cb3d9e822487658bca0bbcbaec2b4b7061e8e4f7b74068e" => :high_sierra
sha256 "c289a65ded1c77bfa31f624dc6a06de059a8fcda4fc7b2bca9401794bdbf0fa8" => :sierra
sha256 "3f441463cc4aa3699f4f06df389b21703607894678e46b2f79ef235e50147530" => :el_capitan
end
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on "openssl@1.1" => :optional
def install
system "./autogen.sh"
args = %W[
--prefix=#{prefix}
--disable-debug
--disable-dependency-tracking
--disable-silent-rules
]
if build.include? '--with-openssl@1.1'
args << "--enable-tls"
args << "C_INCLUDE_PATH=#{Formula["openssl@1.1"].opt_include}"
args << "CFLAGS=-I#{Formula["openssl@1.1"].opt_include}"
args << "LDFLAGS=-L#{Formula["openssl@1.1"].opt_lib}"
end
system "./configure", *args
system "make", "install"
end
test do
(testpath/"test.c").write <<~EOS
#include <libdill.h>
#include <stdio.h>
#include <stdlib.h>
coroutine void worker(const char *text) {
while(1) {
printf("%s\\n", text);
msleep(now() + random() % 500);
}
}
int main() {
go(worker("Hello!"));
go(worker("World!"));
msleep(now() + 5000);
return 0;
}
EOS
system ENV.cc, "-I#{include}", "-L#{lib}", "-ldill", "-o", "test", "test.c"
system "./test"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment