configure追加--enable-xxx--with-xxxパラメータオプション

2884 ワード

configureに--enable-XXXX,--disable-XXXX,--with-XXXX,--without-XXXXのようなパラメータを生成するにはconfigure.acでAC_を使うARG_ENABLEとAC_ARG_WITHこの2つのマクロ、AC_ARG_ENABLEとAC_ARG_WITH構文は次のとおりです.
AC_ARG_ENABLE(option-name, help-string, action-if-present, action-if-not-present)
AC_ARG_WITH (package, help-string, [action-if-given], [action-if-not-given])

たとえば、次の例です.configureで--enable-debugを追加するとenable_が実行されますdebug=「yes」、そうでない場合enable_debug="no": 
AC_ARG_ENABLE(
	[debug],
	[AS_HELP_STRING([--enable-debug],[enable debugging code and output])],
	[enable_debug="yes"],
	[enable_debug="no"]
)

後でenableによるとdebugこの変数を処理する:makefileを定義する.amマクロ、修正(または定義)makefile.am変数、コードマクロ.
if test "${enable_debug}" = "yes"; then
    #  makefile CFLAGS  ( Makefile.am    )
	CFLAGS="${CFLAGS} -ggdb3 -DDEBUG"

    #  DEBUG_CFLAGS  ( Makefile.am    )
	DEBUG_CFLAGS="-ggdb3 -DDEBUG"
    AC_SUBST([DEBUG_CFLAGS])

    # config.h   ENABLE_DEBUG (       )
	AC_DEFINE(
		[ENABLE_DEBUG],
		[1],
		[Define to 1 if debug should be enabled]
	)
fi

#      makefile ( Makefile.am    )
AM_CONDITIONAL([DEBUG], [test "${enable_debug}" = "yes"])

Makefile.amマクロの使用:
if DEBUG
bin_PROGRAMS = helloworld debug 
debug_SOURCES=src/debug.c 
else
bin_PROGRAMS = helloworld
endif

if DEBUG
helloworld_SOURCES = src/helloworld.c  \
                     src/hello-debug.c
else
helloworld_SOURCES = src/helloworld.c 
endif

パラメータの使用方法は、configureに--disable-pluginsが追加されていない場合、disable_を実行します.plugins=「no」で、後のコンパイルマクロもコードマクロも定義されません.configureに--disable-pluginsまたは--disable-plugins=xxxが追加された場合、パラメータが「yes」でない限り、disable_pluginsは!=「No」はMakefile.amでDISABLEが定義されますPLUGINSマクロ、config.hでDISABLEが定義されますPLUGINSは1です.
AC_ARG_ENABLE(
	[plugins],
	[AS_HELP_STRING([--disable-plugins], [Disable external reparse point
	 plugins for the ntfs-3g FUSE driver])],
	[if test x${enableval} = "xyes"; then disable_plugins="no"; fi],
	[disable_plugins="no"]
)

test "${disable_plugins}" != "no" && AC_DEFINE([DISABLE_PLUGINS], [1], [Define to 1 for disabling reparse plugins])

AM_CONDITIONAL([DISABLE_PLUGINS], [test "${disable_plugins}" != "no"])

AC_ARG_WITHの使い方:
AC_ARG_WITH(pkgconfigdir,
   AS_HELP_STRING([[[--with-pkgconfigdir]]],
      [Use the specified pkgconfig dir (default is libdir/pkgconfig)]),
   [pkgconfigdir=${withval}],
   [pkgconfigdir='${libdir}/pkgconfig'])

AC_SUBST([pkgconfigdir])
AC_MSG_NOTICE([[pkgconfig directory is ${pkgconfigdir}]])

参照先:
大規模プロジェクトはAutomake/Autoconfを使用してコンパイル構成を完了します.https://blog.csdn.net/fd315063004/article/details/7785504
Autotoolsを使用してMakefile学習ノートを生成します.https://geesun.github.io/posts/2015/02/autotool.html