make: Circular dependency dropped

我的未来我决定 提交于 2019-12-04 11:21:33

Your error is this line:

%.o: $(SOURCES)

which presumably expands to something like

%.o: main.asm foo.asm bar.asm

What that means is something very approximately like

main.asm.o: main.asm
foo.asm.o: foo.asm
bar.asm.o: bar.asm
    ....

That's 'approximately' because you're mixing up the syntax here.

You're confusing an ordinary rule (target: source) with a wildcard rule (%.target: %.source). What you probably want is

%.o: %.asm
    $(AS) $(ASFLAGS) -o $@ $<

which teaches Make how to make .o files from .asm files, combined with

httpd: $(SOURCES:.asm=.o)
    $(CC) $(CFLAGS) -o httpd $*

which tells Make how to combine the various .o files into the httpd executable. The $(SOURCES:.asm=.o) variable reference expands to a list of .o files as dependencies, and Make now knows how to create those .o files from the corresponding .asm files.

AS:=yasm
CC:=gcc
ASFLAGS:=-g dwarf2 -f elf64 -a x86
CFLAGS:=-g

OBJECTSDIR:=$(shell pwd)/bin
SRCDIR:=$(shell pwd)/src
SOURCES=$(wildcard $(SRCDIR)/*.asm)
OBJECTS=$(shell find $(OBJECTSDIR) -name *.o)


%.o: %.asm
    $(AS) $(ASFLAGS) -o $(subst $(SRCDIR),$(OBJECTSDIR),$@) $<

httpd: $(SOURCES:.asm=.o)
    $(CC) $(CFLAGS) -o httpd $(OBJECTS)


clean:
    rm -f $(OBJECTSDIR)/*
    rm -f httpd

Thanks to you explication Norman, I did that. It's important for me to have distinct folders, /bin and /src so that everything stay clear.

Thank you, It's working and I understand my error.

note: if I put any object file in the Makefile folder I got weird error from make... just deleting them make it working again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!