Pierre Ossman | 82c7f31 | 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*) |
| 27 | objfmt='ELF' |
| 28 | ;; |
| 29 | freebsd* | netbsd* | openbsd*) |
| 30 | if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then |
| 31 | objfmt='BSD-a.out' |
| 32 | else |
| 33 | objfmt='ELF' |
| 34 | fi |
| 35 | ;; |
| 36 | solaris* | sunos* | sysv* | sco*) |
| 37 | objfmt='ELF' |
| 38 | ;; |
| 39 | darwin* | rhapsody* | nextstep* | openstep* | macos*) |
| 40 | objfmt='Mach-O' |
| 41 | ;; |
| 42 | *) |
| 43 | objfmt='ELF ?' |
| 44 | ;; |
| 45 | esac |
| 46 | |
| 47 | AC_MSG_RESULT([$objfmt]) |
| 48 | if test "$objfmt" = 'ELF ?'; then |
| 49 | objfmt='ELF' |
| 50 | AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.]) |
| 51 | fi |
| 52 | |
| 53 | AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ]) |
| 54 | case "$objfmt" in |
| 55 | MSOMF) NAFLAGS='-fobj -DOBJ32';; |
| 56 | Win32-COFF) NAFLAGS='-fwin32 -DWIN32';; |
| 57 | COFF) NAFLAGS='-fcoff -DCOFF';; |
| 58 | a.out) NAFLAGS='-faout -DAOUT';; |
| 59 | BSD-a.out) NAFLAGS='-faoutb -DAOUT';; |
| 60 | ELF) NAFLAGS='-felf -DELF';; |
| 61 | RDF) NAFLAGS='-frdf -DRDF';; |
| 62 | Mach-O) NAFLAGS='-fmacho -DMACHO';; |
| 63 | esac |
| 64 | AC_MSG_RESULT([$NAFLAGS]) |
| 65 | AC_SUBST([NAFLAGS]) |
| 66 | |
| 67 | AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works]) |
| 68 | cat > conftest.asm <<EOF |
| 69 | [%line __oline__ "configure" |
| 70 | section .text |
| 71 | bits 32 |
| 72 | global _main,main |
| 73 | _main: |
| 74 | main: xor eax,eax |
| 75 | ret |
| 76 | ]EOF |
| 77 | try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm' |
| 78 | if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then |
| 79 | AC_MSG_RESULT(yes) |
| 80 | else |
| 81 | echo "configure: failed program was:" >&AC_FD_CC |
| 82 | cat conftest.asm >&AC_FD_CC |
| 83 | rm -rf conftest* |
| 84 | AC_MSG_RESULT(no) |
| 85 | AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.]) |
| 86 | fi |
| 87 | |
| 88 | AC_MSG_CHECKING([whether the linker accepts assembler output]) |
| 89 | try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC' |
| 90 | if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then |
| 91 | rm -rf conftest* |
| 92 | AC_MSG_RESULT(yes) |
| 93 | else |
| 94 | rm -rf conftest* |
| 95 | AC_MSG_RESULT(no) |
| 96 | AC_MSG_ERROR([configuration problem: maybe object file format mismatch.]) |
| 97 | fi |
| 98 | |
| 99 | ]) |