Move to src/obj directory structure

This commit is contained in:
mintsuki 2023-09-26 19:40:23 -05:00
parent 878ca00f18
commit ea68d596f7
3 changed files with 17 additions and 14 deletions

4
kernel/.gitignore vendored
View file

@ -1,4 +1,4 @@
/limine.h
/src/limine.h
/obj
*.elf
*.o
*.d

View file

@ -61,7 +61,7 @@ override CFLAGS += \
# Internal C preprocessor flags that should not be changed by the user.
override CPPFLAGS := \
-I. \
-I src \
$(CPPFLAGS) \
-MMD \
-MP
@ -84,17 +84,17 @@ override NASMFLAGS += \
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
# object and header dependency file names.
override CFILES := $(shell find -L . -type f -name '*.c')
override ASFILES := $(shell find -L . -type f -name '*.S')
override NASMFILES := $(shell find -L . -type f -name '*.asm')
override OBJ := $(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o)
override HEADER_DEPS := $(CFILES:.c=.c.d) $(ASFILES:.S=.S.d)
override CFILES := $(shell cd src && find -L . -type f -name '*.c')
override ASFILES := $(shell cd src && find -L . -type f -name '*.S')
override NASMFILES := $(shell cd src && find -L . -type f -name '*.asm')
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
# Default target.
.PHONY: all
all: $(KERNEL)
limine.h:
src/limine.h:
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h
# Link rules for the final kernel executable.
@ -105,22 +105,25 @@ $(KERNEL): GNUmakefile linker.ld $(OBJ)
-include $(HEADER_DEPS)
# Compilation rules for *.c files.
%.c.o: %.c GNUmakefile limine.h
obj/%.c.o: src/%.c GNUmakefile src/limine.h
mkdir -p obj
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.S files.
%.S.o: %.S GNUmakefile limine.h
obj/%.S.o: src/%.S GNUmakefile src/limine.h
mkdir -p obj
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.asm (nasm) files.
%.asm.o: %.asm GNUmakefile
obj/%.asm.o: src/%.asm GNUmakefile
mkdir -p obj
nasm $(NASMFLAGS) $< -o $@
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf $(KERNEL) $(OBJ) $(HEADER_DEPS)
rm -rf $(KERNEL) obj
.PHONY: distclean
distclean: clean
rm -f limine.h
rm -f src/limine.h