File: endian.m4

package info (click to toggle)
libchipcard 5.0.3beta-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,384 kB
  • ctags: 1,894
  • sloc: ansic: 20,920; sh: 11,062; xml: 6,709; makefile: 596; cpp: 448
file content (55 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (27)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# $Id: endian.m4 595 2004-11-19 16:17:17Z aquamaniac $
# (c) 2006 Martin Preuss<martin@libchipcard.de>
# This function check for endianness

AC_DEFUN([AQ_ENDIAN],[
dnl PREREQUISITES:
dnl   none
dnl IN: 
dnl   - default type for crosscompiling
dnl OUT:
dnl   Variables:
dnl     aq_endian
dnl   Defines:

# check for type to use
AC_MSG_CHECKING(for endianness)
rm -f conf.endian
AC_TRY_RUN([
#include <stdlib.h>
#include <stdio.h>

int main (){
  const char *s;
  FILE *f;
  union {
    unsigned int i;
    unsigned char c[4];
  } u;
  
  u.i=0x12345678;
  if (u.c[0]==0x78)
   s="little";
  else
   s="big";
  
  f=fopen("conf.endian", "w+");
  if (!f) {
    printf("Could not create file conf.endian\n");
    exit(1);
  }
  fprintf(f, "%s\n", s);
  if (fclose(f)) {
   printf("Could not close file.\n");
   exit(1);
  }
  exit(0);
}
 ],
 [aq_endian=`cat conf.endian`; AC_MSG_RESULT($aq_endian)],
 [AC_MSG_ERROR(Could not determine endianness)],
 [aq_endian="$1"; AC_MSG_RESULT([Crosscompiling, assuming $1])]
)
rm -f conf.endian
])