blakelead
blakelead

Reputation: 1890

"nasm: error: more than one input file specified" when compiling two asm files

I am trying to assemble a small beginner program in assembly language that consists of two asm files. I could make one single file but I wanted to try calling a procedure that is in an other file.
Here is my Makefile :

NAME        =   formatter

SRCS        =   formatter.asm clearstring.asm

OBJS        =   $(SRCS:.asm=.o)`

NASM        =   nasm
NASMFLAGS   =   -f elf64 -F dwarf

LD      =   ld

RM      =   rm -f

all:        $(NAME)

$(NAME):    $(OBJS)
    $(LD) $(OBJS) -o $(NAME)

#(1):
# formatter.o:  formatter.asm
#   $(NASM) -o formatter.o formatter.asm $(NASMFLAGS)
# clearstring.o:    clearstring.asm
#   $(NASM) -o clearstring.o clearstring.asm $(NASMFLAGS)

#(2):
$(OBJS):    $(SRCS)
    $(NASM) -o $(OBJS) $(SRCS) $(NASMFLAGS)

When using the code under comments (1), everything works well but when I use the compact code (2), make gives me that :

nasm -o formatter.o clearstring.o formatter.asm clearstring.asm -f elf64 -F dwarf
nasm: error: more than one input file specified
nasm: error: more than one input file specified
type `nasm -h' for help
make: *** [formatter.o] Error 1

I understand that the assemble step isn't right but I can't make it to do :

nasm -o formatter.o formatter.asm -f elf64 -F dwarf
nasm -o clearstring.o clearstring.asm -f elf64 -F dwarf

I hope I have been clear enough for my first question in this site.
Can you please help me ?

Upvotes: 1

Views: 4058

Answers (1)

Michael
Michael

Reputation: 58507

A rule like this ought to do the trick:

%.o: %.asm
    $(NASM) $(NASMFLAGS) -o $@ $<

$@ and $< will expand to the names of the target and the (first, and in our case, only) input file, respectively.

Upvotes: 1

Related Questions