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