首先準備好 GTK+ 的 Vala 原始碼檔案 MyApp.vala
using Gtk;
namespace ValaTutorial
{
class MyApp : Gtk.Window
{
public MyApp ()
{
var button = new Button.with_label ("Click me!");
add (button);
button.clicked.connect (on_clicked);
}
private void on_clicked (Gtk.Button button)
{
stdout.printf ("Ouch!\n");
}
public static int main (string[] args)
{
Gtk.init (ref args);
var app = new MyApp ();
app.show_all ();
app.destroy.connect (Gtk.main_quit);
Gtk.main ();
return 0;
}
}
}
然後再準備一個 Makefile.am# AM_VALAFLAGS = --pkg gtk+-2.0 bin_PROGRAMS = MyApp MyApp_SOURCES = MyApp.vala MyApp_CPPFLAGS = @GTK_CFLAGS@ MyApp_LDFLAGS = @GTK_LIBS@ MyApp_VALAFLAGS = --pkg gtk+-2.0第 1,8 行是 Vala 使用外部函式庫時需要的參數,視實際需求選擇使用
效果相當於
$ valac --pkg gtk+2.0 MyApp.vala最後是自動產生並修改過後的 configure.ac
# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.65]) AC_INIT([hello], [0.0], [foo@bar.com]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) # Checks for programs. AC_PROG_CC AM_PROG_VALAC([0.8.0]) # Checks for libraries. AM_PATH_GTK_2_0 # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_CONFIG_FILES([Makefile]) AC_OUTPUT第 14 行會產生出 Makefile.am 所需要的 @GTK_CFLAGS@ 及 @GTK_LIBS@
最後就是一般 GNU Build System 慣用的指令
$ autoreconf -if $ ./configure $ make參考資料:
沒有留言:
張貼留言