1

我正在使用 C++ 开发一个项目,我希望在该项目中实现添加插件的能力。编译过程由 Autotools 处理。我已经设法将文件结构设置正确,并且编译了主项目和插件,但由于某种原因,运行时省略了插件make install。单独编译和安装插件时,它工作正常。我在这里遗漏了什么,或者为什么没有从顶部文件夹安装插件?

配置.ac

AC_PREREQ(2.58)
AC_INIT([Net Responsibility],[3.1r323],[contact@netresponsibility.com])
AC_SUBST([LIBTOOL_DEPS])
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_SUBDIRS([plugins/defaultReport])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([scripts/m4])
AC_CANONICAL_SYSTEM
AC_LANG([C++])
AC_PREFIX_PROGRAM([make])

AM_INIT_AUTOMAKE([subdir-objects])

LT_PREREQ([2.2])
LT_INIT([shared])


# Checks for programs.
AC_PROG_CXX
AC_PROG_INSTALL

# Checks for header files.
AC_HEADER_STDC


...

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

生成文件.am

# Main library
lib_LTLIBRARIES = libNetResponsibility.la
libNetResponsibility_la_SOURCES = \
      @top_srcdir@/src/MainApplication.cpp\
      ...
libNetResponsibility_la_CPPFLAGS = $(cppFlags)
libNetResponsibility_la_LDFLAGS = -no-undefined $(ldFlags)

# Minimal executable
bin_PROGRAMS = net-responsibility
net_responsibility_SOURCES = @top_srcdir@/src/main.cpp
net_responsibility_LDADD = -lNetResponsibility

dist_pkgdata_DATA = \
      $(top_srcdir)/data/txt.xml\
      $(top_srcdir)/COPYING

dist_pkgdata_SCRIPTS = $(top_srcdir)/scripts/init.d
dist_noinst_SCRIPTS = $(top_srcdir)/scripts/postinst\
      $(top_srcdir)/scripts/prerm

AM_LDFLAGS = -L/usr/local/lib -L/usr/lib
ACLOCAL_AMFLAGS = -I scripts/m4

incDirs = -I$(top_srcdir)/include

ldFlags = -L/usr/local/lib -L/usr/lib

cppFlags = $(incDirs)\
           -DPKGDATADIR='$(pkgdatadir)'\
           -DPKGLIBDIR='$(pkglibdir)'\
           -DDATABASEDIR='$(databasedir)'\
           -DPIDDIR='$(piddir)'\
           @CPPFLAGS@

AM_CXXFLAGS = $(incDirs) @CXXFLAGS@
AM_CPPFLAGS = $(cppFlags)

EXTRA_DIST = $(top_srcdir)/lib $(top_srcdir)/include

SUBDIRS = . plugins/defaultReport

install: install-am postinst

uninstall: prerm uninstall-am postrm

postinst:
    $(top_srcdir)/scripts/postinst $(pkgdatadir) $(initdir)

prerm:
    $(top_srcdir)/scripts/prerm $(pkgdatadir) $(initdir)

postrm:
    rm -f $(piddir)/net-responsibility.pid
    rm -f $(pkgdatadir)/blacklist.xml
    rm -f $(pkgdatadir)/config.xml
    rm -rf $(pkgdatadir)/reports
    rm -f $(databasedir)/net-responsibility.db
    rm -f $(initdir)/net-responsibility

.PHONY: prerm postinst postrm

插件/defaultReport/configure.ac

AC_PREREQ(2.58)
AC_INIT([Net Responsibility Plugin: Default Report],[0.1],[contact@netresponsibility.com])
AC_SUBST([LIBTOOL_DEPS])
AC_SUBST([nrlibdir], ["${libdir}/net-responsibility"])
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_SRCDIR([src/Report.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_LANG([C++])
AC_PREFIX_PROGRAM([make])

AM_INIT_AUTOMAKE([subdir-objects])

LT_PREREQ([2.2])
LT_INIT([shared])

# Checks for programs.
AC_PROG_CXX
AC_PROG_INSTALL

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

插件/defaultReport/Makefile.am

# General settings
ACLOCAL_AMFLAGS = -I m4

ldFlags = -L/usr/local/lib -L/usr/lib

AM_CXXFLAGS = @CXXFLAGS@

# Module specific settings
nrlib_LTLIBRARIES = defaultReport.la
defaultReport_la_SOURCES = \
   src/Report.cpp
defaultReport_la_LDFLAGS = -module -no-undefined $(ldFlags)
defaultReport_la_LIBADD = -lNetResponsibility
defaultReport_la_CPPFLAGS = -I../../include @CPPFLAGS@
4

1 回答 1

2

您需要进行nrlibdir一些不同的设置:

插件/defaultReport/configure.ac

删除这一行:

AC_SUBST([nrlibdir], ["${libdir}/net-responsibility"])

插件/defaultReport/Makefile.am

在之前添加这一行nrlib_LTLIBRARIES

nrlibdir=$(libdir)/net-responsibility

这应该有助于automake正确make install

编辑:这次我真的试过了。除上述更改外 installuninstall删除Makefile.am. 您应该将postinst,prermpostrm目标附加到其他一些安装挂钩上,可能类似于:

install-data-hook:
        $(top_srcdir)/scripts/postinst $(pkgdatadir) $(initdir)

uninstall-local:
        $(top_srcdir)/scripts/prerm $(pkgdatadir) $(initdir)

uninstall-hook:
        rm -f $(piddir)/net-responsibility.pid
        rm -f $(pkgdatadir)/blacklist.xml
        rm -f $(pkgdatadir)/config.xml
        rm -rf $(pkgdatadir)/reports
        rm -f $(databasedir)/net-responsibility.db
        rm -f $(initdir)/net-responsibility

将代替那些目标起作用。

于 2012-06-22T20:56:52.557 回答