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