Author Topic: MACRO to tell what version/platform of NASM?  (Read 6958 times)

nobody

  • Guest
MACRO to tell what version/platform of NASM?
« on: November 30, 2006, 04:58:17 AM »
Hi.

I'm wondering if there is any sort of predefined MACRO I can check for to figure out what platform of NASM is being used?  For example, can I use something like:

%ifdef WIN32

to check or include conditional code for when compiling on a Windows based system?  (nasmw)


Sorry if this question is answered elsewhere but I wasn't even sure what keywords to use for a search.

nobody

  • Guest
Re: MACRO to tell what version/platform of NASM?
« Reply #1 on: November 30, 2006, 06:44:08 AM »
Good question. We can determine the version - __NASM_VER__ expends to a string "0.98.39", __NASM_VERSION_ID__ expands to a (dword) number, there's __NASM_MAJOR__, etc., too. (see "predefined macros")

But I don't think there's a way to determine which build of Nasm is running (the platform Nasm is compiled for). Since any build of Nasm (except "nasm16", which is "deprecated") will emit any output format, this may not be what we actually need to know.

There's __OUTPUT_FORMAT__, which... I'm less sure how to use. I can do:

ver db __NASM_VER__

and Print "ver" and get "0.98.39". but if I try:

fmt db __OUTPUT_FORMAT__

Nasm informs me that the symbol "elf" is not defined. If I do:

fmt db "__OUTPUT_FORMAT__"

it just prints "__OUTPUT_FORMAT__" :(

I *can* do:

%ifidn __OUTPUT_FORMAT__, elf
; some code
%endif

That may be what you're looking for, or can be made to work...

"__OUTPUT_FORMAT__" doesn't seem to be documented anywhere (note to self:...). Hope that's some help.

Best,
Frank

nobody

  • Guest
Re: MACRO to tell what version/platform of NASM?
« Reply #2 on: November 30, 2006, 08:16:04 AM »
NASM is platform-independent. (Intentionally so.)

Thus the proper solution is to detect the platform
in e.g. your Makefile, and pass it to NASM in the
form of the -D command line option, e.g. -D WIN32.

nobody

  • Guest
Re: MACRO to tell what version/platform of NASM?
« Reply #3 on: November 30, 2006, 02:42:26 PM »
> Thus the proper solution is to detect the platform
> in e.g. your Makefile, and pass it to NASM in the
> form of the -D command line option, e.g. -D WIN32.  


What I've always doen is this.

Example of a Makefile:

--------

NAME = myprog

linux:$(NAME)
windows:$(NAME).exe

$(NAME): $(NAME).asm
    nasm -fbin -DLINUX -o $(NAME) $(NAME).asm


$(NAME).exe: $(NAME).asm
    nasm -fbin -DWIN -o $(NAME).exe $(NAME).asm

--------

Now, if I want assemble from linux, I write:
    make linux

but if I want assemble from windows, I write:
    make windows

-----
nmt