使用make构建时,使用ASM文件的“循环依赖性”

时间:2016-03-25 19:40:54

标签: assembly makefile nasm gnu-make

问题在于,当我构建我的项目时,make会给出有关ASM文件的循环依赖性的恼人消息。奇怪的是,没有为以相同方式编译的C文件显示消息。这是Makefile:

# VV4OS Makefile. Here are the main targets:
# I.   all (can be called without specifying the target) - builds everything
# II.  install - copies the kernel to a disk image.
# III. clean - removes the files that are created by this build system
# and thus can be recovered.
# You can set up the build system by changing the build constants.

# Here come build constants.
# If you can't build VV4OS consider changing them.

# Used tools.

MAKE=make

MOUNT=mount
UMOUNT=umount

SUDO=sudo

# I don't know if there are systems where RM, CP or MKDIR command isn't standard.
# I've added them just in case.

RM=rm
RMFLAGS=-f

CP=cp
CPFLAGS=

MKDIR=mkdir
MKDIRFLAGS=-p

# Compilers (and the linker) and their flags.

ASM=nasm
ASMFLAGS=-felf32

CC=/home/alexander/opt/cross/bin/i686-elf-gcc
CFLAGS=-Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude

LINKER=/home/alexander/opt/cross/bin/i686-elf-gcc
LFLAGS=-ffreestanding -nostdlib -lgcc -T linker.ld

# Files.

SOURCES=$(wildcard *.c) $(wildcard */*.c) $(wildcard */*/*.c) \
    $(wildcard *.asm) $(wildcard */*.asm) $(wildcard */*/*.asm)

OBJECTS=$(SOURCES:=.o)

KERNEL=kernel.elf

DISK_IMG=disk.img
IMG_OFFSET=1048576 # Where the partition starts in bytes (NOT in sectors)
IMG_MNTDIR=/mnt/

# Destination paths.

KERNEL_DEST_PATH=/sys/vv4os/
KERNEL_DEST_NAME=kernel.elf

# These targets are executed whenever they called even if there are ready files with their names.

.PHONY: all install clean

# Here comes the build system code.
# Do not modify it unless your IQ level is higher than 110.

# Build everything (currently only the kernel).
# You can simply call make if you want to do it.

all:
    $(MAKE) $(KERNEL)

# Installs the kernel to a disk image.

install: $(KERNEL) $(DISK_IMG)
    $(MOUNT) -o loop,offset=$(IMG_OFFSET) $(DISK_IMG) $(IMG_MNTDIR)
    $(MKDIR) $(MKDIRFLAGS) $(IMG_MNTDIR)/$(KERNEL_DEST_PATH)
    $(CP) $(KERNEL) $(IMG_MNTDIR)/$(KERNEL_DEST_PATH)/$(KERNEL_DEST_NAME)
    $(UMOUNT) $(IMG_MNTDIR)

# Only builds the kernel.

$(KERNEL): $(OBJECTS)
    $(LINKER) $(LFLAGS) -o $@ $^

# Assemblies assembly files with assembler.

%.asm.o: %.asm
    $(ASM) $(ASMFLAGS) $< -o $@

# Compiles C files with compiler.

%.c.o: %.c
    $(CC) $(CFLAGS) $< -o $@

# Removes all the files that are created by make (and thus can be recovered).

clean:
    $(RM) $(RMFLAGS) $(OBJECTS) $(KERNEL)

这是构建日志:

$ make
make kernel.elf
make[1]: Entering directory '/home/alexander/Documents/vv4os'
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude io/term.c -o io/term.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude io/keyboard.c -o io/keyboard.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude hdd/hdd.c -o hdd/hdd.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude hdd/mbr.c -o hdd/mbr.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude libc/stdlib.c -o libc/stdlib.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude libc/string.c -o libc/string.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude libc/stdio.c -o libc/stdio.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude isr/isr.c -o isr/isr.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude isr/descriptor_tables.c -o isr/descriptor_tables.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude isr/timer.c -o isr/timer.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude general/system.c -o general/system.c.o
/home/alexander/opt/cross/bin/i686-elf-gcc -Wall -Wextra -Werror -ffreestanding -std=c11 -c -Iinclude general/kernel.c -o general/kernel.c.o
make[1]: Circular boot/boot.asm <- boot/boot.asm.o dependency dropped.
nasm -felf32 boot/boot.asm -o boot/boot.asm.o
make[1]: Circular isr/interrupts.asm <- isr/interrupts.asm.o dependency dropped.
nasm -felf32 isr/interrupts.asm -o isr/interrupts.asm.o
/home/alexander/opt/cross/bin/i686-elf-gcc -ffreestanding -nostdlib -lgcc -T linker.ld -o kernel.elf io/term.c.o io/keyboard.c.o hdd/hdd.c.o hdd/mbr.c.o libc/stdlib.c.o libc/string.c.o libc/stdio.c.o isr/isr.c.o isr/descriptor_tables.c.o isr/timer.c.o general/system.c.o general/kernel.c.o boot/boot.asm.o isr/interrupts.asm.o
make[1]: Leaving directory '/home/alexander/Documents/vv4os'

可能是什么问题?

UPD:
当像

这样的目标时,它总是给出这样的信息
file.asm.o: file.asm
    nasm file.asm -o file.asm.o
执行

,其中file.asm是任何程序集文件(它与空文件一起使用)。

1 个答案:

答案 0 :(得分:1)

问题是您的.asm文件与内置%: %.o规则匹配。此规则允许您键入make foo以从foo创建名为foo.o的可执行文件,类似于您可以使用相同的命令从名为foo.c的文件构建可执行文件。要防止它与此规则匹配,您需要创建一个与.asm文件匹配的隐式规则:

%.asm:

您的.c文件不需要此功能,因为已有内置%.c:规则。