1class Gtkx3 < Formula
2  desc "Toolkit for creating graphical user interfaces"
3  homepage "http://gtk.org/"
4  url "https://download.gnome.org/sources/gtk+/3.20/gtk+-3.20.5.tar.xz"
5  sha256 "9790b0267384904ad8a08e7f16e5f9ff1c4037de57788d48d1eaf528355b1564"
6
7  option :universal
8  option "with-quartz-relocation", "Build with quartz relocation support"
9
10  depends_on "pkg-config" => :build
11  depends_on "gnome/gitg/gdk-pixbuf"
12  depends_on "jasper" => :optional
13  depends_on "gnome/gitg/atk"
14  depends_on "gnome/gitg/gobject-introspection"
15  depends_on "libepoxy"
16  depends_on "gnome/gitg/gsettings-desktop-schemas" => :recommended
17  depends_on "gnome/gitg/pango"
18  depends_on "gnome/gitg/glib"
19  depends_on "hicolor-icon-theme"
20
21  def install
22    ENV.universal_binary if build.universal?
23
24    args = %W[
25      --enable-debug
26      --disable-dependency-tracking
27      --prefix=#{prefix}
28      --disable-glibtest
29      --enable-introspection=yes
30      --disable-schemas-compile
31      --enable-quartz-backend
32      --disable-x11-backend
33    ]
34
35    args << "--enable-quartz-relocation" if build.with?("quartz-relocation")
36
37    system "./configure", *args
38    # necessary to avoid gtk-update-icon-cache not being found during make install
39    bin.mkpath
40    ENV.prepend_path "PATH", "#{bin}"
41
42    system "make", "install"
43    # Prevent a conflict between this and Gtk+2
44    mv bin/"gtk-update-icon-cache", bin/"gtk3-update-icon-cache"
45  end
46
47  def post_install
48    system "#{Formula["glib"].opt_bin}/glib-compile-schemas", "#{HOMEBREW_PREFIX}/share/glib-2.0/schemas"
49  end
50
51  test do
52    (testpath/"test.c").write <<-EOS.undent
53      #include <gtk/gtk.h>
54
55      int main(int argc, char *argv[]) {
56        gtk_disable_setlocale();
57        return 0;
58      }
59    EOS
60    atk = Formula["atk"]
61    cairo = Formula["cairo"]
62    fontconfig = Formula["fontconfig"]
63    freetype = Formula["freetype"]
64    gdk_pixbuf = Formula["gdk-pixbuf"]
65    gettext = Formula["gettext"]
66    glib = Formula["glib"]
67    libepoxy = Formula["libepoxy"]
68    libpng = Formula["libpng"]
69    pango = Formula["pango"]
70    pixman = Formula["pixman"]
71    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
72    flags += %W[
73      -I#{atk.opt_include}/atk-1.0
74      -I#{cairo.opt_include}/cairo
75      -I#{fontconfig.opt_include}
76      -I#{freetype.opt_include}/freetype2
77      -I#{gdk_pixbuf.opt_include}/gdk-pixbuf-2.0
78      -I#{gettext.opt_include}
79      -I#{glib.opt_include}/gio-unix-2.0/
80      -I#{glib.opt_include}/glib-2.0
81      -I#{glib.opt_lib}/glib-2.0/include
82      -I#{include}
83      -I#{include}/gtk-3.0
84      -I#{libepoxy.opt_include}
85      -I#{libpng.opt_include}/libpng16
86      -I#{pango.opt_include}/pango-1.0
87      -I#{pixman.opt_include}/pixman-1
88      -D_REENTRANT
89      -L#{atk.opt_lib}
90      -L#{cairo.opt_lib}
91      -L#{gdk_pixbuf.opt_lib}
92      -L#{gettext.opt_lib}
93      -L#{glib.opt_lib}
94      -L#{lib}
95      -L#{pango.opt_lib}
96      -latk-1.0
97      -lcairo
98      -lcairo-gobject
99      -lgdk-3
100      -lgdk_pixbuf-2.0
101      -lgio-2.0
102      -lglib-2.0
103      -lgobject-2.0
104      -lgtk-3
105      -lintl
106      -lpango-1.0
107      -lpangocairo-1.0
108    ]
109    system ENV.cc, "test.c", "-o", "test", *flags
110    system "./test"
111  end
112end
113