如何在libdir的子目录中使用autotools安装lua模块

我编写了一个小 lua 模块,使用 autotools 编译,并且我希望修改它的组织结构:

现在在主目录中有这个:

autogen.sh
configure.ac
Makefile.am
src
    file1.c
    file2.c
    file3.c

其中 autogen.sh

 #!/bin/sh
 echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1
 echo "Running libtoolize..."; libtoolize --copy --automake || exit 1;
 echo "Running autoheader..." ; autoheader || exit 1
 echo "Running autoconf..." ; autoconf || exit 1
 echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
 ./configure "$@"

其中 configure.ac

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([lua-clangc], [0.0.1], [cedlemo@gmx.com])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC(clang gcc)
# Checks for libraries.
PKG_CHECK_MODULES([DEPS], [lua])
#LUA_VERSION = $(pkg-config --version)
#AC_SUBST([LUA_VERSION])
# Checks for header files.
AC_CHECK_HEADERS([string.h stdlib.h clang-c/Index.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AM_INIT_AUTOMAKE(1.13 dist-bzip2 foreign subdir-objects)
LT_PREREQ(2.4)
LT_INIT
AC_CONFIG_FILES([
  Makefile
])
AC_OUTPUT

其中 Makefile.am

MAINTAINERCLEANFILES = \
Makefile.in aclocal.m4 config.h.in configure \
depcomp install-sh missing compile config.sub \
config.guess ltmain.sh compile

lib_LTLIBRARIES = src/clangc.la
src_clangc_la_SOURCES = src/clangc.c src/indexlib.c src/translationunitlib.c src/constants.c src/clangc_module_functions.c
src_clangc_la_LDFLAGS = -module -avoid-version -shared -llua -lm -lclang -fPIC

我使用以下命令编译和安装 lua 模块:

./autogen.sh --libdir=/usr/lib/lua/5.3
make
sudo make install

我的文件安装在 /usr/lib/lua/5.3 中

/usr/lib/lua/5.3/clangc.so
/usr/lib/lua/5.3/clangc.la

我想只使用以下命令:

./autogen.sh --prefix=/usr

并且 configure.ac 脚本像这样构建 libdir:

libdir=prefix + /lib/lua/ + LUA_VERSION + /clangc/

(我已经有一个方法在 configure.ac 中获取 LUA_VERSION)

点赞
用户1002965
用户1002965

如常我回答自己:

我只需要修改我的 configure.ac:

AC_PREREQ([2.69])
AC_INIT([lua-clangc], [0.0.1], [cedlemo@gmx.com])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_HEADERS([config.h])

# 检查程序。
AC_PROG_CC(clang gcc)

# 检查库。
PKG_CHECK_MODULES([DEPS], [lua])
LUA_VERSION=$(pkg-config --modversion lua | awk -F "." '{print $1"."$2}')
AC_SUBST([LUA_VERSION])

libdir=$prefix/lib/lua/$LUA_VERSION/clangc
# 检查头文件。
AC_CHECK_HEADERS([string.h stdlib.h clang-c/Index.h])

# 检查 typedefs、structures 和编译器特性。

# 检查库函数。
AM_INIT_AUTOMAKE(1.13 dist-bzip2 foreign subdir-objects)
LT_PREREQ(2.4)
LT_INIT
AC_CONFIG_FILES([
  Makefile
])
AC_OUTPUT

首先我需要找到当前的 lua 版本:

LUA_VERSION=$(pkg-config --modversion lua | awk -F "." '{print $1"."$2}')

在我的系统上:

  • pkg-config --modversion lua 返回 5.3.1
  • awk -F "." '{print $1"."$2}' 返回 5.3

接着这行代码:

libdir=$prefix/lib/lua/$LUA_VERSION/clangc

做了所有的魔术。

当我使用:

./autogen.sh --prefix=/usr

我的库被安装在:

/usr/lib/lua/5.3/clangc
2015-07-16 17:25:04