renatofilho@610: dnl Perform a check for a feature for GStreamer
renatofilho@610: dnl Richard Boulton <richard-alsa@tartarus.org>
renatofilho@610: dnl Thomas Vander Stichele <thomas@apestaart.org> added useful stuff
renatofilho@610: dnl Last modification: 25/06/2001
renatofilho@610: dnl GST_CHECK_FEATURE(FEATURE-NAME, FEATURE-DESCRIPTION,
renatofilho@610: dnl                   DEPENDENT-PLUGINS, TEST-FOR-FEATURE,
renatofilho@610: dnl                   DISABLE-BY-DEFAULT, ACTION-IF-USE, ACTION-IF-NOTUSE)
renatofilho@610: dnl
renatofilho@610: dnl This macro adds a command line argument to enable the user to enable
renatofilho@610: dnl or disable a feature, and if the feature is enabled, performs a supplied
renatofilho@610: dnl test to check if the feature is available.
renatofilho@610: dnl
renatofilho@610: dnl The test should define HAVE_<FEATURE-NAME> to "yes" or "no" depending
renatofilho@610: dnl on whether the feature is available.
renatofilho@610: dnl
renatofilho@610: dnl The macro will set USE_<FEATURE-NAME> to "yes" or "no" depending on
renatofilho@610: dnl whether the feature is to be used.
renatofilho@610: dnl Thomas changed this, so that when USE_<FEATURE-NAME> was already set
renatofilho@610: dnl to no, then it stays that way.
renatofilho@610: dnl
renatofilho@610: dnl The macro will call AM_CONDITIONAL(USE_<<FEATURE-NAME>, ...) to allow
renatofilho@610: dnl the feature to control what is built in Makefile.ams.  If you want
renatofilho@610: dnl additional actions resulting from the test, you can add them with the
renatofilho@610: dnl ACTION-IF-USE and ACTION-IF-NOTUSE parameters.
renatofilho@610: dnl 
renatofilho@610: dnl FEATURE-NAME        is the name of the feature, and should be in
renatofilho@610: dnl                     purely upper case characters.
renatofilho@610: dnl FEATURE-DESCRIPTION is used to describe the feature in help text for
renatofilho@610: dnl                     the command line argument.
renatofilho@610: dnl DEPENDENT-PLUGINS   lists any plugins which depend on this feature.
renatofilho@610: dnl TEST-FOR-FEATURE    is a test which sets HAVE_<FEATURE-NAME> to "yes"
renatofilho@610: dnl                     or "no" depending on whether the feature is
renatofilho@610: dnl                     available.
renatofilho@610: dnl DISABLE-BY-DEFAULT  if "disabled", the feature is disabled by default,
renatofilho@610: dnl                     if any other value, the feature is enabled by default.
renatofilho@610: dnl ACTION-IF-USE       any extra actions to perform if the feature is to be
renatofilho@610: dnl                     used.
renatofilho@610: dnl ACTION-IF-NOTUSE    any extra actions to perform if the feature is not to
renatofilho@610: dnl                     be used.
renatofilho@610: dnl
renatofilho@610: dnl
renatofilho@610: dnl thomas :
renatofilho@610: dnl we also added a history.  
renatofilho@610: dnl GST_PLUGINS_YES will contain all plugins to be built
renatofilho@610: dnl                 that were checked through GST_CHECK_FEATURE
renatofilho@610: dnl GST_PLUGINS_NO will contain those that won't be built
renatofilho@610: 
renatofilho@610: AC_DEFUN([GST_CHECK_FEATURE],
renatofilho@610: AC_MSG_NOTICE(***)
renatofilho@610: AC_MSG_NOTICE(*** checking plugin: [$3] ***)
renatofilho@610: AC_MSG_NOTICE(***)
renatofilho@610: [dnl
renatofilho@610: builtin(define, [gst_endisable], ifelse($5, [disabled], [enable], [disable]))dnl
renatofilho@610: dnl if it is set to NO, then don't even consider it for building
renatofilho@610: NOUSE=
renatofilho@610: if test "x$USE_[$1]" = "xno"; then
renatofilho@610:   NOUSE="yes"
renatofilho@610: fi
renatofilho@610: AC_ARG_ENABLE(translit([$1], A-Z, a-z),
renatofilho@610:   [  ]builtin(format, --%-26s gst_endisable %s, gst_endisable-translit([$1], A-Z, a-z), [$2]ifelse([$3],,,: [$3])),
renatofilho@610:   [ case "${enableval}" in
renatofilho@610:       yes) USE_[$1]=yes;;
renatofilho@610:       no) USE_[$1]=no;;
renatofilho@610:       *) AC_MSG_ERROR(bad value ${enableval} for --enable-translit([$1], A-Z, a-z)) ;;
renatofilho@610:     esac],
renatofilho@610:   [ USE_$1=]ifelse($5, [disabled], [no], [yes]))           dnl DEFAULT
renatofilho@610: 
renatofilho@610: dnl *** set it back to no if it was preset to no
renatofilho@610: if test "x$NOUSE" = "xyes"; then
renatofilho@610:   USE_[$1]="no"
renatofilho@610:   AC_MSG_WARN(*** $3 pre-configured not to be built)
renatofilho@610: fi
renatofilho@610: NOUSE=
renatofilho@610: 
renatofilho@610: dnl *** If it's enabled
renatofilho@610: 
renatofilho@610: if test x$USE_[$1] = xyes; then
renatofilho@610:   dnl save compile variables before the test
renatofilho@610: 
renatofilho@610:   gst_check_save_LIBS=$LIBS
renatofilho@610:   gst_check_save_LDFLAGS=$LDFLAGS
renatofilho@610:   gst_check_save_CFLAGS=$CFLAGS
renatofilho@610:   gst_check_save_CPPFLAGS=$CPPFLAGS
renatofilho@610:   gst_check_save_CXXFLAGS=$CXXFLAGS
renatofilho@610: 
renatofilho@610:   HAVE_[$1]=no
renatofilho@610:   dnl TEST_FOR_FEATURE
renatofilho@610:   $4
renatofilho@610: 
renatofilho@610:   LIBS=$gst_check_save_LIBS
renatofilho@610:   LDFLAGS=$gst_check_save_LDFLAGS
renatofilho@610:   CFLAGS=$gst_check_save_CFLAGS
renatofilho@610:   CPPFLAGS=$gst_check_save_CPPFLAGS
renatofilho@610:   CXXFLAGS=$gst_check_save_CXXFLAGS
renatofilho@610: 
renatofilho@610:   dnl If it isn't found, unset USE_[$1]
renatofilho@610:   if test x$HAVE_[$1] = xno; then
renatofilho@610:     USE_[$1]=no
renatofilho@610:   fi
renatofilho@610: fi
renatofilho@610: dnl *** Warn if it's disabled or not found
renatofilho@610: if test x$USE_[$1] = xyes; then
renatofilho@610:   ifelse([$6], , :, [$6])
renatofilho@610:   if test "x$3" != "x"; then
renatofilho@610:     GST_PLUGINS_YES="\t[$3]\n$GST_PLUGINS_YES"
renatofilho@610:   fi
renatofilho@610:   AC_DEFINE(HAVE_[$1], , [support for features: $3])
renatofilho@610: else
renatofilho@610:   ifelse([$3], , :, [AC_MSG_NOTICE(*** These plugins will not be built: [$3])])
renatofilho@610:   if test "x$3" != "x"; then
renatofilho@610:     GST_PLUGINS_NO="\t[$3]\n$GST_PLUGINS_NO"
renatofilho@610:   fi
renatofilho@610:   ifelse([$7], , :, [$7])
renatofilho@610: fi
renatofilho@610: dnl *** Define the conditional as appropriate
renatofilho@610: AM_CONDITIONAL(USE_[$1], test x$USE_[$1] = xyes)
renatofilho@610: ])
renatofilho@610: 
renatofilho@610: dnl Use a -config program which accepts --cflags and --libs parameters
renatofilho@610: dnl to set *_CFLAGS and *_LIBS and check existence of a feature.
renatofilho@610: dnl Richard Boulton <richard-alsa@tartarus.org>
renatofilho@610: dnl Last modification: 26/06/2001
renatofilho@610: dnl GST_CHECK_CONFIGPROG(FEATURE-NAME, CONFIG-PROG-FILENAME, MODULES)
renatofilho@610: dnl
renatofilho@610: dnl This check was written for GStreamer: it should be renamed and checked
renatofilho@610: dnl for portability if you decide to use it elsewhere.
renatofilho@610: dnl
renatofilho@610: AC_DEFUN([GST_CHECK_CONFIGPROG],
renatofilho@610: [
renatofilho@610:   AC_PATH_PROG([$1]_CONFIG, [$2], no)
renatofilho@610:   if test x$[$1]_CONFIG = xno; then
renatofilho@610:     [$1]_LIBS=
renatofilho@610:     [$1]_CFLAGS=
renatofilho@610:     HAVE_[$1]=no
renatofilho@610:   else
renatofilho@610:     if [$2] --plugin-libs [$3] &> /dev/null; then
renatofilho@610:       [$1]_LIBS=`[$2] --plugin-libs [$3]`
renatofilho@610:     else
renatofilho@610:       [$1]_LIBS=`[$2] --libs [$3]`
renatofilho@610:     fi
renatofilho@610:     [$1]_CFLAGS=`[$2] --cflags [$3]`
renatofilho@610:     HAVE_[$1]=yes
renatofilho@610:   fi
renatofilho@610:   AC_SUBST([$1]_LIBS)
renatofilho@610:   AC_SUBST([$1]_CFLAGS)
renatofilho@610: ])
renatofilho@610: 
renatofilho@610: dnl Use AC_CHECK_LIB and AC_CHECK_HEADER to do both tests at once
renatofilho@610: dnl sets HAVE_module if we have it
renatofilho@610: dnl Richard Boulton <richard-alsa@tartarus.org>
renatofilho@610: dnl Last modification: 26/06/2001
renatofilho@610: dnl GST_CHECK_LIBHEADER(FEATURE-NAME, LIB NAME, LIB FUNCTION, EXTRA LD FLAGS, 
renatofilho@610: dnl                     HEADER NAME, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
renatofilho@610: dnl
renatofilho@610: dnl This check was written for GStreamer: it should be renamed and checked
renatofilho@610: dnl for portability if you decide to use it elsewhere.
renatofilho@610: dnl
renatofilho@610: AC_DEFUN([GST_CHECK_LIBHEADER],
renatofilho@610: [
renatofilho@610:   AC_CHECK_LIB([$2], [$3], HAVE_[$1]=yes, HAVE_[$1]=no,[$4])
renatofilho@610:   if test "x$HAVE_[$1]" = "xyes"; then
renatofilho@610:     AC_CHECK_HEADER([$5], :, HAVE_[$1]=no)
renatofilho@610:     if test "x$HAVE_[$1]" = "xyes"; then
renatofilho@610:       dnl execute what needs to be
renatofilho@610:       ifelse([$6], , :, [$6])
renatofilho@610:     else
renatofilho@610:       ifelse([$7], , :, [$7])
renatofilho@610:     fi
renatofilho@610:   else
renatofilho@610:     ifelse([$7], , :, [$7])
renatofilho@610:   fi
renatofilho@610:   AC_SUBST(HAVE_[$1])
renatofilho@610: ]
renatofilho@610: )
renatofilho@610: 
renatofilho@610: dnl 2004-02-14 Thomas - changed to get set properly and use proper output
renatofilho@610: dnl 2003-06-27 Benjamin Otte - changed to make this work with gstconfig.h
renatofilho@610: dnl
renatofilho@610: dnl Add a subsystem --disable flag and all the necessary symbols and substitions
renatofilho@610: dnl
renatofilho@610: dnl GST_CHECK_SUBSYSTEM_DISABLE(SYSNAME, [subsystem name])
renatofilho@610: dnl
renatofilho@610: AC_DEFUN([GST_CHECK_SUBSYSTEM_DISABLE],
renatofilho@610: [
renatofilho@610:   dnl this define will replace each literal subsys_def occurrence with
renatofilho@610:   dnl the lowercase hyphen-separated subsystem
renatofilho@610:   dnl e.g. if $1 is GST_DEBUG then subsys_def will be a macro with gst-debug
renatofilho@610:   define([subsys_def],translit([$1], _A-Z, -a-z))
renatofilho@610: 
renatofilho@610:   AC_ARG_ENABLE(subsys_def, 
renatofilho@610:     AC_HELP_STRING(--disable-subsys_def, [disable $2]),
renatofilho@610:     [
renatofilho@610:       case "${enableval}" in
renatofilho@610:         yes) GST_DISABLE_[$1]=no ;;
renatofilho@610:         no) GST_DISABLE_[$1]=yes ;;
renatofilho@610:         *) AC_MSG_ERROR([bad value ${enableval} for --enable-subsys_def]) ;;
renatofilho@610:        esac
renatofilho@610:     ],
renatofilho@610:     [GST_DISABLE_[$1]=no]) dnl Default value
renatofilho@610: 
renatofilho@610:   if test x$GST_DISABLE_[$1] = xyes; then
renatofilho@610:     AC_MSG_NOTICE([disabled subsystem [$2]])
renatofilho@610:     GST_DISABLE_[$1]_DEFINE="#define GST_DISABLE_$1 1" 
renatofilho@610:   else
renatofilho@610:     GST_DISABLE_[$1]_DEFINE="/* #undef GST_DISABLE_$1 */"
renatofilho@610:   fi
renatofilho@610:   AC_SUBST(GST_DISABLE_[$1]_DEFINE)
renatofilho@610:   undefine([subsys_def])
renatofilho@610: ])
renatofilho@610: 
renatofilho@610: