shiny new avifile test macro let's give it a ride
[platform/upstream/gst-plugins-base.git] / m4 / as-avifile.m4
1 # AS_AVIFILE 0.1.0
2 # CXXFLAGS and LIBS for avifile
3 # taken from Autostar Sandbox, http://autostars.sourceforge.net/
4 # constructed by careful cross-pollination from various sources and lots of
5 # hard labour
6
7 dnl Usage:
8 dnl AS_AVIFILE(MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
9 dnl Test for avifile, and defines 
10 dnl - AVIFILE_CXXFLAGS (C++ compiler flags)
11 dnl - AVIFILE_LDFLAGS (linker flags, stripping and path)
12 dnl as well as set HAVE_AVIFILE to yes or no
13 dnl
14 dnl FIXME: should define AVIFILE_VERSION
15 dnl
16 dnl prerequisites: 
17 dnl - working C++ compiler
18 dnl - usable libstdc++
19 dnl - AC_PATH_XTRA
20
21 AC_DEFUN(AS_AVIFILE, 
22 [
23   HAVE_AVIFILE="no"
24
25   dnl first look for avifile-config
26   AC_PATH_PROG(AVIFILE_CONFIG, avifile-config, no)
27   min_avifile_version=ifelse([$1], ,0.7.0,$1)
28   if test "x$AVIFILE_CONFIG" != "xno"; then
29     dnl now that we have it, we need to save libs and cflags
30     AVIFILE_LDFLAGS=`avifile-config --libs`
31     AVIFILE_CXXFLAGS=`avifile-config --cflags`
32     AC_SUBST(AVIFILE_LDFLAGS)
33     AC_SUBST(AVIFILE_CXXFLAGS)
34     HAVE_AVIFILE="yes"
35   fi
36
37   dnl we got this far, now start checking if we have the right version
38   if test "x$HAVE_AVIFILE" = "xyes";
39   then
40     AC_MSG_CHECKING(for avifile - version >= $min_avifile_version)
41     dnl first get the version number from avifile-config
42     avifile_major_version=`$AVIFILE_CONFIG $avifile_args --version | \
43          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
44     avifile_minor_version=`$AVIFILE_CONFIG $avifile_args --version | \
45          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
46     avifile_micro_version=`$AVIFILE_CONFIG $avifile_config_args --version | \
47          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
48
49     dnl now run a short C app that tells us if the version is ok or not
50     dnl all of this is boilerplate code from other examples
51     rm -f conf.avifiletest
52     AC_TRY_RUN([
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56
57 char*
58 my_strdup (char *str)
59 {
60   char *new_str;
61   
62   if (str)
63   {
64     new_str = (char *) malloc ((strlen (str) + 1) * sizeof (char));
65     strcpy (new_str, str);
66   }
67   else
68     new_str = NULL;
69   
70   return new_str;
71 }
72
73 int
74 main ()
75 {
76   int major, minor, micro;
77   char *tmp_version;
78
79   system ("touch conf.avifiletest");
80
81   /* HP/UX 9 (%@#!) writes to sscanf strings */
82   tmp_version = my_strdup ("$min_avifile_version");
83   if (sscanf (tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) 
84   {
85     printf ("%s, bad version string\n", "$min_avifile_version");
86     exit (1);
87   }
88   if (($avifile_major_version > major) ||
89      (($avifile_major_version == major) && ($avifile_minor_version > minor)) || 
90      (($avifile_major_version == major) && ($avifile_minor_version == minor) && ($avifile_micro_version >= micro)))
91     return 0;
92   else
93   {
94     printf ("\n*** 'avifile-config --version' returned %d.%d.%d, but the minimum version\n", $avifile_major_version, $avifile_minor_version, $avifile_micro_version); 
95     printf ("*** of AVIFILE required is %d.%d.%d. If avifile-config is correct, then it is\n", major, minor, micro);
96     printf ("*** best to upgrade to the required version.\n");
97     printf ("*** If avifile-config was wrong, set the environment variable AVIFILE_CONFIG\n");
98     printf ("*** to point to the correct copy of avifile-config, and remove the file\n");
99     printf ("*** config.cache (if it exists) before re-running configure\n");
100     return 1;
101   }
102 }
103     ], 
104     [ 
105       AC_MSG_RESULT(yes)
106       HAVE_AVIFILE="yes"
107     ],
108     [ 
109       HAVE_AVIFILE="no"
110     ])
111   fi
112   if test "x$HAVE_AVIFILE" = "xyes";
113   then
114     dnl now try to compile a sample test app
115
116     dnl first save whatever language we're currently testing in
117     dnl AC_LANG_SAVE
118     dnl AC_LANG_CPLUSPLUS
119     AC_LANG_PUSH(C++)
120     ac_save_CXXFLAGS=$CXXFLAGS
121     ac_save_LDFLAGS=$LDFLAGS
122     dnl add X flags, because it looks like avifile needs libXv and libXxf86vm
123     CXXFLAGS="$XXCFLAGS $AVIFILE_CXXFLAGS" 
124     LDFLAGS="$LDFLAGS $AVIFILE_LDFLAGS $X_LIBS -lXv -lXxf86vm"
125
126     AC_MSG_CHECKING(compilation of avifile test program)
127     dnl try the compile
128     AC_TRY_LINK([
129 #include <stdio.h>
130 #include <stdlib.h>
131 #include <avifile.h>
132 #include <creators.h>
133       ],[ 
134 /* function body */
135 IVideoDecoder *decoder;
136 BITMAPINFOHEADER bh;
137
138 decoder = Creators::CreateVideoDecoder (bh);
139       ],
140       AC_MSG_RESULT(succeeded)
141       HAVE_AVIFILE="yes",
142       AC_MSG_RESULT(failed)
143       HAVE_AVIFILE="no",
144     )
145     AC_LANG_RESTORE
146     CXXFLAGS="$ac_save_CXXFLAGS"
147     LDFLAGS="$ac_save_LDFLAGS"
148   fi
149 ])
150