1dnl  This file is part of MED.
2dnl
3dnl  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4dnl  MED is free software: you can redistribute it and/or modify
5dnl  it under the terms of the GNU Lesser General Public License as published by
6dnl  the Free Software Foundation, either version 3 of the License, or
7dnl  (at your option) any later version.
8dnl
9dnl  MED is distributed in the hope that it will be useful,
10dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12dnl  GNU Lesser General Public License for more details.
13dnl
14dnl  You should have received a copy of the GNU Lesser General Public License
15dnl  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16dnl
17
18AC_DEFUN([MED_CHECK_TYPEOF_INT64], [
19
20## Guess where as int64 type is provided by --with-int64 option
21## or auto-detection must be used
22
23AC_ARG_WITH([int64],
24            AC_HELP_STRING([--with-int64=<C type>],
25	                   [Use <C type int64_t or long> for int64]),
26	    [],
27	    [withval=no])
28
29
30med_have_int64="no"
31
32dnl Si aucune directive n'est donnée, test  quel
33dnl type d'entier il faut utiliser pour int64 (par compilation en C)
34dnl Pour la cross-compilation, il ne faut pas lancer un test de compilation
35dnl  -> l'utilisateur spécifie le type à utiliser : int64_t ou long
36if test x"$withval" = xno
37then
38
39#Le type int64_t est défini par la macro si stdint.h n'existe pas et qu'un type entier 64bits en complément à 2 existe sur la plateforme.
40#La définition est utilisée dans confdefs.h pour les macro suivantes.
41  AC_TYPE_INT64_T
42#echo "------------------- ac_cv_c_int64_t" : $ac_cv_c_int64_t"  ---------------------"
43# Attention : med_config.h n'est pas directement inclu dans med.h (de façon volontaire pour séparer headers publiques et privés ).
44#Il faut allors utiliser une variable de substitution pour inclure dans le header med.h.in la définition du type int64_t s'il n'est pas disponible dans stdint.h.
45#DONE : 1) Tester en mode 32 bits avec le compilateur : -m32 (mais un long long 64bits existe)
46#TODO : 2) Tester dans un système 32 bits avec proc 32bits
47
48  case "x$ac_cv_c_int64_t" in
49     "xyes")
50	MED_INT64="int64_t"
51      ;;
52     "xno")
53	MED_INT64="med_int"
54        AC_MSG_WARN([There is no 64bits signed integer type, writing/reading MED_INT64 fields will not be possible.])
55      ;;
56     *)
57	MED_INT64="$ac_cv_c_int64_t"
58        AC_MSG_WARN([A 64bits signed integer type has been found ($ac_cv_c_int64_t) and will be used for defining int64_t type in med.h and med_config.h.])
59      ;;
60  esac
61
62#Si int64_t est défini, positionne la définition PP HAVE_INT64 (pour l'option de compilation swig -DSWIGWORDSIZ6E4 )
63#En fait swig se base sur __WORDSIZE == 32/i386 ou 64/x64 malheureusemnt même un linux32 sur proc64 où int64_t existe (long long) swig ne prend pas en charge les int64 car il n'accepte pas l'option SWIGWORDSIZE64
64  test "x$ac_cv_c_int64_t" = "xno" && med_have_int64="no" || med_have_int64="yes"
65  AC_CHECK_SIZEOF(long)
66  AC_CHECK_SIZEOF(long long)
67  test "x$ac_cv_sizeof_long" = "x8" && med_swig_int64="yes" || med_swig_int64="no"
68
69  test "x$ac_cv_sizeof_long" = "x8" && MED_H5T_INT64="H5T_NATIVE_LONG" &&
70    (AC_DEFINE(MED_H5T_INT64,[H5T_NATIVE_LONG],[The hdf type to user for 64bits signed integer type.])) || (
71        test "x$ac_cv_sizeof_long_long" = "x8" && MED_H5T_INT64="H5T_NATIVE_LLONG"
72         AC_DEFINE(MED_H5T_INT64,[H5T_NATIVE_LLONG],[The hdf type to user for 64bits signed integer type.])
73        )
74
75  AC_TYPE_INT32_T
76  case "x$ac_cv_c_int32_t" in
77     "xyes") MED_INT32="int32_t"  ;;
78     "xno")  MED_INT32="med_int"
79        AC_MSG_ERROR([We must found at least a four bytes signed integer type !])
80      ;;
81     *)
82	MED_INT32="$ac_cv_c_int32_t"
83        AC_MSG_WARN([A 32bits signed integer type has been found ($ac_cv_c_int32_t) and will be used for defining int32_t type in med.h and med_config.h.])
84      ;;
85  esac
86
87else
88  MED_INT64="$withval"
89  AC_MSG_NOTICE([Using type $withval for int64])
90  med_have_int64="yes"
91  MED_INT32="int"
92  #Prévoir un paramétrage
93  MED_H5T_INT64="H5T_NATIVE_LONG"
94  AC_DEFINE(MED_H5T_INT64,[H5T_NATIVE_LONG],[The hdf type to use for 64bits signed integer type.])
95fi
96
97test "x$med_swig_int64" = "xyes" && (AC_DEFINE(MED_SWIG_INT64,[],[The size of a long imply the size of python integer via swig.]))
98AM_CONDITIONAL([MED_SWIG_INT64],[test "x$med_swig_int64" = "xyes" ])
99
100test "x$med_have_int64" = "xyes" && (AC_DEFINE(HAVE_INT64,[],[The size of a int64_t, as computed by sizeof.]))
101AM_CONDITIONAL([HAVE_INT64],[test "x$med_have_int64" = "xyes" ])
102
103AC_SUBST(MED_INT64)
104AC_SUBST(MED_INT32)
105
106])
107