blob: 47f8537c35cce498eb1e711f463991557266543f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# MIT License, Copyright (c) 2021 Marvin Borner
# It's not as complicated as it looks
# Obviously needs cross compiler
CC = $(PWD)/cross/opt/bin/i686-elf-gcc
LD = $(PWD)/cross/opt/bin/i686-elf-ld
OC = $(PWD)/cross/opt/bin/i686-elf-objcopy
ST = $(PWD)/cross/opt/bin/i686-elf-strip
AS = nasm
BLD = $(PWD)/build
SRC = $(PWD)/src
# C code
CSRCS = $(shell find $(SRC)/loader/ -type f -name "*.c")
COBJS = $(patsubst $(SRC)/%.c,$(BLD)/%_c.o,$(CSRCS))
# Assembly code
ASRCS = $(shell find $(SRC)/loader/ -type f -name "*.asm")
AOBJS = $(patsubst $(SRC)/%.asm,$(BLD)/%_asm.o,$(ASRCS))
# Enable many warnings for less bugs :)
WARNINGS = -Wall -Wextra -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=2 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wunreachable-code -Wundef -Wold-style-definition -Wvla -pedantic-errors
# Disable some GCC features and boilerplate generation
CFLAGS = $(WARNINGS) -std=c99 -m32 -nostdlib -nostdinc -ffunction-sections -fno-builtin -fno-profile-generate -fno-omit-frame-pointer -fno-common -fno-asynchronous-unwind-tables -fno-stack-protector -fno-pie -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -Ofast -ffreestanding -Wl,-e_start -I$(SRC)/loader/inc/
ASFLAGS = -f elf32
export
all: dir $(BLD)/boot.bin mb1 mb2
dir:
@mkdir -p $(BLD)/entry/
@mkdir -p $(BLD)/loader/fs/
@mkdir -p $(BLD)/loader/protocols/
mb1:
@$(MAKE) --no-print-directory -C example/$@
mb2:
@$(MAKE) --no-print-directory -C example/$@
$(BLD)/boot.bin: $(BLD)/loader.bin
@$(AS) $(ASFLAGS) -f bin $(SRC)/entry/bootsector.asm -o $@
$(BLD)/loader.o: $(COBJS) $(AOBJS)
@$(LD) -N -z max-page-size=0x1000 -e_start -T$(SRC)/loader/link.ld -o $@ $^
$(BLD)/loader.bin: $(BLD)/loader.o
@$(OC) -O binary $^ $@
$(COBJS): $(BLD)/%_c.o : $(SRC)/%.c
@$(CC) -c $(CFLAGS) $< -o $@
$(AOBJS): $(BLD)/%_asm.o : $(SRC)/%.asm
@$(AS) $(ASFLAGS) $< -o $@
clean:
@rm -rf $(BLD)/*
|