Makefile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This is the name that our final kernel executable will have.
  2. # Change as needed.
  3. KERNEL := yerbaos.elf
  4. # It is highly recommended to use a custom built cross toolchain to build a kernel.
  5. # We are only using "cc" as a placeholder here. It may work by using
  6. # the host system's toolchain, but this is not guaranteed.
  7. CC = cc
  8. # User controllable CFLAGS.
  9. CFLAGS = -Wall -Wextra -O2 -pipe
  10. # Internal link flags that should not be changed by the user.
  11. INTERNALLDFLAGS := \
  12. -fno-pic -fpie \
  13. -Wl,-static,-pie,--no-dynamic-linker,-ztext \
  14. -static-pie \
  15. -nostdlib \
  16. -Tlinker.ld \
  17. -z max-page-size=0x1000
  18. # Internal C flags that should not be changed by the user.
  19. INTERNALCFLAGS := \
  20. -I. \
  21. -std=gnu11 \
  22. -ffreestanding \
  23. -fno-stack-protector \
  24. -fno-pic -fpie \
  25. -mgeneral-regs-only \
  26. -mno-red-zone
  27. # Use find to glob all *.c files in the directory and extract the object names.
  28. CFILES := $(shell find ./ -type f -name '*.c')
  29. OBJ := $(CFILES:.c=.o)
  30. # Targets that do not actually build a file of the same name.
  31. .PHONY: all clean
  32. # Default target.
  33. all: $(KERNEL)
  34. # Link rules for the final kernel executable.
  35. $(KERNEL): $(OBJ)
  36. $(CC) $(INTERNALLDFLAGS) $(OBJ) -o $@
  37. # Compilation rules for *.c files.
  38. %.o: %.c
  39. $(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
  40. # Remove object files and the final executable.
  41. clean:
  42. rm -rf $(KERNEL) $(OBJ)