corn/Makefile

88 lines
2.1 KiB
Makefile
Raw Permalink Normal View History

2024-02-04 19:19:54 +00:00
#
# Makefile Configuration
#
2024-01-27 03:29:49 +00:00
2024-01-27 06:16:48 +00:00
CC=cc
LD=ld
2024-02-01 19:43:11 +00:00
AS=nasm
2024-02-04 19:19:54 +00:00
ARCH=amd64
ARCH_COMMON=x86_common
BUILD=build
2024-01-27 06:16:48 +00:00
2024-02-03 20:32:43 +00:00
CFLAGS += -std=c2x -ffreestanding -lgcc -isystem include -pipe
CFLAGS += -Wall -Wextra -pedantic
2024-02-03 20:32:43 +00:00
CFLAGS += -O2 -g -fno-stack-protector -fno-omit-frame-pointer
CFLAGS += -DPAGE_SIZE=4096
2024-02-01 02:19:22 +00:00
LDFLAGS += -nmagic --no-warn-rwx-segments -nostdlib
2024-01-27 06:16:48 +00:00
2024-02-04 19:19:54 +00:00
#
# Makefile
#
ARCH_COMMON += $(ARCH)
2024-01-27 03:29:49 +00:00
2024-02-04 19:19:54 +00:00
KERNEL=kernel.bin
ISO=os_image.iso
ARCH_DIRS = $(patsubst %,src/arch/%,$(ARCH_COMMON))
ARCH_INCLUDES = $(shell find $(ARCH_DIRS) -type d -name "include")
CFLAGS_ARCH = $(patsubst %, -isystem %,$(ARCH_INCLUDES))
H_SRC = $(shell find src include -type f -name "*.h" -not -path "src/arch/*")
HA_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.h")
C_SRC = $(shell find src -type f -name "*.c" -not -path "src/arch/*")
C_OBJ = $(patsubst %.c,build/%.o,$(C_SRC))
2024-02-04 19:19:54 +00:00
CA_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.c")
CA_OBJ = $(patsubst %.c,build/%.o,$(CA_SRC))
2024-01-27 03:29:49 +00:00
2024-02-04 19:19:54 +00:00
A_SRC = $(shell find $(ARCH_DIRS) -type f -name "*.S")
A_OBJ = $(patsubst %.S,build/%.S.o,$(A_SRC))
2024-01-27 03:29:49 +00:00
.PHONY: all clean
all: build/$(ISO)
2024-01-27 03:29:49 +00:00
clean:
@printf "\033[31m RM \033[0m%s\n" build
2024-02-04 19:19:54 +00:00
@rm -fr ./build
2024-01-27 03:29:49 +00:00
$(A_OBJ): build/%.S.o : %.S
2024-01-27 03:29:49 +00:00
@mkdir -p $(@D)
2024-02-01 19:43:11 +00:00
@printf "\033[33m AS \033[0m%s\n" $<
@nasm $< -f elf64 -o $@
2024-01-27 03:29:49 +00:00
$(C_OBJ): build/%.o : %.c
2024-01-27 03:29:49 +00:00
@mkdir -p $(@D)
2024-02-01 19:43:11 +00:00
@printf "\033[34m CC \033[0m%s\n" $<
@$(CC) -c $(CFLAGS) -o $@ $<
2024-01-27 03:29:49 +00:00
2024-02-04 19:19:54 +00:00
$(CA_OBJ): build/%.o : %.c
@mkdir -p $(@D)
@printf "\033[34m CC \033[0m%s\n" $<
@$(CC) -c $(CFLAGS) $(CFLAGS_ARCH) -o $@ $<
build/$(KERNEL): arch/$(ARCH)/linker.ld $(A_OBJ) $(C_OBJ) $(CA_OBJ) $(H_SRC) $(HA_SRC)
2024-01-27 03:29:49 +00:00
@mkdir -p $(@D)
2024-02-01 19:43:11 +00:00
@printf "\033[32m LD \033[0m%s\n" $@
2024-02-04 19:19:54 +00:00
@$(LD) $(LDFLAGS) -T arch/$(ARCH)/linker.ld -o build/$(KERNEL) $(A_OBJ) $(C_OBJ) $(CA_OBJ)
2024-01-27 03:29:49 +00:00
build/$(ISO): build/$(KERNEL) grub.cfg
2024-01-27 03:29:49 +00:00
@mkdir -p $(@D)
@mkdir -p build/iso/boot/grub
@cp grub.cfg build/iso/boot/grub
@cp build/$(KERNEL) build/iso/boot
@printf "\033[35m ISO \033[0m%s\n" build/$(ISO)
@grub-mkrescue -o build/$(ISO) build/iso 2> /dev/null
2024-01-27 08:33:01 +00:00
2024-01-29 00:22:09 +00:00
run: all
2024-02-01 19:43:11 +00:00
@qemu-system-x86_64 \
-cdrom build/$(ISO) \
2024-01-30 17:53:31 +00:00
-serial stdio \
2024-02-02 21:41:19 +00:00
-display sdl \
2024-02-01 20:53:11 +00:00
-m 1G \
-enable-kvm \
2024-01-30 17:53:31 +00:00
-name corn