blob: cc10a215193b3cfd2bd37812be978a3f02ed180d [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
DRC0f413b22010-04-06 20:05:39 +000047 case "$host_cpu" in
DRC49597872010-05-17 20:47:57 +000048 x86_64 | amd64)
DRC0f413b22010-04-06 20:05:39 +000049 objfmt='ELF64'
50 ;;
51 *)
52 objfmt='ELF'
53 ;;
54 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000055 fi
56 ;;
57 solaris* | sunos* | sysv* | sco*)
DRC83e9cd52010-01-28 23:57:53 +000058 case "$host_cpu" in
59 x86_64)
60 objfmt='ELF64'
61 ;;
62 *)
63 objfmt='ELF'
64 ;;
65 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000066 ;;
67 darwin* | rhapsody* | nextstep* | openstep* | macos*)
DRC321ad512009-10-08 09:41:39 +000068 case "$host_cpu" in
69 x86_64)
70 objfmt='Mach-O64'
71 ;;
72 *)
73 objfmt='Mach-O'
74 ;;
75 esac
Pierre Ossman2ae181c2009-03-09 13:21:27 +000076 ;;
77 *)
78 objfmt='ELF ?'
79 ;;
80esac
81
82AC_MSG_RESULT([$objfmt])
83if test "$objfmt" = 'ELF ?'; then
84 objfmt='ELF'
85 AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
86fi
87
88AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
89case "$objfmt" in
90 MSOMF) NAFLAGS='-fobj -DOBJ32';;
91 Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
DRC8b014d72010-02-18 13:03:41 +000092 Win64-COFF) NAFLAGS='-fwin64 -DWIN64 -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000093 COFF) NAFLAGS='-fcoff -DCOFF';;
94 a.out) NAFLAGS='-faout -DAOUT';;
95 BSD-a.out) NAFLAGS='-faoutb -DAOUT';;
96 ELF) NAFLAGS='-felf -DELF';;
DRCcdc8ac32009-06-25 20:38:31 +000097 ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +000098 RDF) NAFLAGS='-frdf -DRDF';;
99 Mach-O) NAFLAGS='-fmacho -DMACHO';;
DRC321ad512009-10-08 09:41:39 +0000100 Mach-O64) NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';;
Pierre Ossman2ae181c2009-03-09 13:21:27 +0000101esac
102AC_MSG_RESULT([$NAFLAGS])
103AC_SUBST([NAFLAGS])
104
105AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
106cat > conftest.asm <<EOF
107[%line __oline__ "configure"
108 section .text
Pierre Ossman2ae181c2009-03-09 13:21:27 +0000109 global _main,main
110_main:
111main: xor eax,eax
112 ret
113]EOF
114try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
115if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
116 AC_MSG_RESULT(yes)
117else
118 echo "configure: failed program was:" >&AC_FD_CC
119 cat conftest.asm >&AC_FD_CC
120 rm -rf conftest*
121 AC_MSG_RESULT(no)
122 AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.])
123fi
124
125AC_MSG_CHECKING([whether the linker accepts assembler output])
126try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC'
127if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then
128 rm -rf conftest*
129 AC_MSG_RESULT(yes)
130else
131 rm -rf conftest*
132 AC_MSG_RESULT(no)
133 AC_MSG_ERROR([configuration problem: maybe object file format mismatch.])
134fi
135
136])