GNU autotools: Debug/Release targets?

后端 未结 4 2253
小蘑菇
小蘑菇 2020-12-12 10:10

I\'ve been looking for this for a while: I\'m currently converting a medium-size program to autotools, coming from an Eclipse-based method (with makefiles)

I\'m alwa

4条回答
  •  温柔的废话
    2020-12-12 10:44

    Another example to configure CFLAGS/CXXFLAGS without editing Makefile.in or Makefile.am. Add this code to your configure.in or configure.ac file:

    test -z "$SED" && SED=sed
    
    AC_ARG_ENABLE([debug],
      [AS_HELP_STRING([--enable-debug],
                      [whether to include debug symbols (default is no)])],
      [enable_debug=$enableval],
      [enable_debug=no]
    )
    
    if test "x$enable_debug" = xyes; then
      dnl Remove all optimization flags from CFLAGS
      changequote({,})
      CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
      CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O[0-9s]*//g'`
    
      CFLAGS=`echo "$CFLAGS" | $SED -e 's/-g[0-9]*//g'`
      CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-g[0-9]*//g'`
      changequote([,])
    
      CFLAGS="$CFLAGS -g -O0"
      CXXFLAGS="$CXXFLAGS -g -O0"
    fi
    
    echo "CFLAGS=$CFLAGS"
    

    Test it:

    $ ./configure --enable-debug | grep CFLAGS
    

提交回复
热议问题