最近开始学习使用自动工具,并一直在尝试用它制作一个简单的Guile程序。按照本教程,我成功编译了程序,将 .go 文件放入%site-ccache-dir
,将 .scm 文件放入%site-dir
. 但是,本教程旨在制作模块而不是制作可执行文件。只需创建一个指向 .scm 文件的链接%site-dir
并将其放入/usr/bin
就足够了吗?使用自动工具执行此操作的最佳方法是什么?以下是我目前的设置...
guile.am:
moddir=$(datadir)/guile/site/$(GUILE_EFFECTIVE_VERSION)
godir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache
GOBJECTS = $(SOURCES:%.scm=%.go)
nobase_dist_mod_DATA = $(SOURCES) $(NOCOMP_SOURCES)
nobase_go_DATA = $(GOBJECTS)
# Make sure source files are installed first, so that the mtime of
# installed compiled files is greater than that of installed source
# files. See
# <http://lists.gnu.org/archive/html/guile-devel/2010-07/msg00125.html>
# for details.
guile_install_go_files = install-nobase_goDATA
$(guile_install_go_files): install-nobase_dist_modDATA
CLEANFILES = $(GOBJECTS)
GUILE_WARNINGS = -Wunbound-variable -Warity-mismatch -Wformat
SUFFIXES = .scm .go
.scm.go:
$(AM_V_GEN)$(top_builddir)/pre-inst-env $(GUILD) compile $(GUILE_WARNINGS) -o "$@" "$<"
引导程序:
#!/usr/bin/env sh
autoreconf --verbose --install --force
生成文件.am:
include guile.am
SOURCES = \
example-program.scm
EXTRA_DIST = \
bootstrap \
pre-inst-env.in
配置.ac:
AC_INIT([example-program], [0.1])
AC_CONFIG_SRCDIR([example-program.scm])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
GUILE_PKG([2.2])
GUILE_PROGS
if test "x$GUILD" = "x"; then
AC_MSG_ERROR(['guild' binary not found; please check your guile-2.x installation.])
fi
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env])
AC_OUTPUT
pre-inst-env.in:
#!/bin/sh
abs_top_srcdir="`cd "@abs_top_srcdir@" > /dev/null; pwd`"
abs_top_builddir="`cd "@abs_top_builddir@" > /dev/null; pwd`"
GUILE_LOAD_COMPILED_PATH="$abs_top_builddir${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH"
GUILE_LOAD_PATH="$abs_top_builddir:$abs_top_srcdir${GUILE_LOAD_PATH:+:}:$GUILE_LOAD_PATH"
export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH
PATH="$abs_top_builddir:$PATH"
export PATH
exec "$@"
示例程序.scm:
#!/usr/bin/guile \
-e main -s
!#
;;; Functions.
(define count-to-100
(lambda ()
(define my-num 1)
(while (<= my-num 100)
(display my-num)
(newline)
(set! my-num (+ my-num 1)))))
;;; Main.
(define (main args)
(count-to-100))