<commit_before>class Qwt < Formula
  desc "Qt Widgets for Technical Applications"
  homepage "https://qwt.sourceforge.io/"
  url "https://downloads.sourceforge.net/project/qwt/qwt/6.1.6/qwt-6.1.6.tar.bz2"
  sha256 "99460d31c115ee4117b0175d885f47c2c590d784206f09815dc058fbe5ede1f6"

  license "LGPL-2.1-only" => { with: "Qwt-exception-1.0" }

  bottle do
    sha256 arm64_big_sur: "a3ebfd4004fec1a451a9af3764b92932ac03f9c0f62ecf2d2c38087a8968aaa3"
    sha256 big_sur:       "b703690ba90cdecc05cbbe3681d00d4c5138a341fb67e5d6c3586a0f3fa91ae4"
    sha256 catalina:      "e54a2c2582412a4ac2730dfc9d59b00a98ffce155c1f2fefac78abd266fcdb84"
    sha256 mojave:        "6dffaa9d451b82e5bdd78ae6dea239b3f0e5338677085babe3b2185724b46580"
  end

  depends_on "qt"

  # Update designer plugin linking back to qwt framework/lib after install
  # See: https://sourceforge.net/p/qwt/patches/45/
  patch :DATA

  def install
    inreplace "qwtconfig.pri" do |s|
      s.gsub!(/^\s*QWT_INSTALL_PREFIX\s*=(.*)$/, "QWT_INSTALL_PREFIX=#{prefix}")

      # Install Qt plugin in `lib/qt/plugins/designer`, not `plugins/designer`.
      s.sub! %r{(= \$\$\{QWT_INSTALL_PREFIX\})/(plugins/designer)$},
             "\\1/lib/qt/\\2"
    end

    args = ["-config", "release", "-spec"]
    spec = if ENV.compiler == :clang
      "macx-clang"
    else
      "macx-g++"
    end
    spec << "-arm64" if Hardware::CPU.arm?
    args << spec

    system "qmake", *args
    system "make"
    system "make", "install"
  end

  test do
    (testpath/"test.cpp").write <<~EOS
      #include <qwt_plot_curve.h>
      int main() {
        QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
        return (curve1 == NULL);
      }
    EOS
    system ENV.cxx, "test.cpp", "-o", "out",
      "-std=c++11",
      "-framework", "qwt", "-framework", "QtCore",
      "-F#{lib}", "-F#{Formula["qt"].opt_lib}",
      "-I#{lib}/qwt.framework/Headers",
      "-I#{Formula["qt"].opt_lib}/QtCore.framework/Versions/5/Headers",
      "-I#{Formula["qt"].opt_lib}/QtGui.framework/Versions/5/Headers"
    system "./out"<commit_msg>qwt: change qt to qt@5<commit_after>class Qwt < Formula
  desc "Qt Widgets for Technical Applications"
  homepage "https://qwt.sourceforge.io/"
  url "https://downloads.sourceforge.net/project/qwt/qwt/6.1.6/qwt-6.1.6.tar.bz2"
  sha256 "99460d31c115ee4117b0175d885f47c2c590d784206f09815dc058fbe5ede1f6"
  license "LGPL-2.1-only" => { with: "Qwt-exception-1.0" }
  revision 1

  bottle do
    sha256 arm64_big_sur: "a3ebfd4004fec1a451a9af3764b92932ac03f9c0f62ecf2d2c38087a8968aaa3"
    sha256 big_sur:       "b703690ba90cdecc05cbbe3681d00d4c5138a341fb67e5d6c3586a0f3fa91ae4"
    sha256 catalina:      "e54a2c2582412a4ac2730dfc9d59b00a98ffce155c1f2fefac78abd266fcdb84"
    sha256 mojave:        "6dffaa9d451b82e5bdd78ae6dea239b3f0e5338677085babe3b2185724b46580"
  end

  depends_on "qt@5"

  # Update designer plugin linking back to qwt framework/lib after install
  # See: https://sourceforge.net/p/qwt/patches/45/
  patch :DATA

  def install
    inreplace "qwtconfig.pri" do |s|
      s.gsub!(/^\s*QWT_INSTALL_PREFIX\s*=(.*)$/, "QWT_INSTALL_PREFIX=#{prefix}")

      # Install Qt plugin in `lib/qt/plugins/designer`, not `plugins/designer`.
      s.sub! %r{(= \$\$\{QWT_INSTALL_PREFIX\})/(plugins/designer)$},
             "\\1/lib/qt/\\2"
    end

    args = ["-config", "release", "-spec"]
    spec = if ENV.compiler == :clang
      "macx-clang"
    else
      "macx-g++"
    end
    spec << "-arm64" if Hardware::CPU.arm?
    args << spec

    qt5 = Formula["qt@5"].opt_prefix
    system "#{qt5}/bin/qmake", *args
    system "make"
    system "make", "install"
  end

  test do
    (testpath/"test.cpp").write <<~EOS
      #include <qwt_plot_curve.h>
      int main() {
        QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
        return (curve1 == NULL);
      }
    EOS
    system ENV.cxx, "test.cpp", "-o", "out",
      "-std=c++11",
      "-framework", "qwt", "-framework", "QtCore",
      "-F#{lib}", "-F#{Formula["qt@5"].opt_lib}",
      "-I#{lib}/qwt.framework/Headers",
      "-I#{Formula["qt@5"].opt_lib}/QtCore.framework/Versions/5/Headers",
      "-I#{Formula["qt@5"].opt_lib}/QtGui.framework/Versions/5/Headers"
    system "./out"
{'fraction_non_alphanumeric': 0.1589779985805536, 'fraction_numerical': 0.11189969245327655, 'mean_word_length': 3.219560878243513, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5780823', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1757, 'n_words': 269}