| 1 | # toltcl.m4 - TOLTCL M4 Macros. -*-Autoconf-*- |
|---|
| 2 | ## Copyright 2007 Free Software Foundation, Inc. |
|---|
| 3 | ## Written by Daniel Rus <rus.daniel@gmail.com>, 2007 |
|---|
| 4 | ## |
|---|
| 5 | ## This file is free software; the Free Software Foundation gives |
|---|
| 6 | ## unlimited permission to copy and/or distribute it, with or without |
|---|
| 7 | ## modifications, as long as this notice is preserved.# |
|---|
| 8 | |
|---|
| 9 | #------------------------------------------------------------------------ |
|---|
| 10 | # _SET_WITH_PACKAGE_OPTIONS_ -- |
|---|
| 11 | # |
|---|
| 12 | # Auxiliar macro used by TOLTCL_REQUIRE_PACKAGE |
|---|
| 13 | # Create configure script options: --with-.. |
|---|
| 14 | # |
|---|
| 15 | # Arguments: |
|---|
| 16 | # 1st: short package name (i.e.: dmalloc). |
|---|
| 17 | # 2nd: long package name (i.e.: Debug Malloc). |
|---|
| 18 | # |
|---|
| 19 | # Results: |
|---|
| 20 | # Adds the following arguments to configure: |
|---|
| 21 | # |
|---|
| 22 | # --with-$1=DIR |
|---|
| 23 | # Specify the directory where to find the package files, libraries |
|---|
| 24 | # under DIR/lib, headers under DIR/include. |
|---|
| 25 | # (i.e.: --with-dmalloc=/home/me/local) |
|---|
| 26 | # |
|---|
| 27 | # --with-$1-includes=DIR |
|---|
| 28 | # Specify the directory where to find the package $1 headers. |
|---|
| 29 | # (i.e.: --with-dmalloc-includes=/home/me/local/include) |
|---|
| 30 | # |
|---|
| 31 | # --with-$1-libraries=DIR |
|---|
| 32 | # Specify the directory where to find the package $1 libraries. |
|---|
| 33 | # (i.e.: --with-dmalloc-libraries=/home/me/local/lib) |
|---|
| 34 | # |
|---|
| 35 | # Defines the following vars: |
|---|
| 36 | # $1_dir Directory path given at --with-$1=<DIR> |
|---|
| 37 | # $1_inc_dir Directory path given at --with-$1-includes=<DIR> |
|---|
| 38 | # $1_lib_dir Directory path given at --with-$1-libraries=<DIR> |
|---|
| 39 | #------------------------------------------------------------------------ |
|---|
| 40 | AC_DEFUN([_SET_WITH_PACKAGE_OPTIONS_],[ |
|---|
| 41 | # create --with-$1, --with-$1-includes, and --with-$1-libraries options |
|---|
| 42 | AC_ARG_WITH([$1],AC_HELP_STRING([--with-$1=DIR],[DIR where to find $2 package]),[$1_dir=$withval],[$1_dir=""]) |
|---|
| 43 | AC_ARG_WITH([$1-includes],AC_HELP_STRING([--with-$1-includes=DIR],[DIR where to find $2 headers]),[$1_inc_dir=$withval],[$1_inc_dir=""]) |
|---|
| 44 | AC_ARG_WITH([$1-libraries],AC_HELP_STRING([--with-$1-libraries=DIR],[DIR where to find $2 libraries]),[$1_lib_dir=$withval],[$1_lib_dir=""]) |
|---|
| 45 | ]) |
|---|
| 46 | |
|---|
| 47 | #------------------------------------------------------------------------ |
|---|
| 48 | # _CHECK_PACKAGE_HEADER_ -- |
|---|
| 49 | # |
|---|
| 50 | # Auxiliar macro used by TOLTCL_REQUIRE_PACKAGE. |
|---|
| 51 | # |
|---|
| 52 | # Checks for the existence of the header given as 3th parameter. |
|---|
| 53 | # |
|---|
| 54 | # If the header file is found, shows a success message, otherwise |
|---|
| 55 | # it will show an error message and stop the script proccess. |
|---|
| 56 | # |
|---|
| 57 | # Arguments (same as TOLTCL_REQUIRE_PACKAGE): |
|---|
| 58 | # 1st: short package name (i.e.: dmalloc). |
|---|
| 59 | # 2nd: long package name (i.e.: Debug Malloc). |
|---|
| 60 | # 3th: one package's header file to look for (i.e.: dmalloc.h). |
|---|
| 61 | # 4th: short library name used with flag -l (i.e.: dmalloc). |
|---|
| 62 | # |
|---|
| 63 | # Results: |
|---|
| 64 | # Defines the following configure cache variable: |
|---|
| 65 | # ac_cv_header_$1 Will be "yes" if header file $3 was found. |
|---|
| 66 | # |
|---|
| 67 | # Creates the following vars: |
|---|
| 68 | # $1_INC_DIR Directory path where header file was found. |
|---|
| 69 | #------------------------------------------------------------------------ |
|---|
| 70 | AC_DEFUN([_CHECK_PACKAGE_HEADER_],[ |
|---|
| 71 | AC_CACHE_VAL(ac_cv_header_$1,[ |
|---|
| 72 | if test "x${$1_dir}" != "x" ; then |
|---|
| 73 | AC_MSG_CHECKING([for $3 in ${$1_dir}/include]) |
|---|
| 74 | if test -r "${$1_dir}/include/$3" ; then |
|---|
| 75 | $1_INC_DIR="${$1_dir}/include" |
|---|
| 76 | ac_cv_header_$1=yes |
|---|
| 77 | AC_MSG_RESULT([yes]) |
|---|
| 78 | else |
|---|
| 79 | AC_MSG_RESULT([no]) |
|---|
| 80 | fi |
|---|
| 81 | elif test "x${$1_inc_dir}" != "x" ; then |
|---|
| 82 | AC_MSG_CHECKING([for $3 in $1_inc_dir]) |
|---|
| 83 | if test -r "${$1_inc_dir}/$3" ; then |
|---|
| 84 | $1_INC_DIR="${$1_inc_dir}" |
|---|
| 85 | ac_cv_header_$1=yes |
|---|
| 86 | AC_MSG_RESULT([yes]) |
|---|
| 87 | else |
|---|
| 88 | AC_MSG_RESULT([no]) |
|---|
| 89 | fi |
|---|
| 90 | else |
|---|
| 91 | AC_MSG_CHECKING([for $3]) |
|---|
| 92 | for dir in /usr/local/include /usr/local /usr/include /usr |
|---|
| 93 | do |
|---|
| 94 | if test -r "${dir}/$3" ; then |
|---|
| 95 | $1_INC_DIR="${dir}" |
|---|
| 96 | ac_cv_header_$1=yes |
|---|
| 97 | break |
|---|
| 98 | fi |
|---|
| 99 | done |
|---|
| 100 | if test "${ac_cv_header_$1}" = "yes" ; then |
|---|
| 101 | AC_MSG_RESULT([yes]) |
|---|
| 102 | else |
|---|
| 103 | AC_MSG_RESULT([no]) |
|---|
| 104 | fi |
|---|
| 105 | fi |
|---|
| 106 | ]) |
|---|
| 107 | |
|---|
| 108 | if test "${ac_cv_header_$1}" != "yes" ; then |
|---|
| 109 | AC_MSG_ERROR([Cannot find header $3 (package: $2)]) |
|---|
| 110 | fi |
|---|
| 111 | ]) |
|---|
| 112 | |
|---|
| 113 | #------------------------------------------------------------------------ |
|---|
| 114 | # _CHECK_PACKAGE_LIB_ -- |
|---|
| 115 | # |
|---|
| 116 | # Auxiliar macro used by TOLTCL_REQUIRE_PACKAGE. |
|---|
| 117 | # |
|---|
| 118 | # Checks for the existence of the library given as 4th parameter. |
|---|
| 119 | # |
|---|
| 120 | # If the library is found, shows a success message, otherwise |
|---|
| 121 | # it will show an error message and stop the script proccess. |
|---|
| 122 | ## |
|---|
| 123 | # Arguments (same as TOLTCL_REQUIRE_PACKAGE): |
|---|
| 124 | # 1st: short package name (i.e.: dmalloc). |
|---|
| 125 | # 2nd: long package name (i.e.: Debug Malloc). |
|---|
| 126 | # 3th: one package's header file to look for (i.e.: dmalloc.h). |
|---|
| 127 | # 4th: short library name used with flag -l (i.e.: dmalloc). |
|---|
| 128 | # |
|---|
| 129 | # Results: |
|---|
| 130 | # Defines the following configure cache variable: |
|---|
| 131 | # ac_cv_lib_$1 Will be "yes" if library $4 was found. |
|---|
| 132 | # |
|---|
| 133 | # Creates the following vars: |
|---|
| 134 | # $1_LIB_DIR Directory path where library was found. |
|---|
| 135 | # $1_LIB Library's file name. |
|---|
| 136 | #------------------------------------------------------------------------ |
|---|
| 137 | AC_DEFUN([_CHECK_PACKAGE_LIB_],[ |
|---|
| 138 | AC_CACHE_VAL(ac_cv_lib_$1,[ |
|---|
| 139 | if test "x${$1_dir}" != "x" ; then |
|---|
| 140 | AC_MSG_CHECKING([for lib$4.so in ${$1_dir}/lib]) |
|---|
| 141 | if test -r "${$1_dir}/lib/lib$4.so" ; then |
|---|
| 142 | $1_LIB_DIR="${$1_dir}/lib" |
|---|
| 143 | ac_cv_lib_$1=yes |
|---|
| 144 | AC_MSG_RESULT([yes]) |
|---|
| 145 | else |
|---|
| 146 | AC_MSG_RESULT([no]) |
|---|
| 147 | fi |
|---|
| 148 | elif test "x${$1_lib_dir}" != "x" ; then |
|---|
| 149 | AC_MSG_CHECKING([for lib$4.so in $1_dir/lib]) |
|---|
| 150 | if test -r "${$1_lib_dir}/lib$4.so" ; then |
|---|
| 151 | $1_LIB_DIR="${$1_lib_dir}" |
|---|
| 152 | ac_cv_lib_$1=yes |
|---|
| 153 | AC_MSG_RESULT([yes]) |
|---|
| 154 | else |
|---|
| 155 | AC_MSG_RESULT([no]) |
|---|
| 156 | fi |
|---|
| 157 | else |
|---|
| 158 | AC_MSG_CHECKING([for lib$4.so]) |
|---|
| 159 | for dir in /usr/local/lib /usr/local /usr/lib /usr |
|---|
| 160 | do |
|---|
| 161 | if test -r "${dir}/lib$4.so" ; then |
|---|
| 162 | $1_LIB_DIR="${dir}" |
|---|
| 163 | ac_cv_lib_$1=yes |
|---|
| 164 | break |
|---|
| 165 | fi |
|---|
| 166 | done |
|---|
| 167 | if test "${ac_cv_lib_$1}" = "yes" ; then |
|---|
| 168 | AC_MSG_RESULT([yes]) |
|---|
| 169 | else |
|---|
| 170 | AC_MSG_RESULT([no]) |
|---|
| 171 | fi |
|---|
| 172 | fi |
|---|
| 173 | ]) |
|---|
| 174 | |
|---|
| 175 | if test "${ac_cv_lib_$1}" != "yes" ; then |
|---|
| 176 | AC_MSG_ERROR([Cannot find library lib$4.so (package: $2)]) |
|---|
| 177 | fi |
|---|
| 178 | ]) |
|---|
| 179 | |
|---|
| 180 | #------------------------------------------------------------------------ |
|---|
| 181 | # TOLTCL_REQUIRE_PACKAGE -- |
|---|
| 182 | # |
|---|
| 183 | # This macro creates several configure script options to activate |
|---|
| 184 | # the use of an specified package. It looks for the given library and |
|---|
| 185 | # header file. If the package is found it adds the corresponding entries |
|---|
| 186 | # to the compilation environment used by Tcl, using the M4 Macros that |
|---|
| 187 | # comes with TEA Std (in tcl.m4 file). |
|---|
| 188 | # |
|---|
| 189 | # Uses the following auxiliar macros: |
|---|
| 190 | # _SET_WITH_PACKAGE_OPTIONS_ -> to create --with-$1-... options |
|---|
| 191 | # _CHECK_PACKAGE_LIB_ -> to look for the given library package |
|---|
| 192 | # _CHECK_PACKAGE_HEADER_ -> to look for the header file |
|---|
| 193 | # |
|---|
| 194 | # Arguments: |
|---|
| 195 | # 1st: short package name (i.e.: dmalloc). |
|---|
| 196 | # 2nd: long package name (i.e.: Debug Malloc). |
|---|
| 197 | # 3th: one package's header file to look for (i.e.: dmalloc.h). |
|---|
| 198 | # 4th: short library name used with flag -l (i.e.: dmalloc). |
|---|
| 199 | # |
|---|
| 200 | # Results: |
|---|
| 201 | # Defines the following configure cache variable: |
|---|
| 202 | # ac_cv_package_$1 Will be "yes" if package was found |
|---|
| 203 | #------------------------------------------------------------------------ |
|---|
| 204 | AC_DEFUN([TOLTCL_REQUIRE_PACKAGE],[ |
|---|
| 205 | # first create configure script options --with-blabla... |
|---|
| 206 | _SET_WITH_PACKAGE_OPTIONS_($@) |
|---|
| 207 | AC_LANG([C]) |
|---|
| 208 | |
|---|
| 209 | _CHECK_PACKAGE_LIB_($@) |
|---|
| 210 | |
|---|
| 211 | if test "$3" != "" ; then |
|---|
| 212 | _CHECK_PACKAGE_HEADER_($@) |
|---|
| 213 | ifelse([$1_INC_DIR],[],[],TEA_ADD_INCLUDES([-I${$1_INC_DIR}])) |
|---|
| 214 | fi |
|---|
| 215 | |
|---|
| 216 | if test "${ac_cv_lib_$1}" = "yes" ; then |
|---|
| 217 | AC_CACHE_VAL(ac_cv_$1,[ac_cv_$1=yes]) |
|---|
| 218 | ifelse([$1_LIB_DIR],[],[],TEA_ADD_LIBS([-L${$1_LIB_DIR} -Wl,-R,${$1_LIB_DIR}])) |
|---|
| 219 | TEA_ADD_LIBS([-l$4]) |
|---|
| 220 | fi |
|---|
| 221 | ]) |
|---|