Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 1 | # AC_PROG_NASM |
| 2 | # -------------------------- |
| 3 | # Check that NASM exists and determine flags |
| 4 | AC_DEFUN([AC_PROG_NASM],[ |
| 5 | |
| 6 | AC_CHECK_PROGS(NASM, [nasm nasmw]) |
| 7 | test -z "$NASM" && AC_MSG_ERROR([no nasm (Netwide Assembler) found]) |
| 8 | |
| 9 | AC_MSG_CHECKING([for object file format of host system]) |
| 10 | case "$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*) |
DRC | cdc8ac3 | 2009-06-25 20:38:31 +0000 | [diff] [blame] | 27 | case "$host_cpu" in |
| 28 | x86_64) |
| 29 | objfmt='ELF64' |
| 30 | ;; |
| 31 | *) |
| 32 | objfmt='ELF' |
| 33 | ;; |
| 34 | esac |
Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 35 | ;; |
| 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*) |
DRC | 83e9cd5 | 2010-01-28 23:57:53 +0000 | [diff] [blame] | 44 | case "$host_cpu" in |
| 45 | x86_64) |
| 46 | objfmt='ELF64' |
| 47 | ;; |
| 48 | *) |
| 49 | objfmt='ELF' |
| 50 | ;; |
| 51 | esac |
Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 52 | ;; |
| 53 | darwin* | rhapsody* | nextstep* | openstep* | macos*) |
DRC | 321ad51 | 2009-10-08 09:41:39 +0000 | [diff] [blame] | 54 | case "$host_cpu" in |
| 55 | x86_64) |
| 56 | objfmt='Mach-O64' |
| 57 | ;; |
| 58 | *) |
| 59 | objfmt='Mach-O' |
| 60 | ;; |
| 61 | esac |
Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 62 | ;; |
| 63 | *) |
| 64 | objfmt='ELF ?' |
| 65 | ;; |
| 66 | esac |
| 67 | |
| 68 | AC_MSG_RESULT([$objfmt]) |
| 69 | if test "$objfmt" = 'ELF ?'; then |
| 70 | objfmt='ELF' |
| 71 | AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.]) |
| 72 | fi |
| 73 | |
| 74 | AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ]) |
| 75 | case "$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';; |
DRC | cdc8ac3 | 2009-06-25 20:38:31 +0000 | [diff] [blame] | 82 | ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';; |
Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 83 | RDF) NAFLAGS='-frdf -DRDF';; |
| 84 | Mach-O) NAFLAGS='-fmacho -DMACHO';; |
DRC | 321ad51 | 2009-10-08 09:41:39 +0000 | [diff] [blame] | 85 | Mach-O64) NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';; |
Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 86 | esac |
| 87 | AC_MSG_RESULT([$NAFLAGS]) |
| 88 | AC_SUBST([NAFLAGS]) |
| 89 | |
| 90 | AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works]) |
| 91 | cat > conftest.asm <<EOF |
| 92 | [%line __oline__ "configure" |
| 93 | section .text |
Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame] | 94 | global _main,main |
| 95 | _main: |
| 96 | main: xor eax,eax |
| 97 | ret |
| 98 | ]EOF |
| 99 | try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm' |
| 100 | if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then |
| 101 | AC_MSG_RESULT(yes) |
| 102 | else |
| 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.]) |
| 108 | fi |
| 109 | |
| 110 | AC_MSG_CHECKING([whether the linker accepts assembler output]) |
| 111 | try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC' |
| 112 | if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then |
| 113 | rm -rf conftest* |
| 114 | AC_MSG_RESULT(yes) |
| 115 | else |
| 116 | rm -rf conftest* |
| 117 | AC_MSG_RESULT(no) |
| 118 | AC_MSG_ERROR([configuration problem: maybe object file format mismatch.]) |
| 119 | fi |
| 120 | |
| 121 | ]) |