Autoconf: déterminer l’endianness
Lors de développements assez proches de la machine, il peut être capital de savoir si la machine sur laquelle on se trouve est little-endian ou big-endian, ou en français petit-boutiste et gros-boutiste (oui, c’est assez laid)
Autoconf fourni la réponse à cette question avec la macro AC_C_BIGENDIAN
Le manuel d’autoconf renseigne parfaitement sur son utilisation :
Macro: AC_C_BIGENDIAN ([action-if-true], [action-if-false], [action-if-unknown])
If words are stored with the most significant byte first (like Motorola and
SPARC CPUs), execute action-if-true. If words are stored with the least
significant byte first (like Intel and VAX CPUs), execute action-if-false.This macro runs a test-case if endianness cannot be determined from the
system header files. When cross-compiling, the test-case is not run but grep’ed
for some magic values. action-if-unknown is executed if the latter case fails to
determine the byte sex of the host system.The default for action-if-true is to define `WORDS_BIGENDIAN’. The default
for action-if-false is to do nothing. And finally, the default for
action-if-unknown is to abort configure and tell the installer which variable he
should preset to bypass this test.
Et voici un exemple d’utilisation réel, vérifiant que la machine est little endian :
AC_C_BIGENDIAN(
[AC_MSG_ERROR([big endian, sorry but pppoesk will not work])],
[AC_MSG_RESULT([little endian, fine])],
[AC_MSG_ERROR([unknown endianess ?])]
)
Oui c’est tout, c’est aussi simple que ça.