Added root Makefile and module Makefile

This commit is contained in:
lucic71 2020-06-19 15:21:33 +03:00
parent c944ebee8c
commit ee226907a6
2 changed files with 117 additions and 17 deletions

View File

@ -1,33 +1,67 @@
OBJECTS = loader.o kmain.o
# loader and kmain must be the only object files placed in the root directory.
OBJECTS = loader.o kmain.o
# Flags for linker and compiler. Those options tell the compiler to stay chill
# and let me handle libraries, linking and other stuff.
CC = gcc
CCFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c
LDFLAGS = -T link.ld -melf_i386
LDFLAGS = -T link.ld -m elf_i386
AS = nasm
ASFLAGS = -f elf32
all: kernel.elf
# Each module directory starts with the character 'm'. MDIRS will search for such
# directories and MOBJECTS will collect the module objects to be linked with the
# root objects (loader and kmain).
MDIRS = $(wildcard m*)
MOBJECTS = $(wildcard $(MDIRS)/*.o)
.PHONY: all clean mall
# all - Default rule that build the entire project.
all: kernel.elf mall
# mall - Recursively build all modules.
mall:
for dir in $(MDIRS); do \
$(MAKE) -C $$dir; \
done
# kernel.elf - Link all root objects and module objects to create the
# kernel.elf executable
kernel.elf: $(OBJECTS)
ld $(LDFLAGS) $(OBJECTS) -o kernel.elf
ld $(LDFLAGS) $(OBJECTS) $(MOBJECTS) -o kernel.elf
# os.iso - Create the OS image and place the kernel fiel in GRUB directory.
os.iso: kernel.elf
cp kernel.elf iso/boot/kernel.elf
genisoimage -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
-boot-load-size 4 \
-A os \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o os.iso \
iso
genisoimage -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
-boot-load-size 4 \
-A os \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o os.iso \
iso
# run - Run the emulator using the config file.
BOCHS_CONFIG := bochsrc.txt
run: os.iso
bochs -f bochsrc.txt -q
bochs -f $(BOCHS_CONFIG) -q
# Compile and assemble c and s files.
%.o: %.c
$(CC) $(CCFLAGS) $< -o $@
@ -35,5 +69,13 @@ run: os.iso
%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
clean:
rm -rf *.o kernel.elf os.iso bochslog.txt iso/boot/kernel.elf
# clean, mclean - Clean unuseful files from root directory and from module
# directories
clean: mclean
@$(RM) *.o kernel.elf os.iso bochslog.txt iso/boot/kernel.elf
mclean:
for dir in $(MDIRS); do \
$(MAKE) -C $$dir distclean; \
done

58
mterminal/Makefile Normal file
View File

@ -0,0 +1,58 @@
# SRC_DIR - Directory containing source
# OBJ_DIR - Directory where temporary objects will be created
# INC_DIR - Directory where header files are declared
SRC_DIR := src
OBJ_DIR := obj
INC_DIR := include
# MOBJECT - Module Object
MOBJECT := terminal.o
SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# CCFLAGS, LDFLAGS, INCFLAGS - Flags for linker and compiler.
# HFLAGS - MMD generates makefile dependencies so that whenever a header file
# is modified the project will be rebuilt if needed.
CC = gcc
CCFLAGS = -m32 -nostdlib -lgcc -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c
HFLAGS = -MMD
LDFLAGS = -relocatable -m elf_i386
INCFLAGS = -I$(INC_DIR)
.PHONY: all clean
# all - Default rule for building the module object.
all: $(MOBJECT)
# MOBJECT - Links all object into one global module object.
$(MOBJECT): $(OBJECTS)
ld $(LDFLAGS) $^ -o $@
# Rule that converts source files into object files.
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CCFLAGS) $(HFLAGS) $(INCFLAGS) $< -o $@
# OBJ_DIR - Creates a temporary folder containing object files.
$(OBJ_DIR):
mkdir -p $@
# clean, mclean - deletes object files and the module object if necessary
clean:
@$(RM) -rv $(OBJ_DIR)
distclean: clean
@$(RM) $(MOBJECT)
# Create d files used for makefile dependencies using o files.
-include $(OBJECTS:.o=.d)