various AC_HELP_STRING changes
[platform/upstream/gst-plugins-good.git] / m4 / as-arts.m4
1 # This is an example arts .m4 adapted and scrubbed by thomasvs
2
3 # Configure paths for ARTS
4 # Philip Stadermann   2001-06-21
5 # stolen from esd.m4
6
7 dnl AM_PATH_ARTS([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
8 dnl Test for ARTS, and define ARTS_CXXFLAGS and ARTS_LIBS
9 dnl
10 AC_DEFUN([AM_PATH_ARTS],
11 [dnl 
12 dnl Get the cflags and libraries from the artsc-config script
13 dnl
14 AC_ARG_WITH(arts-prefix,
15   AC_HELP_STRING([--with-arts-prefix=PFX],
16                  [prefix where ARTS is installed (optional)]),
17   arts_prefix="$withval", arts_prefix="")
18
19 AC_ARG_WITH(arts-exec-prefix,
20   AC_HELP_STRING([--with-arts-exec-prefix=PFX],
21                  [exec prefix where ARTS is installed (optional)]),
22   arts_exec_prefix="$withval", arts_exec_prefix="")
23
24 AC_ARG_ENABLE(artstest, 
25   AC_HELP_STRING([--disable-artstest],
26                  [do not try to compile and run a test ARTS program]),
27   , enable_artstest=yes)
28
29   if test x$arts_exec_prefix != x ; then
30     arts_args="$arts_args --exec-prefix=$arts_exec_prefix"
31     if test x${ARTS_CONFIG+set} != xset ; then
32       ARTS_CONFIG=$arts_exec_prefix/bin/artsc-config
33     fi
34   fi
35   if test x$arts_prefix != x ; then
36     arts_args="$arts_args --prefix=$arts_prefix"
37     if test x${ARTS_CONFIG+set} != xset ; then
38       ARTS_CONFIG=$arts_prefix/bin/artsc-config
39     fi
40   fi
41
42   AC_PATH_PROG(ARTS_CONFIG, artsc-config, no)
43   min_arts_version=ifelse([$1], ,0.9.5,$1)
44   AC_MSG_CHECKING(for ARTS artsc - version >= $min_arts_version)
45   no_arts=""
46   if test "$ARTS_CONFIG" = "no" ; then
47     no_arts=yes
48   else
49     # FIXME : thomas added this sed to get arts path instead of artsc
50     ARTS_CXXFLAGS=`$ARTS_CONFIG $artsconf_args --cflags | sed 's/artsc$/arts/'`
51     ARTS_LIBS=`$ARTS_CONFIG $artsconf_args --libs | sed 's/artsc$/arts/'`
52
53     arts_major_version=`$ARTS_CONFIG $arts_args --version | \
54            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
55     arts_minor_version=`$ARTS_CONFIG $arts_args --version | \
56            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
57     arts_micro_version=`$ARTS_CONFIG $arts_config_args --version | \
58            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
59     if test "x$enable_artstest" = "xyes" ; then
60       dnl ac_save_CXXFLAGS="$CXXFLAGS"
61       dnl ac_save_LIBS="$LIBS"
62       dnl CFLAGS="$CFLAGS $ARTS_CXXFLAGS"
63       dnl LIBS="$LIBS $ARTS_LIBS"
64 dnl
65 dnl Now check if the installed ARTS is sufficiently new. (Also sanity
66 dnl checks the results of artsc-config to some extent)
67 dnl
68
69 dnl a*s: to successfully compile the C++ test app, we need to 
70 dnl first make sure we're going to compile it as C++ (with AC_LANG_PUSH),
71 dnl then add the CFLAGS and CLIBS of arts which we just discovered to the
72 dnl C++ compilation and linking flags.
73 dnl We also need to clean up after the test; this means using AC_LANG_POP
74 dnl and restoring the CPPFLAGS and LDFLAGS from the saved values we take 
75 dnl here.
76
77 dnl ask nicely for C++ compilation
78       AC_LANG_PUSH(C++)
79
80 dnl save compilation and link flags and make our own
81       ac_save_CPPFLAGS="$CPPFLAGS"
82       ac_save_LDFLAGS="$LDFLAGS"
83       AC_SUBST(CPPFLAGS,"$CPPFLAGS $ARTS_CXXFLAGS")
84       AC_SUBST(LDFLAGS,"$LDFLAGS $ARTS_CLIBS")
85  
86       rm -f conf.artstest
87       AC_TRY_RUN([
88 #include <stdio.h>
89 #include <stdlib.h>
90 #include <string.h>
91 #include <artsflow.h>
92
93 char*
94 my_strdup (char *str)
95 {
96   char *new_str;
97   
98   if (str)
99     {
100       // thomas: the original test did not have the typecast
101       new_str = (char *) malloc ((strlen (str) + 1) * sizeof(char));
102       strcpy (new_str, str);
103     }
104   else
105     new_str = NULL;
106   
107   return new_str;
108 }
109
110 int main ()
111 {
112   int major, minor, micro;
113   char *tmp_version;
114
115   system ("touch conf.artstest");
116
117   /* HP/UX 9 (%@#!) writes to sscanf strings */
118   tmp_version = my_strdup("$min_arts_version");
119   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
120      printf("%s, bad version string\n", "$min_arts_version");
121      exit(1);
122    }
123
124    if (($arts_major_version > major) ||
125       (($arts_major_version == major) && ($arts_minor_version > minor)) ||
126       (($arts_major_version == major) && ($arts_minor_version == minor) && ($arts_micro_version >= micro)))
127     {
128       return 0;
129     }
130   else
131     {
132       printf("\n*** 'artsc-config --version' returned %d.%d.%d, but the minimum version\n", $arts_major_version, $arts_minor_version, $arts_micro_version);
133       printf("*** of ARTS required is %d.%d.%d. If artsc-config is correct, then it is\n", major, minor, micro);
134       printf("*** best to upgrade to the required version.\n");
135       printf("*** If artsc-config was wrong, set the environment variable ARTS_CONFIG\n");
136       printf("*** to point to the correct copy of artsc-config, and remove the file\n");
137       printf("*** config.cache before re-running configure\n");
138       return 1;
139     }
140 }
141
142 ],, no_arts=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
143       dnl CFLAGS="$ac_save_CFLAGS"
144       dnl LIBS="$ac_save_LIBS"
145       dnl a*s this is were we clean up after the test
146       AC_LANG_POP(C++)
147       CXXFLAGS="$ac_save_CXXFLAGS"
148       LDFLAGS="$ac_save_LDFLAGS"
149       dnl a*s we are sure that these are right, so we make them active
150       AC_SUBST(CXXFLAGS,"$CXXFLAGS")
151       AC_SUBST(LDFLAGS,"$LDFLAGS")
152     fi
153   fi
154   if test "x$no_arts" = x ; then
155     AC_MSG_RESULT(yes)
156     ifelse([$2], , :, [$2])     
157   else
158     AC_MSG_RESULT(no)
159     if test "$ARTS_CONFIG" = "no" ; then
160       echo "*** The artsc-config script installed by ARTS could not be found"
161       echo "*** If ARTS was installed in PREFIX, make sure PREFIX/bin is in"
162       echo "*** your path, or set the ARTS_CONFIG environment variable to the"
163       echo "*** full path to artsc-config."
164     else
165       if test -f conf.artstest ; then
166         :
167       else
168          echo "*** Could not run ARTS test program, checking why..."
169          CFLAGS="$CFLAGS $ARTS_CXXFLAGS"
170          LIBS="$LIBS $ARTS_LIBS"
171          AC_TRY_LINK([
172 #include <stdio.h>
173 #include <artsflow.h>
174 ],      [ return 0; ],
175         [ echo "*** The test program compiled, but did not run. This usually means"
176           echo "*** that the run-time linker is not finding ARTS or finding the wrong"
177           echo "*** version of ARTS. If it is not finding ARTS, you'll need to set your"
178           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
179           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
180           echo "*** is required on your system"
181           echo "***"
182           echo "*** If you have an old version installed, it is best to remove it, although"
183           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
184         [ echo "*** The test program failed to compile or link. See the file config.log for the"
185           echo "*** exact error that occured. This usually means ARTS was incorrectly installed"
186           echo "*** or that you have moved ARTS since it was installed. In the latter case, you"
187           echo "*** may want to edit the artsc-config script: $ARTS_CONFIG" ])
188           CFLAGS="$ac_save_CFLAGS"
189           LIBS="$ac_save_LIBS"
190       fi
191     fi
192     ARTS_CXXFLAGS=""
193     ARTS_LIBS=""
194     ifelse([$3], , :, [$3])
195   fi
196   AC_SUBST(ARTS_CXXFLAGS)
197   AC_SUBST(ARTS_LIBS)
198   rm -f conf.artstest
199 ])
200
201 dnl release C++ question
202