velikiyv4
velikiyv4

Reputation: 31

'Circular dependency dropped` with ASM files when building with make

The problem is that when I build my project, make gives annoying messages about circular dependencies with ASM files. What's strange, the message isn't shown for C files compiled in the very same way. Here is the 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)

And here is the build log:

$ 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'

What could be the problem?

UPD:
It always gives such a message when a target like

file.asm.o: file.asm
    nasm file.asm -o file.asm.o

is executed where file.asm is any assembly file (it works with an empty one).

Upvotes: 0

Views: 337

Answers (1)

Ross Ridge
Ross Ridge

Reputation: 39621

The problem is that your .asm files match the builtin %: %.o rule. This rule lets you type make foo to create an executable named foo from foo.o similar to how you can use the same command to build an executable from a file named foo.c. To prevent it from matching this rule you need create an implicit rule that matches .asm files:

%.asm:

You don't need this for your .c files because there's already a builtin %.c: rule.

Upvotes: 1

Related Questions