2016-04-21 5 views
0

Ich wünsche viele --enable-*/--disable-* Optionen durch so etwas wie zu generieren:AC_ARG_ENABLE in einer m4_foreach_w Schleife: keine Hilfe Zeichenfolge

COMPONENTS([a b c], [yes]) 

wo das zweite Argument des Standardwert der automatischen enable_* variabel ist. Mein erster Versuch war, eine AC_ARG_ENABLE(...) innerhalb einer m4_foreach_w zu schreiben, aber bis jetzt bekomme ich nur die erste Komponente, die im ./configure --help Ausgang erscheint.

Wenn ich handgeschriebene AC_ARG_ENABLE s hinzufüge, funktionieren sie wie üblich.

Unabhängig davon funktionieren die --enable-*/--disable-* Optionen so, wie sie sollten, nur der Hilfetext fehlt.

Hier ist der vollständige Code, um das Problem zu reproduzieren:

AC_INIT([foo], 1.0) 
AM_INIT_AUTOMAKE([foreign]) 

AC_DEFUN([COMPONENTS], 
[ 
    m4_foreach_w([component], [$1], [ 
     AS_ECHO(["Processing [component] component with default enable=$2"]) 
     AC_ARG_ENABLE([component], 
      [AS_HELP_STRING([--enable-[]component], [component] component)], 
      , 
      [enable_[]AS_TR_SH([component])=$2] 
     ) 
    ]) 
    AC_ARG_ENABLE([x], 
     [AS_HELP_STRING([--enable-[]x], [component x])], 
     , 
     [enable_[]AS_TR_SH([x])=$2] 
    ) 
    AC_ARG_ENABLE([y], 
     [AS_HELP_STRING([--enable-[]y], [component y])], 
     , 
     [enable_[]AS_TR_SH([y])=$2] 
    ) 
]) 

COMPONENTS([a b c], [yes]) 

for var in a b c x y; do 
    echo -n "\$enable_$var=" 
    eval echo "\$enable_$var" 
done 
AC_CONFIG_FILES(Makefile) 
AC_OUTPUT 

Und eine leere Makefile.am. Um zu überprüfen, dass die Optionen arbeiten:

$ ./configure --disable-a --disable-b --disable-d --disable-x 
configure: WARNING: unrecognized options: --disable-d 
... 
Processing component a with default enable=yes 
Processing component b with default enable=yes 
Processing component c with default enable=yes 
$enable_a=no 
$enable_b=no 
$enable_c=yes 
$enable_x=no 
$enable_y=yes 

Antwort

0

Nachdem ich um in autoconf Quellen gestoßen, habe ich herausgefunden dies mit dem m4_divert_once Aufruf zu tun hat, bei der Umsetzung von AC_ARG_ENABLE:

# AC_ARG_ENABLE(FEATURE, HELP-STRING, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) 
# ------------------------------------------------------------------------ 
AC_DEFUN([AC_ARG_ENABLE], 
[AC_PROVIDE_IFELSE([AC_PRESERVE_HELP_ORDER], 
[], 
[m4_divert_once([HELP_ENABLE], [[ 
Optional Features: 
    --disable-option-checking ignore unrecognized --enable/--with options 
    --disable-FEATURE  do not include FEATURE (same as --enable-FEATURE=no) 
    --enable-FEATURE[=ARG] include FEATURE [ARG=yes]]])])dnl 
m4_divert_once([HELP_ENABLE], [$2])dnl 
_AC_ENABLE_IF([enable], [$1], [$3], [$4])dnl 
])# AC_ARG_ENABLE 

# m4_divert_once(DIVERSION-NAME, CONTENT) 
# --------------------------------------- 
# Output CONTENT into DIVERSION-NAME once, if not already there. 
# An end of line is appended for free to CONTENT. 
m4_define([m4_divert_once], 
[m4_expand_once([m4_divert_text([$1], [$2])])]) 

ich raten bin dass das HELP-STRING Argument in seiner nicht erweiterten Form gespeichert wird, so dass es nur einmal für alle Komponenten hinzugefügt wird. Sie manuell die AC_HELP_STRING erweitert das tut, was ich will:

AC_DEFUN([COMPONENTS], 
[ 
    m4_foreach_w([comp], [$1], [ 
     AS_ECHO(["Processing component 'comp' with default enable=$2"]) 
     AC_ARG_ENABLE([comp], 
      m4_expand([AS_HELP_STRING([--enable-comp], enable component comp)]), 
      , 
      [enable_[]AS_TR_SH([comp])=$2] 
     ) 
    ]) 
]) 

COMPONENTS([a b c x y], [yes]) 

ich nicht einen Weg, um richtig zu zitieren components so finden konnte, dass es als Zeichenfolge angezeigt wird, nachdem in m4_foreach_w als Schleifenvariable verwendet wird, so dass ich es gerade umbenannt um mir den Ärger zu ersparen.

Verwandte Themen