Fixes to properly conditionally compile architecture-dependent code
[platform/upstream/gstreamer.git] / gstreamer.m4
1 dnl Configure paths for GStreamer
2 dnl This was based upon the glib.m4 created by Owen Taylor 97-11-3
3 dnl Changes mostly involve replacing GLIB with GStreamer
4 dnl
5 dnl Written by Thomas Nyberg <thomas.nyberg@codefactory.se> 2001-03-01
6
7 dnl AM_PATH_GSTREAMER([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
8 dnl Test for GStreamer, and define GSTREAMER_CFLAGS and GSTREAMER_LIBS
9 dnl
10 AC_DEFUN(AM_PATH_GSTREAMER,
11 [
12 dnl
13 dnl Get command-line stuff
14 dnl
15         AC_ARG_WITH(gstreamer-prefix,[  --with-gstreamer-prefix=PFX   Prefix where GStreamer is installed (optional)],
16                 gstreamer_config_prefix="$withval", gstreamer_config_prefix="")
17         AC_ARG_WITH(gstreamer-exec-prefix,[  --with-gstreamer-exec-prefix=PFX Exec prefix where GStreamer is installed (optional)],
18                 gstreamer_config_exec_prefix="$withval", gstreamer_config_exec_prefix="")
19         AC_ARG_ENABLE(gstreamer-test, [  --disable-gstreamer-test       Do not try and run a test GStreamer-program],   
20                 , enable_gstreamer_test=yes)
21
22         if test "x$gstreamer_config_prefix" != "x"; then
23                 gstreamer_config_args="$gstreamer_config_args --prefix=$gstreamer_config_prefix" ;
24
25                 if test "x${GSTREAMER_CONFIG+set}" != "xset" ; then
26                         GSTREAMER_CONFIG="$gstreamer_config_prefix/bin/gstreamer-config" 
27                 fi
28         fi
29         if test "x$gstreamer_config_exec_prefix" != "x"; then
30                 gstreamer_config_args="$gstreamer_config_args --exec-prefix=$gstreamer_config_exec_prefix" ;
31
32                 if test "x${GSTREAMER_CONFIG+set}" != "xset" ; then
33                         GSTREAMER_CONFIG="$gstreamer_config_exec_prefix/bin/gstreamer-config"
34                 fi      
35         fi
36
37         AC_PATH_PROG(GSTREAMER_CONFIG, gstreamer-config, no)
38
39         if test "x$1" == "x" ; then
40                 min_gstreamer_version="0.0.1" 
41         else
42                 min_gstreamer_version="$1"
43         fi
44
45 dnl
46 dnl Check to make sure version wanted is better than the existing version
47 dnl
48         AC_MSG_CHECKING(for GStreamer-version >= $min_gstreamer_version)
49         no_gstreamer=""
50
51         if test "x$GSTREAMER_CONFIG" = "xno" ; then
52                 no_gstreamer=yes
53         else
54                 GSTREAMER_CFLAGS=`$GSTREAMER_CONFIG $gstreamer_config_args --cflags`
55                 GSTREAMER_LIBS=`$GSTREAMER_CONFIG $gstreamer_config_args --libs`
56
57                 gstreamer_config_major_version=`$GSTREAMER_CONFIG $gstreamer_config_args --version | \
58                                                 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
59                 gstreamer_config_minor_version=`$GSTREAMER_CONFIG $gstreamer_config_args --version | \
60                                                 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
61                 gstreamer_config_micro_version=`$GSTREAMER_CONFIG $gstreamer_config_args --version | \
62                                                 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
63
64                 if test "x$enable_gstreamer_test" = "xyes" ; then
65                         ac_save_CFLAGS="$CFLAGS"
66                         ac_save_LIBS="$LIBS"
67                         CFLAGS="$CFLAGS $GSTREAMER_CFLAGS"
68                         LIBS="$GSTREAMER_LIBS $LIBS"
69 dnl
70 dnl Try and run a program linked with libs
71 dnl
72 AC_TRY_RUN([
73 #include <gst/gst.h>
74 #include <stdio.h>
75 #include <stdlib.h>
76 #include <string.h>
77 int 
78 main ()
79 {
80         int major, minor, micro;
81         char *tmp_version;
82
83         system("touch conf.gstreamertest");
84
85         tmp_version = strdup("$min_gstreamer_version");
86         if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
87                 printf("%s, bad version string\n", "$min_gstreamer_version");
88                 return 1;
89         }       
90
91         if (($gstreamer_config_major_version > major) ||
92                 (($gstreamer_config_major_version == major) && ($gstreamer_config_minor_version > minor)) ||
93                 (($gstreamer_config_major_version == major) && ($gstreamer_config_minor_version == minor) && 
94                 ($gstreamer_config_micro_version >= micro))) {
95                 return 0;
96         } else {
97                 printf("\n*** An old version of GStreamer(%d.%d.%d) was found.\n", 
98                         $gstreamer_config_major_version, $gstreamer_config_minor_version, 
99                         $gstreamer_config_micro_version);
100
101                 printf("*** You need a version of GStreamer newer than %d.%d.%d.\n", major, minor, micro);
102         
103         }
104
105         return 1;
106                 
107 }
108 ],, no_gstreamer=yes, [echo $ac_n "cross compiling; assuming OK... $ac_c"])
109                         CFLAGS="$ac_save_CFLAGS"
110                         LIBS="$ac_save_LIBS"
111                 fi
112         fi
113         if test "x$no_gstreamer" = "x" ; then
114                 AC_MSG_RESULT(yes)
115                 ifelse([$2], , :, [$2])
116         else
117 dnl
118 dnl Something went wrong, looks like GStreamer was not found
119 dnl
120                 if test "$GSTREAMER_CONFIG" = "no" ; then
121                         echo "*** The gstreamer-config script installed by GStreamer could not be found"
122                         echo "*** If GStreamer was installed in PREFIX, make sure PREFIX/bin is in"
123                         echo "*** your path, or set the GSTREAMER_CONFIG environment variable to the"
124                         echo "*** full path to gstreamer-config."
125                 else
126                         if test -f conf.gstreamertest ; then
127                                 :
128                         else
129                                 echo "*** Could not run GStreamer test program, checking why..."
130                                 CFLAGS="$CFLAGS $GSTREAMER_CFLAGS"
131                                 LIBS="$LIBS $GSTREAMER_LIBS"
132 AC_TRY_LINK([
133 #include <gst/gst.h>
134 #include <stdio.h>
135 ], 
136
137 gst_init(NULL, NULL); 
138 return 0; 
139 ],
140         [ echo "*** The test program compiled, but did not run. This usually means"
141           echo "*** that the run-time linker is not finding GStreamer or finding the wrong"
142           echo "*** version of GStreamer. If it is not finding GStreamer, you'll need to set your"
143           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
144           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
145           echo "*** is required on your system"
146           echo "***"
147           echo "*** If you have an old version installed, it is best to remove it, although"
148           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
149         [ echo "*** The test program failed to compile or link. See the file config.log for the"
150           echo "*** exact error that occured. This usually means GStreamer was incorrectly installed"
151           echo "*** or that you have moved GStreamer since it was installed. In the latter case, you"
152           echo "*** may want to edit the gstremaer-config script: $GSTREAMER_CONFIG" ])
153                                 CFLAGS="$ac_save_CFLAGS"
154                                 LIBS="$ac_save_LIBS"
155                        fi
156                 fi
157                 GSTREAMER_CFLAGS=""
158                 GSTREAMER_LIBS=""
159                 ifelse([$3], , :, [$3])
160         fi
161
162 dnl
163 dnl Define our flags and libs
164 dnl
165         AC_SUBST(GSTREAMER_CFLAGS)
166         AC_SUBST(GSTREAMER_LIBS)
167         rm -f conf.gstreamertest
168 ])
169