build: Add rules for assembly files to makefile
This commit is contained in:
parent
b219c030cf
commit
ce4a376d04
1 changed files with 22 additions and 4 deletions
|
@ -20,6 +20,9 @@ $(eval $(call DEFAULT_VAR,CC,cc))
|
||||||
# User controllable CFLAGS.
|
# User controllable CFLAGS.
|
||||||
CFLAGS ?= -O2 -g -Wall -Wextra -Wpedantic -pipe
|
CFLAGS ?= -O2 -g -Wall -Wextra -Wpedantic -pipe
|
||||||
|
|
||||||
|
# User controllable nasm flags. We set none by default.
|
||||||
|
NASMFLAGS ?=
|
||||||
|
|
||||||
# User controllable linker flags. We set none by default.
|
# User controllable linker flags. We set none by default.
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
|
|
||||||
|
@ -49,10 +52,15 @@ override INTERNALLDFLAGS := \
|
||||||
-Wl,-z,max-page-size=0x1000 \
|
-Wl,-z,max-page-size=0x1000 \
|
||||||
-Wl,-T,linker.ld
|
-Wl,-T,linker.ld
|
||||||
|
|
||||||
# Use find to glob all *.c files in the directory and extract the object names.
|
override INTERNALNASMFLAGS := \
|
||||||
|
-F dwarf -g -f elf64
|
||||||
|
|
||||||
|
# Use find to glob all *.c, *.S, and *.asm files in the directory and extract the object names.
|
||||||
override CFILES := $(shell find ./ -type f -name '*.c')
|
override CFILES := $(shell find ./ -type f -name '*.c')
|
||||||
override OBJ := $(CFILES:.c=.o)
|
override SFILES := $(shell find ./ -type f -name '*.S')
|
||||||
override HEADER_DEPS := $(CFILES:.c=.d)
|
override ASMFILES := $(shell find ./ -type f -name '*.asm')
|
||||||
|
override OBJ := $(CFILES:.c=.o) $(SFILES:.S=.o) $(ASMFILES:.asm=.o)
|
||||||
|
override HEADER_DEPS := $(CFILES:.c=.d) $(SFILES:.S=.o)
|
||||||
|
|
||||||
# Default target.
|
# Default target.
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
@ -65,11 +73,21 @@ limine.h:
|
||||||
$(KERNEL): $(OBJ)
|
$(KERNEL): $(OBJ)
|
||||||
$(CC) $(OBJ) $(LDFLAGS) $(INTERNALLDFLAGS) -o $@
|
$(CC) $(OBJ) $(LDFLAGS) $(INTERNALLDFLAGS) -o $@
|
||||||
|
|
||||||
# Compilation rules for *.c files.
|
# Include header dependencies
|
||||||
-include $(HEADER_DEPS)
|
-include $(HEADER_DEPS)
|
||||||
|
|
||||||
|
# Compilation rules for *.c files.
|
||||||
%.o: %.c limine.h
|
%.o: %.c limine.h
|
||||||
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
# Compilation rules for *.S files.
|
||||||
|
%.o: %.S limine.h
|
||||||
|
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
# Compilation rules for *.asm (nasm) files.
|
||||||
|
%.o: %.asm
|
||||||
|
nasm $(NASMFLAGS) $(INTERNALNASMFLAGS) $< -o $@
|
||||||
|
|
||||||
# Remove object files and the final executable.
|
# Remove object files and the final executable.
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|
Loading…
Add table
Reference in a new issue