TheMakeFiler
TheMakeFiler

Reputation: 3

How do I assemble multiple assembly files into multiple object files with a Makefile?

I want to be able to turn all the *.asm files in a folder to *.o files. For example, if I have header.asm and main.asm, I want header.o and main.o. Nasm can only assemble 1 input file to 1 output file. I have tried this:

%.o : %.asm
        nasm -f elf64 $(patsubst %.o,%.asm,$@) -o $@

along with multiple other things but to no success.

Upvotes: 0

Views: 1319

Answers (1)

MadScientist
MadScientist

Reputation: 100966

Somewhere you have to tell make what files you want to assemble. A pattern rule is just a template for how to build a .o from a .asm. It's not an instruction that says "go find all .asm files and turn them into .o files". It's a template that says, IF you want to build a .o file, and you can find a .asm file, then here's how you can turn the latter into the former.

So, you need a pattern rule to describe how to build things:

%.o : %.asm
        nasm -f elf64 $< -o $@

then you also need a list of the things you want to build; say:

all: foo.o bar.o baz.o

(since you haven't told us anything about the names of the .asm files you want to build I just used random names).

Upvotes: 2

Related Questions