class GnuIndent < Formula
  desc "C code prettifier"
  homepage "https://www.gnu.org/software/indent/"
  url "http://ftpmirror.gnu.org/indent/indent-2.2.13.tar.xz"
  mirror "https://ftp.gnu.org/gnu/indent/indent-2.2.13.tar.xz"
  sha256 "1b81ba4e9a006ca8e6eb5cbbe4cf4f75dfc1fc9301b459aa0d40393e85590a0b"

  bottle do
    sha256 "ceeedf5520df14be36ad8d14d68e29b8ca6da6f427a320546a1331e86306d4c5" => :tiger_altivec
  end

  depends_on "gettext"

  deprecated_option "default-names" => "with-default-names"

  option "with-default-names", "Do not prepend 'g' to the binary"

  def install
    args = %W[
      --disable-dependency-tracking
      --prefix=#{prefix}
      --mandir=#{man}
    ]

    args << "--program-prefix=g" if build.without? "default-names"

    system "./configure", *args
    system "make", "install"
  end

  test do
    (testpath/"test.c").write("int main(){ return 0; }")
    system "#{bin}/gindent", "test.c"
    assert_equal File.read("test.c"), <<-EOS.undent
      int
      main ()
      {
        return 0;
      }
    EOS
  end
end
