7.文件夹

本系列文章均翻译自Automake官方文档:Automake Manual,github同步项目:question

7.1 递归子文件夹

顶层的Makefile.am必须告诉Automake哪些子文件夹将被构建。通过SUBDIRS变量实现。
当你在顶级目录执行make命令的时候,在所有的子文件夹中也会执行,自定义的规则除外。

note:这些子文件夹中不要求含有Makefile.am文件,只要求含有Makefile文件(after configure)。

默认子文件夹会在当前目录之前构建,可以在任何位置添加.来改变这一顺序。

SUBDIRS = lib src . tests

总是把测试的放在最后。

7.2 条件子文件夹

7.2.1 SUBDIRS vs DIST_SUBDIRS

  • SUBDIRS包含了当前目录下必须构建的子目录。需要手动定义。
  • DIST_SUBDIRS用于需要在所有的目录下递归的规则。
  • ‘make maintainer-clean’, ‘make distclean’ and ‘make dist’规则使用DIST_SUBDIRS,其它规则使用SUBDIRS
  • 如果使用Automake的conditionals定义SUBDIRS,Automake会自动定义DIST_SUBDIRS;如果SUBDIRS包含了AC_SUBST变量,DIST_SUBDIRS需要手动定义。

7.2.2 使用AM_CONDITIONAL定义子目录

举例:

configure
    AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
    AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])

Makefil.am
    if COND_OPT
      MAYBE_OPT = opt
    endif
    SUBDIRS = src $(MAYBE_OPT)

在这种情况下,Automake会自动定义DIST_SUBDIRS = src opt,因为知道在特定的条件下MAYBE_OPT会含有opt

7.2.3 使用AC_SUBST定义子目录

举例:

configure
    if test "$want_opt" = yes; then
      MAYBE_OPT=opt
    else
      MAYBE_OPT=
    fi
    AC_SUBST([MAYBE_OPT])
    AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])

Makefil.am
    SUBDIRS = src $(MAYBE_OPT)
    DIST_SUBDIRS = src opt

Automake不能猜测MAYBE_OPT的值是什么,需要手动定义DIST_SUBDIRS

7.4 嵌套包

嵌套的包目录应该也在SUBDIRS中列出。子包的Makefile应该由自己的configure脚本生成,而不是父包的configure。通过使用AC_CONFIG_SUBDIRS达到这一目的。

arm’s configure.ac:
    
    AC_INIT([arm], [1.0])
    AC_CONFIG_AUX_DIR([.])
    AM_INIT_AUTOMAKE
    AC_PROG_CC
    AC_CONFIG_FILES([Makefile])
    # Call hand's ./configure script recursively.
    AC_CONFIG_SUBDIRS([hand])
    AC_OUTPUT

arm’s Makefile.am:
    
    # Build the library in the hand subdirectory first.
    SUBDIRS = hand

    # Include hand's header when compiling this directory.
    AM_CPPFLAGS = -I$(srcdir)/hand

    bin_PROGRAMS = arm
    arm_SOURCES = arm.c
    # link with the hand library.
    arm_LDADD = hand/libhand.a

猜你喜欢

转载自blog.csdn.net/SHRINKSHR/article/details/85838595
今日推荐