第一个GTK程序:中国农历 之三
第一个GTK程序:中国农历 之三
下面我们开始修改Makefile.am文件,这个文件提供给automake程序,扫描产生Makefile.in文件用的
当前根目录下面,glade-2生成的Makefile.am内容如下:
## Process this file with automake to produce Makefile.in
SUBDIRS = src po
EXTRA_DIST = \
autogen.sh \
lunarcalendar.glade \
lunarcalendar.gladep
install-data-local:
@$(NORMAL_INSTALL)
if test -d $(srcdir)/pixmaps; then \
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/pixmaps; \
for pixmap in $(srcdir)/pixmaps/*; do \
if test -f $$pixmap; then \
$(INSTALL_DATA) $$pixmap $(DESTDIR)$(pkgdatadir)/pixmaps; \
fi \
done \
fi
dist-hook:
if test -d pixmaps; then \
mkdir $(distdir)/pixmaps; \
for pixmap in pixmaps/*; do \
if test -f $$pixmap; then \
cp -p $$pixmap $(distdir)/pixmaps; \
fi \
done \
fi
SUBDIRS定义了自动搜索的两个子目录。目前不需要修改
EXTRA_DIST定义的是当前目录下额外被安装、打包的文件,我们这里不需要打包这些文件,因此删除
另外几个定义的是安装数据文件时的操作,不需要修改。修改后的Makefile.am如下
## Process this file with automake to produce Makefile.in
SUBDIRS = src po
install-data-local:
@$(NORMAL_INSTALL)
if test -d $(srcdir)/pixmaps; then \
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/pixmaps; \
for pixmap in $(srcdir)/pixmaps/*; do \
if test -f $$pixmap; then \
$(INSTALL_DATA) $$pixmap $(DESTDIR)$(pkgdatadir)/pixmaps; \
fi \
done \
fi
dist-hook:
if test -d pixmaps; then \
mkdir $(distdir)/pixmaps; \
for pixmap in pixmaps/*; do \
if test -f $$pixmap; then \
cp -p $$pixmap $(distdir)/pixmaps; \
fi \
done \
fi
然后,我们再打开src目录下的Makefile.am文件
## Process this file with automake to produce Makefile.in
INCLUDES = \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
@PACKAGE_CFLAGS@
bin_PROGRAMS = lunarcalendar
lunarcalendar_SOURCES = \
main.c \
support.c support.h \
interface.c interface.h \
callbacks.c callbacks.h
lunarcalendar_LDADD = @PACKAGE_LIBS@ $(INTLLIBS)
这里面通过bin_PROGRAMS的方式,定义了一个可执行文件为lunarcalendar,然后其源代码为lunarcalendar_SOURCES所定义
lunarcalendar_LDADD定义的是链接lunarcalendar时,额外链接的库文件或链接选项。INCLUDES定义的是编译时的一些编译宏定义
在现在的automake版本中,已经认为这种方式是古老的方式了(估计还是因为这个定义就等于是全局性的了)。
替代的宏定义是如下:
lunarcalendar_CFLAGS = \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
@GTKLUNARCALENDAR_CFLAGS@
lunarcalendar_LDFLAGS = @GTKLUNARCALENDAR_LIBS@
对于lunarcalendar_LDADD,我们删除其中的@PACKAGE_LIBS@,其他暂时保留
修改后的Makefile.am如下:
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = lunarcalendar
lunarcalendar_SOURCES = \
main.c \
support.c support.h \
interface.c interface.h \
callbacks.c callbacks.h
lunarcalendar_CFLAGS = \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
@GTKLUNARCALENDAR_CFLAGS@
lunarcalendar_LDFLAGS = @GTKLUNARCALENDAR_LIBS@
lunarcalendar_LDADD = $(INTLLIBS)
然后,我们在configure.ac中增加一个autoconf调用automake的接口,在AC_INIT之后增加一行AM_INIT_AUTOMAKE
AC_INIT(lunarcalendar, 0.1, eagle_xmw@yahoo.com.cn)
AM_INIT_AUTOMAKE
这时候,我们需要开始准备config.h.in文件了,在根目录下通过执行autoheader生成。
执行完后,会自动config.h.in文件,并自动修改configure.ac中的AC_CONFIG_SRCDIR为config.h.in
生成的config.h.in内容如下:
生成的config.h.in内容
生成config.h.in文件之后,我们就可以开始准备生成configure文件及其配套脚本了。
第一步,根目录下执行aclocal,以生成aclocal.m4
第二步,根目录下执行autoconf,以生成configure
第三步,根目录下执行automake,以生成Makefile.in,这一步会检测当前目录下缺少哪些脚本,通常是缺少install-sh/missing/INSTALL/COPYING/depcomp
automake可以自动拷贝一份过来,只需要带参数-a或者--add-missing即可
这几步的动作,我们可以写到一个脚本自动化执行一下,比如autogen.sh
#! /bin/sh
aclocal || exit $?
autoheader || exit $?
automake -a || exit $?
autoconf || exit $?
到这一步,我们的程序应该可以编译、链接起来了
编译链接后,可执行文件是可以生成了,但会在最后报错,原因是po目录下面没有相应的Makefile文件
这个目录的编译处理就涉及到gettext及多国语言了。
此时的源代码:lunarcalendar.0.0.2.zip