class Libtensorflow < Formula desc "C interface for Google's OS library for Machine Intelligence" homepage "https://www.tensorflow.org/" url "https://github.com/tensorflow/tensorflow/archive/v1.4.1.tar.gz" sha256 "1f75e463318419a1b3ae076d5a92697c1d3a85e8377c946a5510b651ff5c0d60" bottle do cellar :any sha256 "cad9bfc243a26c7b9df779ef498808a5f45facc4a08377030df0488c8cfede46" => :high_sierra sha256 "aede64a8eca627fbdfba2527252af5b0debf1a46842a93ef0033cf2afe7c6bac" => :sierra sha256 "2ec1d3fa148c0a5978e59074e412ad97cbdbdd34a929a3670e20d23b34bb02fe" => :el_capitan end depends_on "bazel" => :build depends_on :java => ["1.8", :build] def install cmd = Language::Java.java_home_cmd("1.8") ENV["JAVA_HOME"] = Utils.popen_read(cmd).chomp ENV["PYTHON_BIN_PATH"] = which("python").to_s ENV["CC_OPT_FLAGS"] = "-march=native" ENV["TF_NEED_JEMALLOC"] = "1" ENV["TF_NEED_GCP"] = "0" ENV["TF_NEED_HDFS"] = "0" ENV["TF_ENABLE_XLA"] = "0" ENV["USE_DEFAULT_PYTHON_LIB_PATH"] = "1" ENV["TF_NEED_OPENCL"] = "0" ENV["TF_NEED_CUDA"] = "0" ENV["TF_NEED_MKL"] = "0" ENV["TF_NEED_VERBS"] = "0" ENV["TF_NEED_MPI"] = "0" ENV["TF_NEED_S3"] = "1" ENV["TF_NEED_GDR"] = "0" system "./configure" system "bazel", "build", "--compilation_mode=opt", "--copt=-march=native", "tensorflow:libtensorflow.so" lib.install Dir["bazel-bin/tensorflow/*.so"] (include/"tensorflow/c").install "tensorflow/c/c_api.h" (lib/"pkgconfig/tensorflow.pc").write <<~EOS Name: tensorflow Description: Tensorflow library Version: #{version} Libs: -L#{lib} -ltensorflow Cflags: -I#{include} EOS end test do (testpath/"test.c").write <<~EOS #include #include int main() { printf("%s", TF_Version()); } EOS system ENV.cc, "-L#{lib}", "-ltensorflow", "-o", "test_tf", "test.c" assert_equal version, shell_output("./test_tf") end end