Reputation: 181
FILES = lab.o
OBJS = $(FILES:.o=.c)
ASMS = $(FILES:.c=.s)
all: lab
lab: $(OBJS)
gcc -o lab $(OBJS)
asmfiles: $(ASMS)
%.o: %.c
gcc -c $< -o $@
%.s: %.c
gcc -S $< -o $@
clean:
rm -f *.o *.s
When running make clean, then make, I keep getting
make: *** No rule to make target `lab', needed by `all'. Stop.
I've tried using both lab, lab.asm. lab.o for the files. I can't find much info on using a makefile without .c file.
Pretty stumped.
Upvotes: 1
Views: 2215
Reputation: 58497
Your makefile doesn't specify what to do with .asm
files, nor does it say anything about using NASM as the assembler.
Here's a small example makefile that would build an executable named lab
from the assembly file lab.asm
using NASM as the assembler and LD (from the GNU binutils) as the linker. Feel free to modify/expand it as necessary:
TARGET = lab
FILES = lab.asm
OBJS = $(FILES:.asm=.o)
NASM = nasm
ASM_FLAGS = -f elf64
LD = ld
all : $(TARGET)
lab: $(OBJS)
$(LD) -o $(TARGET) $(OBJS)
%.o : %.asm
$(NASM) $(ASM_FLAGS) -o $@ $<
Upvotes: 1