1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(viterbi27.c)
3AC_CONFIG_HEADER(config.h)
4SO_NAME=2
5VERSION=2.0.1
6AC_SUBST(SO_NAME)
7AC_SUBST(VERSION)
8
9dnl Checks for programs.
10AC_PROG_CC
11if test $GCC != "yes"
12then
13	AC_MSG_ERROR([Need GNU C compiler])
14fi
15dnl Checks for libraries.
16AC_CHECK_LIB(c, malloc)
17
18dnl Checks for header files.
19AC_CHECK_HEADERS(getopt.h stdio.h stdlib.h memory.h)
20if test -z "$HAVE_stdio.h"
21then
22	AC_MSG_ERROR([Need stdio.h!])
23fi
24if test -z "$HAVE_stdlib.h"
25then
26	AC_MSG_ERROR([Need stdlib.h!])
27fi
28if test -z "$HAVE_stdlib.h"
29then
30	AC_MSG_ERROR([Need memory.h!])
31fi
32
33AC_CANONICAL_SYSTEM
34case $target_cpu in
35i386|i486|i586|i686)
36	ARCH_OPTION=-march=$target_cpu
37	;;
38esac
39
40AC_SUBST(ARCH_OPTION)
41
42SIMD=no
43
44AC_ARG_ENABLE(port,[  --enable-port           force use of portable C code],SIMD="port")
45AC_ARG_ENABLE(mmx,[  --enable-mmx            force use of MMX instructions],SIMD="MMX")
46AC_ARG_ENABLE(sse,[  --enable-sse            force use of SSE instructions],SIMD="SSE")
47AC_ARG_ENABLE(sse2,[  --enable sse2           force use of SSE2 instructions],SIMD="SSE2")
48
49# If not specified, find out which versions of the library (port/mmx/sse/sse2) to install as the default
50# by looking at the CPUID flags
51
52if test $SIMD = no; then
53
54if test $cross_compiling = yes; then
55   AC_MSG_ERROR([Must specify --with-port, --with-mmx, --with-sse or --with-sse2 when cross-compiling])
56fi
57
58AC_MSG_CHECKING([for SSE2 support...])
59AC_TRY_RUN([
60int main(){
61  int f;
62
63  asm("movl \$1,%%eax;cpuid;movl %%edx,%0" : "=r"(f) : : "%eax","%ebx","%ecx");
64
65  if(f & (1 << 26))
66    exit(0);
67  else
68    exit(1);
69}],SIMD="SSE2";
70   AC_MSG_RESULT([yes]),
71   AC_MSG_RESULT([no]))
72fi
73
74if test $SIMD = no; then
75AC_MSG_CHECKING([for SSE support...])
76AC_TRY_RUN([
77int main(){
78  int f;
79
80  asm("movl \$1,%%eax;cpuid;movl %%edx,%0" : "=r"(f) : : "%eax","%ebx","%ecx");
81
82  if(f & (1 << 25))
83    exit(0);
84  else
85    exit(1);
86}],SIMD="SSE";
87   AC_MSG_RESULT([yes]),
88   AC_MSG_RESULT([no]))
89fi
90
91if test $SIMD = no; then
92AC_MSG_CHECKING([for MMX support...])
93AC_TRY_RUN([
94int main(){
95  int f;
96
97  asm("movl \$1,%%eax;cpuid;movl %%edx,%0" : "=r"(f) : : "%eax","%ebx","%ecx");
98
99  if(f & (1 << 23))
100    exit(0);
101  else
102    exit(1);
103}],SIMD="MMX";
104   AC_MSG_RESULT([yes]),
105   AC_MSG_RESULT([no]))
106fi
107
108case $SIMD in
109SSE2)
110	AC_MSG_RESULT([Building SSE2 version])
111	AC_TRY_COMPILE(,[asm("movdqa %xmm0,%xmm0"); ],,
112	 AC_MSG_ERROR([You have a SSE2 CPU but your assembler does not support SSE2 mnemonics.
113	  Install the latest version of bintools or restart configure with the --enable-sse option]))
114	STATIC_LIB=libviterbi_sse2.a
115
116	;;
117SSE)
118	AC_MSG_RESULT([Building SSE version])
119	STATIC_LIB=libviterbi_sse.a
120	;;
121MMX)
122	AC_MSG_RESULT([Building MMX version])
123	STATIC_LIB=libviterbi_mmx.a
124	;;
125port|no)
126	AC_MSG_RESULT([Building portable C version])
127	STATIC_LIB=libviterbi_port.a
128	;;
129esac
130
131
132AC_SUBST(STATIC_LIB)
133
134dnl Checks for library functions.
135AC_CHECK_FUNCS(getopt_long)
136
137AC_OUTPUT(makefile)
138
139