我在项目的根目录中有以下makefile:
Makefile
const classes = new Set();
class A {
constructor() {
classes.add(this.constructor);
}
}
class B extends A {
}
class C extends A {
}
class D extends C {
}
new B();
new B();
new C();
new D();
console.log([...classes]);
包含pi / 3 / mod.mk
# Board version
# Available: 3
PI ?= 3
# Kernel binaries
ifeq ($(PI), 3)
KERNEL_IMG := kernel8.img
else ifeq ($(PI), 2)
KERNEL_IMG := kernel7.img
else ifeq ($(PI), 1)
KERNEL_IMG := kernel.img
else
$(error Unsupported Raspberry Pi version)
endif
KERNEL_ELF := $(patsubst %.img,%.elf,$(KERNEL_IMG))
# Directories/paths
BUILD_DIR := build
# Toolchain
TOOLCHAIN ?= aarch64-elf
OBJCOPY := $(TOOLCHAIN)-objcopy
LD := $(TOOLCHAIN)-ld
CC := $(TOOLCHAIN)-gcc
# Misc
LINKER_SCRIPT := linker.ld
# Flags
LDFLAGS := -T $(LINKER_SCRIPT)
ASFLAGS :=
CFLAGS :=
# Source files
C_SRC := $(wildcard *.c)
ASM_SRC := $(wildcard *.S)
# Include
include pi/$(PI)/mod.mk
# Object files
OBJECTS := $(patsubst %,$(BUILD_DIR)/%.o,$(C_SRC))
OBJECTS += $(patsubst %,$(BUILD_DIR)/%.o,$(ASM_SRC))
# Targets
.PHONY: all builddirs clean
all: $(BUILD_DIR)/$(KERNEL_IMG)
$(BUILD_DIR)/$(KERNEL_IMG): $(BUILD_DIR)/$(KERNEL_ELF)
$(OBJCOPY) $< -O binary $@
$(BUILD_DIR)/$(KERNEL_ELF): $(LINKER_SCRIPT) $(OBJECTS)
$(LD) $(OBJECTS) $(LDFLAGS) -o $@
$(OBJECTS): | builddirs
builddirs: $(BUILD_DIR)/pi/$(PI)
$(BUILD_DIR)/pi/$(PI):
mkdir -p $@
$(BUILD_DIR)/%.S.o: %.S
$(CC) -c $< $(ASFLAGS) -o $@
$(BUILD_DIR)/%.c.o: %.c
$(CC) -c $< $(CFLAGS) -o $@
clean:
$(RM) -r $(BUILD_DIR)
现在是问题所在:每当我在项目的根目录中运行“ make”时,都会调用“ $(BUILD_DIR)/pi/3/start.S.o”规则,而不是“ all”。如果我将'include pi / $(PI)/mod.mk'移至根makefile的最底部,并将'pi / 3 / mod.mk'中的'C_SRC'和'ASM_SRC'变量替换为'OBJECTS + = $(BUILD_DIR)/pi/3/start.So'并调用'make',甚至没有调用此规则,所以我得到一个错误,表明make不知道如何构建开始。所以
我做错了什么,最好的解决方法是什么?
答案 0 :(得分:0)
Make的默认目标是Makefile中的第一个目标。在您的情况下,第一个目标是包含的Makefile中定义的目标:$(BUILD_DIR)/pi/3/start.S.o
。要么调用make all
或在Makefile中移动all
规则,使其成为第一个规则,要么告诉make默认目标是all
:
.DEFAULT_GOAL := all
(请参阅GNU make manual)。