m4/gst.m4: Add
[platform/upstream/gst-common.git] / m4 / gst-feature.m4
1 dnl Perform a check for a feature for GStreamer
2 dnl Richard Boulton <richard-alsa@tartarus.org>
3 dnl Thomas Vander Stichele <thomas@apestaart.org> added useful stuff
4 dnl Last modification: 25/06/2001
5 dnl AG_GST_CHECK_FEATURE(FEATURE-NAME, FEATURE-DESCRIPTION,
6 dnl                   DEPENDENT-PLUGINS, TEST-FOR-FEATURE,
7 dnl                   DISABLE-BY-DEFAULT, ACTION-IF-USE, ACTION-IF-NOTUSE)
8 dnl
9 dnl This macro adds a command line argument to allow the user to enable
10 dnl or disable a feature, and if the feature is enabled, performs a supplied
11 dnl test to check if the feature is available.
12 dnl
13 dnl The test should define HAVE_<FEATURE-NAME> to "yes" or "no" depending
14 dnl on whether the feature is available.
15 dnl
16 dnl The macro will set USE_<FEATURE-NAME> to "yes" or "no" depending on
17 dnl whether the feature is to be used.
18 dnl Thomas changed this, so that when USE_<FEATURE-NAME> was already set
19 dnl to no, then it stays that way.
20 dnl
21 dnl The macro will call AM_CONDITIONAL(USE_<<FEATURE-NAME>, ...) to allow
22 dnl the feature to control what is built in Makefile.ams.  If you want
23 dnl additional actions resulting from the test, you can add them with the
24 dnl ACTION-IF-USE and ACTION-IF-NOTUSE parameters.
25 dnl 
26 dnl FEATURE-NAME        is the name of the feature, and should be in
27 dnl                     purely upper case characters.
28 dnl FEATURE-DESCRIPTION is used to describe the feature in help text for
29 dnl                     the command line argument.
30 dnl DEPENDENT-PLUGINS   lists any plug-ins which depend on this feature.
31 dnl TEST-FOR-FEATURE    is a test which sets HAVE_<FEATURE-NAME> to "yes"
32 dnl                     or "no" depending on whether the feature is
33 dnl                     available.
34 dnl DISABLE-BY-DEFAULT  if "disabled", the feature is disabled by default,
35 dnl                     if any other value, the feature is enabled by default.
36 dnl ACTION-IF-USE       any extra actions to perform if the feature is to be
37 dnl                     used.
38 dnl ACTION-IF-NOTUSE    any extra actions to perform if the feature is not to
39 dnl                     be used.
40 dnl
41 dnl
42 dnl thomas :
43 dnl we also added a history.  
44 dnl GST_PLUGINS_YES will contain all plugins to be built
45 dnl                 that were checked through AG_GST_CHECK_FEATURE
46 dnl GST_PLUGINS_NO will contain those that won't be built
47
48 AC_DEFUN([AG_GST_CHECK_FEATURE],
49 echo
50 AC_MSG_NOTICE(*** checking feature: [$2] ***)
51 if test "x[$3]" != "x"
52 then
53   AC_MSG_NOTICE(*** for plug-ins: [$3] ***)
54 fi
55 [dnl
56 builtin(define, [gst_endisable], ifelse($5, [disabled], [enable], [disable]))dnl
57 dnl if it is set to NO, then don't even consider it for building
58 NOUSE=
59 if test "x$USE_[$1]" = "xno"; then
60   NOUSE="yes"
61 fi
62 AC_ARG_ENABLE(translit([$1], A-Z, a-z),
63   [  ]builtin(format, --%-26s gst_endisable %s, gst_endisable-translit([$1], A-Z, a-z), [$2]ifelse([$3],,,: [$3])),
64   [ case "${enableval}" in
65       yes) USE_[$1]=yes;;
66       no) USE_[$1]=no;;
67       *) AC_MSG_ERROR(bad value ${enableval} for --enable-translit([$1], A-Z, a-z)) ;;
68     esac],
69   [ USE_$1=]ifelse($5, [disabled], [no], [yes]))           dnl DEFAULT
70
71 dnl *** set it back to no if it was preset to no
72 if test "x$NOUSE" = "xyes"; then
73   USE_[$1]="no"
74   AC_MSG_WARN(*** $3 pre-configured not to be built)
75 fi
76 NOUSE=
77
78 dnl *** If it's enabled
79
80 if test x$USE_[$1] = xyes; then
81   dnl save compile variables before the test
82
83   gst_check_save_LIBS=$LIBS
84   gst_check_save_LDFLAGS=$LDFLAGS
85   gst_check_save_CFLAGS=$CFLAGS
86   gst_check_save_CPPFLAGS=$CPPFLAGS
87   gst_check_save_CXXFLAGS=$CXXFLAGS
88
89   HAVE_[$1]=no
90   dnl TEST_FOR_FEATURE
91   $4
92
93   LIBS=$gst_check_save_LIBS
94   LDFLAGS=$gst_check_save_LDFLAGS
95   CFLAGS=$gst_check_save_CFLAGS
96   CPPFLAGS=$gst_check_save_CPPFLAGS
97   CXXFLAGS=$gst_check_save_CXXFLAGS
98
99   dnl If it isn't found, unset USE_[$1]
100   if test x$HAVE_[$1] = xno; then
101     USE_[$1]=no
102   else
103     ifelse([$3], , :, [AC_MSG_NOTICE(*** These plugins will be built: [$3])])
104   fi
105 fi
106 dnl *** Warn if it's disabled or not found
107 if test x$USE_[$1] = xyes; then
108   ifelse([$6], , :, [$6])
109   if test "x$3" != "x"; then
110     GST_PLUGINS_YES="\t[$3]\n$GST_PLUGINS_YES"
111   fi
112   AC_DEFINE(HAVE_[$1], , [support for features: $3])
113 else
114   ifelse([$3], , :, [AC_MSG_NOTICE(*** These plugins will not be built: [$3])])
115   if test "x$3" != "x"; then
116     GST_PLUGINS_NO="\t[$3]\n$GST_PLUGINS_NO"
117   fi
118   ifelse([$7], , :, [$7])
119 fi
120 dnl *** Define the conditional as appropriate
121 AM_CONDITIONAL(USE_[$1], test x$USE_[$1] = xyes)
122 ])
123
124 dnl Use a -config program which accepts --cflags and --libs parameters
125 dnl to set *_CFLAGS and *_LIBS and check existence of a feature.
126 dnl Richard Boulton <richard-alsa@tartarus.org>
127 dnl Last modification: 26/06/2001
128 dnl AG_GST_CHECK_CONFIGPROG(FEATURE-NAME, CONFIG-PROG-FILENAME, MODULES)
129 dnl
130 dnl This check was written for GStreamer: it should be renamed and checked
131 dnl for portability if you decide to use it elsewhere.
132 dnl
133 AC_DEFUN([AG_GST_CHECK_CONFIGPROG],
134 [
135   AC_PATH_PROG([$1]_CONFIG, [$2], no)
136   if test x$[$1]_CONFIG = xno; then
137     [$1]_LIBS=
138     [$1]_CFLAGS=
139     HAVE_[$1]=no
140   else
141     if [$2] --plugin-libs [$3] &> /dev/null; then
142       [$1]_LIBS=`[$2] --plugin-libs [$3]`
143     else
144       [$1]_LIBS=`[$2] --libs [$3]`
145     fi
146     [$1]_CFLAGS=`[$2] --cflags [$3]`
147     HAVE_[$1]=yes
148   fi
149   AC_SUBST([$1]_LIBS)
150   AC_SUBST([$1]_CFLAGS)
151 ])
152
153 dnl Use AC_CHECK_LIB and AC_CHECK_HEADER to do both tests at once
154 dnl sets HAVE_module if we have it
155 dnl Richard Boulton <richard-alsa@tartarus.org>
156 dnl Last modification: 26/06/2001
157 dnl AG_GST_CHECK_LIBHEADER(FEATURE-NAME, LIB NAME, LIB FUNCTION, EXTRA LD FLAGS, 
158 dnl                     HEADER NAME, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
159 dnl
160 dnl This check was written for GStreamer: it should be renamed and checked
161 dnl for portability if you decide to use it elsewhere.
162 dnl
163 AC_DEFUN([AG_GST_CHECK_LIBHEADER],
164 [
165   AC_CHECK_LIB([$2], [$3], HAVE_[$1]=yes, HAVE_[$1]=no,[$4])
166   if test "x$HAVE_[$1]" = "xyes"; then
167     AC_CHECK_HEADER([$5], :, HAVE_[$1]=no)
168     if test "x$HAVE_[$1]" = "xyes"; then
169       dnl execute what needs to be
170       ifelse([$6], , :, [$6])
171     else
172       ifelse([$7], , :, [$7])
173     fi
174   else
175     ifelse([$7], , :, [$7])
176   fi
177   AC_SUBST(HAVE_[$1])
178 ]
179 )
180
181 dnl 2004-02-14 Thomas - changed to get set properly and use proper output
182 dnl 2003-06-27 Benjamin Otte - changed to make this work with gstconfig.h
183 dnl
184 dnl Add a subsystem --disable flag and all the necessary symbols and substitions
185 dnl
186 dnl AG_GST_CHECK_SUBSYSTEM_DISABLE(SYSNAME, [subsystem name])
187 dnl
188 AC_DEFUN([AG_GST_CHECK_SUBSYSTEM_DISABLE],
189 [
190   dnl this define will replace each literal subsys_def occurrence with
191   dnl the lowercase hyphen-separated subsystem
192   dnl e.g. if $1 is GST_DEBUG then subsys_def will be a macro with gst-debug
193   define([subsys_def],translit([$1], _A-Z, -a-z))
194
195   AC_ARG_ENABLE(subsys_def, 
196     AC_HELP_STRING(--disable-subsys_def, [disable $2]),
197     [
198       case "${enableval}" in
199         yes) GST_DISABLE_[$1]=no ;;
200         no) GST_DISABLE_[$1]=yes ;;
201         *) AC_MSG_ERROR([bad value ${enableval} for --enable-subsys_def]) ;;
202        esac
203     ],
204     [GST_DISABLE_[$1]=no]) dnl Default value
205
206   if test x$GST_DISABLE_[$1] = xyes; then
207     AC_MSG_NOTICE([disabled subsystem [$2]])
208     GST_DISABLE_[$1]_DEFINE="#define GST_DISABLE_$1 1" 
209   else
210     GST_DISABLE_[$1]_DEFINE="/* #undef GST_DISABLE_$1 */"
211   fi
212   AC_SUBST(GST_DISABLE_[$1]_DEFINE)
213   undefine([subsys_def])
214 ])
215
216 dnl relies on GST_PLUGINS_ALL, GST_PLUGINS_SELECTED, GST_PLUGINS_YES,
217 dnl GST_PLUGINS_NO, and BUILD_EXTERNAL
218 AC_DEFUN([AG_GST_OUTPUT_PLUGINS], [
219
220 echo "configure: *** Plug-ins without external dependencies that will be built:"
221 ( for i in $GST_PLUGINS_SELECTED; do echo -e '\t'$i; done ) | sort
222 echo
223
224 echo "configure: *** Plug-ins without external dependencies that will NOT be built:"
225 ( for i in $GST_PLUGINS_ALL; do
226     case $GST_PLUGINS_SELECTED in
227       *$i*)
228         ;;
229       *)
230         echo -e '\t'$i
231         ;;
232     esac
233   done ) | sort
234 echo
235
236 if test "x$BUILD_EXTERNAL" = "xno"; then
237   echo "configure: *** No plug-ins with external dependencies will be built"
238 else
239   echo -n "configure: *** Plug-ins with dependencies that will be built:"
240   echo -e "$GST_PLUGINS_YES" | sort
241   echo
242   echo -n "configure: *** Plug-ins with dependencies that will NOT be built:"
243   echo -e "$GST_PLUGINS_NO" | sort
244   echo
245 fi
246 ])
247