blob: f7d7b690b4e351aae262fd2d768709bb102db64f [file] [log] [blame]
Pierre Ossman82c7f312009-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*)
12 objfmt='Win32-COFF'
13 ;;
14 msdosdjgpp* | go32*)
15 objfmt='COFF'
16 ;;
17 os2-emx*) # not tested
18 objfmt='MSOMF' # obj
19 ;;
20 linux*coff* | linux*oldld*)
21 objfmt='COFF' # ???
22 ;;
23 linux*aout*)
24 objfmt='a.out'
25 ;;
26 linux*)
DRC246c3d92009-06-25 20:38:31 +000027 case "$host_cpu" in
28 x86_64)
29 objfmt='ELF64'
30 ;;
31 *)
32 objfmt='ELF'
33 ;;
34 esac
Pierre Ossman82c7f312009-03-09 13:21:27 +000035 ;;
36 freebsd* | netbsd* | openbsd*)
37 if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
38 objfmt='BSD-a.out'
39 else
40 objfmt='ELF'
41 fi
42 ;;
43 solaris* | sunos* | sysv* | sco*)
44 objfmt='ELF'
45 ;;
46 darwin* | rhapsody* | nextstep* | openstep* | macos*)
47 objfmt='Mach-O'
48 ;;
49 *)
50 objfmt='ELF ?'
51 ;;
52esac
53
54AC_MSG_RESULT([$objfmt])
55if test "$objfmt" = 'ELF ?'; then
56 objfmt='ELF'
57 AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
58fi
59
60AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
61case "$objfmt" in
62 MSOMF) NAFLAGS='-fobj -DOBJ32';;
63 Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
64 COFF) NAFLAGS='-fcoff -DCOFF';;
65 a.out) NAFLAGS='-faout -DAOUT';;
66 BSD-a.out) NAFLAGS='-faoutb -DAOUT';;
67 ELF) NAFLAGS='-felf -DELF';;
DRC246c3d92009-06-25 20:38:31 +000068 ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';;
Pierre Ossman82c7f312009-03-09 13:21:27 +000069 RDF) NAFLAGS='-frdf -DRDF';;
70 Mach-O) NAFLAGS='-fmacho -DMACHO';;
71esac
72AC_MSG_RESULT([$NAFLAGS])
73AC_SUBST([NAFLAGS])
74
75AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
76cat > conftest.asm <<EOF
77[%line __oline__ "configure"
78 section .text
Pierre Ossman82c7f312009-03-09 13:21:27 +000079 global _main,main
80_main:
81main: xor eax,eax
82 ret
83]EOF
84try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
85if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
86 AC_MSG_RESULT(yes)
87else
88 echo "configure: failed program was:" >&AC_FD_CC
89 cat conftest.asm >&AC_FD_CC
90 rm -rf conftest*
91 AC_MSG_RESULT(no)
92 AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.])
93fi
94
95AC_MSG_CHECKING([whether the linker accepts assembler output])
96try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC'
97if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then
98 rm -rf conftest*
99 AC_MSG_RESULT(yes)
100else
101 rm -rf conftest*
102 AC_MSG_RESULT(no)
103 AC_MSG_ERROR([configuration problem: maybe object file format mismatch.])
104fi
105
106])