blob: 9b8d31252e0dffc21ba68c472e88767cbb942487 [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*)
DRCf0813812009-10-08 09:41:39 +000047 case "$host_cpu" in
48 x86_64)
49 objfmt='Mach-O64'
50 ;;
51 *)
52 objfmt='Mach-O'
53 ;;
54 esac
Pierre Ossman82c7f312009-03-09 13:21:27 +000055 ;;
56 *)
57 objfmt='ELF ?'
58 ;;
59esac
60
61AC_MSG_RESULT([$objfmt])
62if test "$objfmt" = 'ELF ?'; then
63 objfmt='ELF'
64 AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
65fi
66
67AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
68case "$objfmt" in
69 MSOMF) NAFLAGS='-fobj -DOBJ32';;
70 Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
71 COFF) NAFLAGS='-fcoff -DCOFF';;
72 a.out) NAFLAGS='-faout -DAOUT';;
73 BSD-a.out) NAFLAGS='-faoutb -DAOUT';;
74 ELF) NAFLAGS='-felf -DELF';;
DRC246c3d92009-06-25 20:38:31 +000075 ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';;
Pierre Ossman82c7f312009-03-09 13:21:27 +000076 RDF) NAFLAGS='-frdf -DRDF';;
77 Mach-O) NAFLAGS='-fmacho -DMACHO';;
DRCf0813812009-10-08 09:41:39 +000078 Mach-O64) NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';;
Pierre Ossman82c7f312009-03-09 13:21:27 +000079esac
80AC_MSG_RESULT([$NAFLAGS])
81AC_SUBST([NAFLAGS])
82
83AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
84cat > conftest.asm <<EOF
85[%line __oline__ "configure"
86 section .text
Pierre Ossman82c7f312009-03-09 13:21:27 +000087 global _main,main
88_main:
89main: xor eax,eax
90 ret
91]EOF
92try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
93if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
94 AC_MSG_RESULT(yes)
95else
96 echo "configure: failed program was:" >&AC_FD_CC
97 cat conftest.asm >&AC_FD_CC
98 rm -rf conftest*
99 AC_MSG_RESULT(no)
100 AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.])
101fi
102
103AC_MSG_CHECKING([whether the linker accepts assembler output])
104try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC'
105if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then
106 rm -rf conftest*
107 AC_MSG_RESULT(yes)
108else
109 rm -rf conftest*
110 AC_MSG_RESULT(no)
111 AC_MSG_ERROR([configuration problem: maybe object file format mismatch.])
112fi
113
114])