2016-04-13 36 views
1

我有一些自定義autoconf宏將由幾個項目共享。我希望有一些AC_ARG_WITH宏取決於該項目,所以它們在./configure -h時不顯示。例如:有條件的AS_ARG_WITH配置

if test $PKG_NAME = proj1; then 
    AC_ARG_WITH(foodir, AC_HELP_STRING([--with-foodir=DIR], 
     [where foo will come from]), 
     foodir=$withval, 
     foodir="") 
fi 

我試過的東西像m4_ifAS_IF,但它不工作。有沒有辦法做到這一點,或者我是SOL?

謝謝!

回答

0

所以我運氣不好,想象一下。我很感興趣,所以試着想出一個解決方案。我以爲這可能是一種可能configure.ac

AC_INIT([Autohell], [0.0.1]) 
AC_PREREQ(2.13) 

AC_ARG_ENABLE([extras],[AC_HELP_STRING([--enable-extras],[Enable extra options])], 
[ 
    AS_CASE([$enable_extras], 
    [yes], 
    [ 
     AC_ARG_ENABLE([foo],[AC_HELP_STRING([--enable-foo],[Enable the Foo])], 
     [ 
      enable_foo=$enableval 
      echo "Foo Enabled" 
     ], 
     [ 
      enable_foo="no" 
      echo "Foo Disabled" 
     ]) 
    ], 
    [ 
     echo "Extras Disabled" 
    ]) 
],enable_extras="no") 

AM_CONDITIONAL([FOO],[test "$enable_foo" = "yes"]) 

cat << EOF 

    Extras: ${enable_extras} 

     Foo: ${enable_foo} 

EOF 

不用說,它沒有工作。既--enable-extras--enable-foo出現在./configure --help和由開關設定的變量是獨立的,檢查出該樣品的輸出:

$ ./configure 

    Extras: no 

     Foo: 

$ ./configure --enable-extras 
Foo Disabled 

    Extras: yes 

     Foo: no 

$ ./configure --enable-extras --enable-foo 
Foo Enabled 

    Extras: yes 

     Foo: yes 

$ ./configure --disable-extras --enable-foo 
Extras Disabled... 

    Extras: no 

     Foo: yes 

輸出是相當有趣的:雖然開關和互補變量代替,條件塊被推崇所以我們真的只能在--enable-foo的時候我們也在--enable-extras