-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
55 lines (45 loc) · 1.7 KB
/
Makefile
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
CC=gcc
AS=as
GCCPARAMS = -m32 -nostdlib -fno-builtin -fno-exceptions -ffreestanding -fno-leading-underscore -Wall -Wextra -Wpedantic -fno-stack-protector
ASPARAMS = --32
LDPARAMS = -melf_i386
SRC_DIR=src
HDR_DIR=include
OBJ_DIR=obj
ISO_DIR=iso
SRC_FILES1=$(wildcard $(SRC_DIR)/*.c)
OBJ_FILES1=$(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES1))
SRC_FILES2=$(wildcard $(SRC_DIR)/*.s)
OBJ_FILES2=$(patsubst $(SRC_DIR)/%.s, $(OBJ_DIR)/%.o, $(SRC_FILES2))
SRC_FILES3=$(wildcard $(SRC_DIR)/*.asm)
OBJ_FILES3=$(patsubst $(SRC_DIR)/%.asm, $(OBJ_DIR)/%.o, $(SRC_FILES3))
check_dir:
if [ ! -d "$(OBJ_DIR)" ]; then \
mkdir -p $(OBJ_DIR); \
fi
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(GCCPARAMS) $^ -I$(HDR_DIR) -c -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
$(AS) $(ASPARAMS) -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.asm
nasm -f elf32 -o $@ $<
cooker-os.bin: $(SRC_DIR)/linker.ld $(OBJ_FILES1) $(OBJ_FILES2) $(OBJ_FILES3)
ld $(LDPARAMS) -T $< -o $@ $(OBJ_DIR)/*.o
cooker-os.iso: cooker-os.bin
mkdir iso
mkdir iso/boot
mkdir iso/boot/grub
cp cooker-os.bin iso/boot/cooker-os.bin
echo 'set timeout=0' > iso/boot/grub/grub.cfg
echo 'set default=0' >> iso/boot/grub/grub.cfg
echo '' >> iso/boot/grub/grub.cfg
echo 'menuentry "CookerOS" {' >> iso/boot/grub/grub.cfg
echo ' multiboot /boot/cooker-os.bin' >> iso/boot/grub/grub.cfg
echo ' boot' >> iso/boot/grub/grub.cfg
echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=cooker-os.iso iso
rm -rf iso
install: cooker-os.bin
sudo cp $< /boot/cooker-os.bin
clean:
rm -rf *.o cooker-os cooker-os.iso cooker-os.bin $(OBJ_DIR)/*.o iso