Makefile没有针对目标的规则

时间:2018-03-04 05:57:30

标签: c makefile gnu-make

抱怨目标' build / libc / string / strlen.c'没有规则。当它明确定义时。奇怪的是,它成功编译了除#c; build / libc / libc.a'之外的所有依赖项。我曾经或者至少试图禁用内置的隐式规则和变量,以避免花费数小时调试同时拔掉头发,但它似乎没有帮助,因为我完全失去了。

生成文件:

.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

命令日志:

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.

1 个答案:

答案 0 :(得分:6)

注意build/libc/string/strlen.c)末尾的右括号 - 它会阻止:.c=.o替换正常运行,因此请尝试在源文件> build 目录,当然不存在。

根本原因很可能是这一行有一个右括号太多:

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

,它将右括号添加到列表中的最后一个目标。这就是为什么所有以前的目标都已正确构建的原因。