| 1 |
# =========================================================================== |
| 2 |
# https://www.gnu.org/software/autoconf-archive/ax_cfitsio.html |
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# SYNOPSIS |
| 6 |
# |
| 7 |
# AX_CFITSIO |
| 8 |
# |
| 9 |
# DESCRIPTION |
| 10 |
# |
| 11 |
# This macro searches for the headers and libraries of the cfitsio library |
| 12 |
# of https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html that typically have |
| 13 |
# been installed with package names like cfitsio-devel or libcfitsio-dev |
| 14 |
# on Linux operating systems. |
| 15 |
# |
| 16 |
# If compilation of the test program works, the macro AC_SUBST's the |
| 17 |
# variables CFITSIO_LDFLAGS -L flags with the library directory, |
| 18 |
# CFITSIO_LIBS with the -l flag of the library and CFITSIO_CFLAGS with the |
| 19 |
# -I flag of the include directory. |
| 20 |
# |
| 21 |
# If the m4-variable CFITSIO_HOME is set, the name of that directory is |
| 22 |
# given preference in the search order to find the (binary) library and |
| 23 |
# include directory. |
| 24 |
# |
| 25 |
# If configure is called with the option --with-cfitsio=<DIR>, this |
| 26 |
# directory overrides the standard search directories and <DIR>/lib and |
| 27 |
# <DIR>/include are the only points where cfitsio is searched after. A |
| 28 |
# further fine-tuning is separately available with the configure options |
| 29 |
# --with-cfitsio-include=<DIR> and/or --with-cfitsio-libdir=<DIR> which |
| 30 |
# override only the default search list of directories for the |
| 31 |
# header-files or libraries. |
| 32 |
# |
| 33 |
# For most compilations one would run separately |
| 34 |
# |
| 35 |
# AC_CHECK_HEADERS([fitsio.h],[],AC_MSG_WARN([Warning: Could not find cfitsio header fitsio.h ... ])]) |
| 36 |
# |
| 37 |
# to define (or not to define) HAVE_FITSIO_H; this is not included here. |
| 38 |
# |
| 39 |
# LICENSE |
| 40 |
# |
| 41 |
# Copyright (c) 2025 Richard J. Mathar <[email protected]> |
| 42 |
# |
| 43 |
# Copying and distribution of this file, with or without modification, are |
| 44 |
# permitted in any medium without royalty provided the copyright notice |
| 45 |
# and this notice are preserved. This file is offered as-is, without any |
| 46 |
# warranty. |
| 47 |
|
| 48 |
#serial 5 |
| 49 |
|
| 50 |
AC_DEFUN([AX_CFITSIO], |
| 51 |
[ |
| 52 |
ac_with_cfitsio=no |
| 53 |
dnl ${build_cpu} is only known if LT_INIT was used... |
| 54 |
dnl 'uname -i' returns unknown on Fedora, even if it is x86_64 |
| 55 |
AC_CANONICAL_HOST |
| 56 |
if test $host_cpu = "x86_64"; then |
| 57 |
ac_search_lib_path="$CFITSIO_HOME/lib64 $CFITSIO_HOME/lib /usr/lib64 /usr/lib/x86_64-linux-gnu /usr/local/lib64 /opt/lib64 /opt/local/lib64 /usr/lib" |
| 58 |
else |
| 59 |
ac_search_lib_path="$CFITSIO_HOME/lib /usr/lib /usr/local/lib /opt/opencv/lib /opt/local/lib /usr/lib/i386-linux-gnu /usr/lib64" |
| 60 |
fi |
| 61 |
ac_search_include_path="$CFITSIO_HOME/include /usr/include/cfitsio/ /usr/include /usr/local/include /opt/include" |
| 62 |
|
| 63 |
AC_ARG_WITH(cfitsio, |
| 64 |
[AS_HELP_STRING([--with-cfitsio=DIR], [root directory of cfitsio installation])], |
| 65 |
ac_with_cfitsio=$withval |
| 66 |
if test "x${ac_with_cfitsio}" != xyes && test "x${ac_with_cfitsio}" != xno; then |
| 67 |
ac_cfitsio_include="$withval/include" |
| 68 |
ac_cfitsio_libdir="$withval/lib" |
| 69 |
fi |
| 70 |
) |
| 71 |
|
| 72 |
AC_ARG_WITH([cfitsio-include], |
| 73 |
[AS_HELP_STRING([--with-cfitsio-include=DIR], [cfitsio header files are in DIR])], |
| 74 |
ac_with_cfitsio=$withval |
| 75 |
if test "x${ac_with_cfitsio}" != xyes && test "x${ac_with_cfitsio}" != xno; then |
| 76 |
ac_cfitsio_include="$withval" |
| 77 |
fi |
| 78 |
) |
| 79 |
|
| 80 |
AC_ARG_WITH([cfitsio-libdir], |
| 81 |
[AS_HELP_STRING([--with-cfitsio-libdir=DIR], [The cfitsio library is in DIR])], |
| 82 |
ac_with_cfitsio=$withval |
| 83 |
if test "x${ac_with_cfitsio}" != xyes && test "x${ac_with_cfitsio}" != xno; then |
| 84 |
ac_cfitsio_libdir="$withval" |
| 85 |
fi |
| 86 |
) |
| 87 |
|
| 88 |
if test "x${ac_cfitsio_libdir}" == "x"; then |
| 89 |
for ac_search_lib_test in $ac_search_lib_path; do |
| 90 |
if test -r "$ac_search_lib_test"; then |
| 91 |
ls $ac_search_lib_test/libcfitsio* >/dev/null 2>&1 |
| 92 |
if test $? -eq 0; then |
| 93 |
ac_cfitsio_libdir="$ac_search_lib_test/" |
| 94 |
break; |
| 95 |
fi |
| 96 |
fi |
| 97 |
done |
| 98 |
fi |
| 99 |
|
| 100 |
if test "x${ac_cfitsio_include}" == "x"; then |
| 101 |
for ac_search_include_test in $ac_search_include_path ; do |
| 102 |
if test -r "$ac_search_include_test/fitsio.h"; then |
| 103 |
ac_cfitsio_include="$ac_search_include_test" |
| 104 |
break; |
| 105 |
fi |
| 106 |
done |
| 107 |
fi |
| 108 |
|
| 109 |
AX_CFITSIO_LOCAL($ac_cfitsio_libdir, $ac_cfitsio_include) |
| 110 |
]) |
| 111 |
|
| 112 |
|
| 113 |
dnl Subfunction which intermediatly sets the LDFLAGS and CXXFLAGS |
| 114 |
dnl to the search paths found above, tries to compile-link a trivial |
| 115 |
dnl program that uses the standard fitsio.h, and results in |
| 116 |
dnl either failure or success of the entire search. The LDFLAGS |
| 117 |
dnl and CXXFLAGS are restored to the content they had before the |
| 118 |
dnl macro call. |
| 119 |
AC_DEFUN([AX_CFITSIO_LOCAL], |
| 120 |
[ |
| 121 |
AC_REQUIRE([AX_SAVE_FLAGS]) |
| 122 |
AC_REQUIRE([AX_RESTORE_FLAGS]) |
| 123 |
|
| 124 |
AX_SAVE_FLAGS(cfitsio) |
| 125 |
|
| 126 |
AC_MSG_NOTICE(Check $1 $2) |
| 127 |
|
| 128 |
if test "$1"; then |
| 129 |
LDFLAGS="$LDFLAGS -L$1 -lcfitsio -pthread" |
| 130 |
fi |
| 131 |
if test "$2"; then |
| 132 |
CXXFLAGS="$CXXFLAGS -I$2" |
| 133 |
fi |
| 134 |
|
| 135 |
AC_LANG_PUSH(C) |
| 136 |
AC_MSG_CHECKING(for cfitsio in $1) |
| 137 |
|
| 138 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <fitsio.h>]], [[ ; ]])],[success=yes],[success=no]) |
| 139 |
|
| 140 |
AC_MSG_RESULT($success) |
| 141 |
AC_LANG_POP() |
| 142 |
|
| 143 |
AX_RESTORE_FLAGS(cfitsio) |
| 144 |
|
| 145 |
if test "x$success" != xyes; then |
| 146 |
AC_MSG_ERROR(cfitsio not (properly) installed. Get a recent version from: https://heasarc.gsfc.nasa.gov/docs/software/fitsio/ or the linux package manager) |
| 147 |
else |
| 148 |
if test "$1"; then |
| 149 |
AC_SUBST(CFITSIO_LDFLAGS, "-L$1") |
| 150 |
AC_SUBST(CFITSIO_LIBS, "-lcfitsio") |
| 151 |
fi |
| 152 |
if test "$2"; then |
| 153 |
AC_SUBST(CFITSIO_CFLAGS, "-I$2") |
| 154 |
fi |
| 155 |
fi |
| 156 |
]) |