blob: b8254b656f23e9d1f0e7f92a7cab213e7cf156fc [file] [log] [blame]
Pierre Ossman2ae181c2009-03-09 13:21:27 +00001# AC_PROG_NASM
2# --------------------------
3# Check that NASM exists and determine flags
4AC_DEFUN([AC_PROG_NASM],[
5
6AC_CHECK_PROGS(NASM, [nasm nasmw])
7test -z "$NASM" && AC_MSG_ERROR([no nasm (Netwide Assembler) found])
8
9AC_MSG_CHECKING([for object file format of host system])
10case "$host_os" in
11 cygwin* | mingw* | pw32* | interix*)
DRC8b014d72010-02-18 13:03:41 +000012 case "$host_cpu" in
13 x86_64)
14 objfmt='Win64-COFF'
15 ;;
16 *)
17 objfmt='Win32-COFF'
18 ;;
19 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000020 ;;
21 msdosdjgpp* | go32*)
22 objfmt='COFF'
23 ;;
24 os2-emx*) # not tested
25 objfmt='MSOMF' # obj
26 ;;
27 linux*coff* | linux*oldld*)
28 objfmt='COFF' # ???
29 ;;
30 linux*aout*)
31 objfmt='a.out'
32 ;;
33 linux*)
DRCcdc8ac32009-06-25 20:38:31 +000034 case "$host_cpu" in
35 x86_64)
36 objfmt='ELF64'
37 ;;
38 *)
39 objfmt='ELF'
40 ;;
41 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000042 ;;
43 freebsd* | netbsd* | openbsd*)
44 if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
45 objfmt='BSD-a.out'
46 else
47 objfmt='ELF'
48 fi
49 ;;
50 solaris* | sunos* | sysv* | sco*)
DRC83e9cd52010-01-28 23:57:53 +000051 case "$host_cpu" in
52 x86_64)
53 objfmt='ELF64'
54 ;;
55 *)
56 objfmt='ELF'
57 ;;
58 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000059 ;;
60 darwin* | rhapsody* | nextstep* | openstep* | macos*)
DRC321ad512009-10-08 09:41:39 +000061 case "$host_cpu" in
62 x86_64)
63 objfmt='Mach-O64'
64 ;;
65 *)
66 objfmt='Mach-O'
67 ;;
68 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000069 ;;
70 *)
71 objfmt='ELF ?'
72 ;;
73esac
74
75AC_MSG_RESULT([$objfmt])
76if test "$objfmt" = 'ELF ?'; then
77 objfmt='ELF'
78 AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
79fi
80
81AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
82case "$objfmt" in
83 MSOMF) NAFLAGS='-fobj -DOBJ32';;
84 Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
DRC8b014d72010-02-18 13:03:41 +000085 Win64-COFF) NAFLAGS='-fwin64 -DWIN64 -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000086 COFF) NAFLAGS='-fcoff -DCOFF';;
87 a.out) NAFLAGS='-faout -DAOUT';;
88 BSD-a.out) NAFLAGS='-faoutb -DAOUT';;
89 ELF) NAFLAGS='-felf -DELF';;
DRCcdc8ac32009-06-25 20:38:31 +000090 ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000091 RDF) NAFLAGS='-frdf -DRDF';;
92 Mach-O) NAFLAGS='-fmacho -DMACHO';;
DRC321ad512009-10-08 09:41:39 +000093 Mach-O64) NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000094esac
95AC_MSG_RESULT([$NAFLAGS])
96AC_SUBST([NAFLAGS])
97
98AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
99cat > conftest.asm <<EOF
100[%line __oline__ "configure"
101 section .text
Pierre Ossman2ae181c2009-03-09 13:21:27 +0000102 global _main,main
103_main:
104main: xor eax,eax
105 ret
106]EOF
107try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
108if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
109 AC_MSG_RESULT(yes)
110else
111 echo "configure: failed program was:" >&AC_FD_CC
112 cat conftest.asm >&AC_FD_CC
113 rm -rf conftest*
114 AC_MSG_RESULT(no)
115 AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.])
116fi
117
118AC_MSG_CHECKING([whether the linker accepts assembler output])
119try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC'
120if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then
121 rm -rf conftest*
122 AC_MSG_RESULT(yes)
123else
124 rm -rf conftest*
125 AC_MSG_RESULT(no)
126 AC_MSG_ERROR([configuration problem: maybe object file format mismatch.])
127fi
128
129])