blob: e8d7d0846cdaed4936c628f8840114f0512a0acf [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*)
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*)
DRCcdc8ac32009-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 Ossman2ae181c2009-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*)
DRC83e9cd52010-01-28 23:57:53 +000044 case "$host_cpu" in
45 x86_64)
46 objfmt='ELF64'
47 ;;
48 *)
49 objfmt='ELF'
50 ;;
51 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000052 ;;
53 darwin* | rhapsody* | nextstep* | openstep* | macos*)
DRC321ad512009-10-08 09:41:39 +000054 case "$host_cpu" in
55 x86_64)
56 objfmt='Mach-O64'
57 ;;
58 *)
59 objfmt='Mach-O'
60 ;;
61 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000062 ;;
63 *)
64 objfmt='ELF ?'
65 ;;
66esac
67
68AC_MSG_RESULT([$objfmt])
69if test "$objfmt" = 'ELF ?'; then
70 objfmt='ELF'
71 AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
72fi
73
74AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
75case "$objfmt" in
76 MSOMF) NAFLAGS='-fobj -DOBJ32';;
77 Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
78 COFF) NAFLAGS='-fcoff -DCOFF';;
79 a.out) NAFLAGS='-faout -DAOUT';;
80 BSD-a.out) NAFLAGS='-faoutb -DAOUT';;
81 ELF) NAFLAGS='-felf -DELF';;
DRCcdc8ac32009-06-25 20:38:31 +000082 ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000083 RDF) NAFLAGS='-frdf -DRDF';;
84 Mach-O) NAFLAGS='-fmacho -DMACHO';;
DRC321ad512009-10-08 09:41:39 +000085 Mach-O64) NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000086esac
87AC_MSG_RESULT([$NAFLAGS])
88AC_SUBST([NAFLAGS])
89
90AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
91cat > conftest.asm <<EOF
92[%line __oline__ "configure"
93 section .text
Pierre Ossman2ae181c2009-03-09 13:21:27 +000094 global _main,main
95_main:
96main: xor eax,eax
97 ret
98]EOF
99try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
100if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
101 AC_MSG_RESULT(yes)
102else
103 echo "configure: failed program was:" >&AC_FD_CC
104 cat conftest.asm >&AC_FD_CC
105 rm -rf conftest*
106 AC_MSG_RESULT(no)
107 AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.])
108fi
109
110AC_MSG_CHECKING([whether the linker accepts assembler output])
111try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC'
112if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then
113 rm -rf conftest*
114 AC_MSG_RESULT(yes)
115else
116 rm -rf conftest*
117 AC_MSG_RESULT(no)
118 AC_MSG_ERROR([configuration problem: maybe object file format mismatch.])
119fi
120
121])