简体   繁体   English

Makefile没有针对目标的规则

[英]Makefile no rule for target

Make complains that there is no rule for target 'build/libc/string/strlen.c' when it's clearly defined. 明确定义目标'build / libc / string / strlen.c'没有规则。 Weirdly, it successfully compiled all but one dependency for 'build/libc/libc.a'. 奇怪的是,它成功编译了“ build / libc / libc.a”的所有依赖关系。 I had, or at least attempted to, disabled the builtin implicit rules and variables to avoid spending hours debugging while pulling my hair out but it doesn't seem to help because I'm completely lost. 我曾经或至少尝试过禁用内置的隐式规则和变量,以免花费大量时间进行调试,而又一头雾水,但这似乎无济于事,因为我完全迷路了。

Makefile: 生成文件:

.SUFFIXES:

MAKEFLAGS += -rR

STD = gnu11
CFLAGS = -O2 -g -ffreestanding -fbuiltin -Wall -Wno-div-by-zero -D__is_vos_kernel__ -Iinclude
LFLAGS = -O2 -g -ffreestanding -fbuiltin -Wall -Wextra
LIBC_FLAGS = -O2 -g -D__is_vos_libc__ -Iinclude
LIBK_FLAGS = -O2 -g -ffreestanding -fbuiltin -D__is_vos_libc__ -Iinclude -D__is_vos_kernel__

CC = i386-elf-gcc
LD = i386-elf-ld
AR = i386-elf-ar
AS = /usr/local/bin/nasm

SYSROOT = sysroot
BUILDDIR = builddir

SYSARG = --sysroot=sysroot -isystem=/usr/include

LIBC_OBJECTS = $(wildcard libc/*.c)
LIBC_HEADERS = $(wildcard libc/*.h)
LLIBC_HEADERS = $(wildcard sysroot/usr/include/*.h)

header:=$(shell find libc -type f -name "*.h")

prepare-dir:
    mkdir -p sysroot/usr/include sysroot/usr/lib build

sysroot/usr/include/%.h: libc/%.h prepare-dir
    cd libc; rsync -R $(<:libc/%=%) ../sysroot/usr/include

prepare-headers: $(addprefix sysroot/usr/include/, $(header:libc/%=%))
    @echo $^

prepare: prepare-dir prepare-headers

build/libc/%.o: libc/%.c prepare
    $(CC) $(SYSARG) -c $< -o $@ -std=$(STD) $(LIBC_FLAGS)

libc_objects = $(shell find libc -type f -name "*.c")
libco_pre = $(addprefix build/, $(libc_objects)))

build/libc/libc.a: $(libco_pre:.c=.o)
    $(AR) rcs $@ $^

clean:
    find . -type f -name "*.o" -delete
    find sysroot -type f -name "*" -delete
    # find sysroot -type d -name "*" -delete
    find build -type f -name "*" -delete
    # find build -type d -name "*" -delete

Command log: 命令日志:

G16-MACBOOKPRO:VioletOS ghifari160$ make -rR build/libc/libc.a
mkdir -p sysroot/usr/include sysroot/usr/lib build
cd libc; rsync -R stdbool.h ../sysroot/usr/include
cd libc; rsync -R stdint.h ../sysroot/usr/include
cd libc; rsync -R stdlib.h ../sysroot/usr/include
cd libc; rsync -R string.h ../sysroot/usr/include
cd libc; rsync -R sys/cdefs.h ../sysroot/usr/include
sysroot/usr/include/stdbool.h sysroot/usr/include/stdint.h sysroot/usr/include/stdlib.h sysroot/usr/include/string.h sysroot/usr/include/sys/cdefs.h
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/stdlib/abort.c -o build/libc/stdlib/abort.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/string/malloc.c -o build/libc/string/malloc.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/string/memcmp.c -o build/libc/string/memcmp.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/string/memcpy.c -o build/libc/string/memcpy.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/string/memmove.c -o build/libc/string/memmove.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/string/memset.c -o build/libc/string/memset.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
i386-elf-gcc --sysroot=sysroot -isystem=/usr/include -c libc/string/strcat.c -o build/libc/string/strcat.o -std=gnu11 -O2 -g -D__is_vos_libc__ -Iinclude
make: *** No rule to make target `build/libc/string/strlen.c)', needed by `build/libc/libc.a'.  Stop.

notice the closing parenthesis at the end of build/libc/string/strlen.c) - it prevents your :.c=.o substitution from functioning properly, so make tries to look for a source file in the build directory, which does of course not exist. 请注意build/libc/string/strlen.c) -它阻止您的:.c=.o替换正常运行,因此请尝试在build目录中查找文件,当然不存在。

the root cause is likely that this line has one closing parenthesis too many: 根本原因可能是此行的右括号太多:

libco_pre = $(addprefix build/, $(libc_objects)))
                                      here -----^

which adds a closing parenthesis to the last target in the list. 这会向列表中的最后一个目标添加一个右括号。 This is why all of the previous targets had been built correctly. 这就是为什么先前所有目标均已正确构建的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM