-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
155 lines (130 loc) · 3.64 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
## Architecture
ARCH := ia32
EXTRA_DEFS += -DKDEBUG=1
EXTRA_DEFS += -DPAGE_POISON=1
EXTRA_DEFS += -DOBJCACHE_POISON=1
EXTRA_DEFS += -DOBJCACHE_DEBUG_FREE=1
TOPDIR := .
#$(shell /bin/pwd)
KERNEL_DIR := $(TOPDIR)/kernel
ARCH_DIR := $(TOPDIR)/arch-$(ARCH)
FS_DIR := $(TOPDIR)/fs
DRIVERS_DIR := $(TOPDIR)/drivers
.PHONY: all clean squeaky boot_floppy userland
## Target toolchain prefix
CROSS_COMPILE :=
## Boot and root image(s)
BOOT_IMAGE := boot.img
# path relative from user dir
ROOT_IMAGE := ../boot.img
## command locations
SH := /bin/sh
RM := rm
MAKE := make
LN := ln
CP := cp
ifdef SPARSE
GCC := $(CROSS_COMPILE)cgcc
EXTRA_DEFS+=-Wno-old-initializer
else
GCC := $(CROSS_COMPILE)gcc
endif
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
STRIP := $(CROSS_COMPILE)strip
# Default target
TARGET: all
# Compiler flags
# -fno-inline \
#
CFLAGS := -ggdb -O2 -nostdlib \
-flto -fwhole-program -fno-fat-lto-objects \
-finline-functions -ftree-partial-pre -fgcse-after-reload -fipa-cp-clone -fipa-pta \
-z execstack \
-static \
-static-libgcc \
-fno-pie -fno-PIE \
-m32 -ffreestanding -fno-stack-protector \
-Wsign-compare \
-Wcast-align \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wmissing-noreturn \
-Wmissing-format-attribute \
-Wno-cast-align \
-I$(TOPDIR)/include $(EXTRA_DEFS)
./include/arch:
@echo " [SYMLINK] ./include/arch -> arch-$(ARCH)"
@$(LN) -sf arch-$(ARCH) ./include/arch
# templates
%.o %.d: %.c ./include/arch Makefile
@echo " [C] $(patsubst %.d, %.c, $@)"
@$(GCC) $(CFLAGS) \
-MMD -MF $(patsubst %.o, %.d, $@) -MT $(patsubst %.d, %.o, $@) \
-c -o $(patsubst %.d, %.o, $@) $<
%.d %.o: %.S ./include/arch Makefile
@echo " [ASM] $(patsubst %.d, %.S, $@)"
@$(GCC) $(CFLAGS) -D__ASM__ \
-MMD -MF $(patsubst %.o, %.d, $@) -MT $(patsubst %.d, %.o, $@) \
-c -o $(patsubst %.d, %.o, $@) $<
include arch-$(ARCH)/Makefile
include kernel/Makefile
include fs/Makefile
include drivers/Makefile
IMAGE_OBJ := $(patsubst %.S, %.o, $(ARCH_ASM_SOURCES)) \
$(patsubst %.c, %.o, $(ARCH_C_SOURCES)) \
$(patsubst %.c, %.o, $(KERNEL_C_SOURCES)) \
$(patsubst %.c, %.o, $(FS_C_SOURCES)) \
$(patsubst %.c, %.o, $(DRIVERS_C_SOURCES))
ALL_SOURCES := $(ARCH_C_SOURCES) $(ARCH_ASM_SOURCES) \
$(KERNEL_C_SOURCES) \
$(FS_C_SOURCES) \
$(DRIVERS_C_SOURCES)
# Generate dependencies
ALL_DEPS := $(patsubst %.S, %.d, $(ARCH_ASM_SOURCES)) \
$(patsubst %.c, %.d, $(ARCH_C_SOURCES)) \
$(patsubst %.c, %.d, $(KERNEL_C_SOURCES)) \
$(patsubst %.c, %.d, $(FS_C_SOURCES)) \
$(patsubst %.c, %.d, $(DRIVERS_C_SOURCES))
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),squeaky)
-include $(ALL_DEPS)
endif
endif
kernel.elf: Makefile $(IMAGE_OBJ) $(ARCH_DIR)/kernel.lnk
@echo " [LINK] $@"
@$(GCC) $(CFLAGS) -Wl,-melf_i386 -Wl,-nostdlib \
-nostartfiles \
-Wl,-z,execstack \
-Wl,--build-id=none \
-Wl,-T,$(ARCH_DIR)/kernel.lnk -o $@ \
$(IMAGE_OBJ) -nostdlib -lgcc
kernel.elf.stripped: kernel.elf
@echo " [STRIP] $@"
@$(CP) $< $@
@$(STRIP) $@
kernel.elf.gz: kernel.elf.stripped
@echo " [COMPRESS] $@"
@gzip -c < $< > $@
all: kernel.elf.gz
userland:
@echo " [USERLAND]"
+$(MAKE) CROSS_COMPILE=$(CROSS_COMPILE) \
ROOT_IMAGE="$(ROOT_IMAGE)" \
-C user root_image
$(BOOT_IMAGE): userland kernel.elf.gz menu.lst
@echo " [BOOTFLOPPY] $@"
@e2fsck -y $(BOOT_IMAGE) || true
@e2cp kernel.elf.gz $(BOOT_IMAGE):kernel
@e2cp menu.lst $(BOOT_IMAGE):
boot_floppy: $(BOOT_IMAGE)
clean:
$(RM) -f $(IMAGE_OBJ) $(ALL_DEPS) \
$(KERNEL_OBJ) $(KERNEL_DIR)/kernel.o \
$(ARCH_OBJ) $(ARCH_DIR)/arch.o \
$(FS_OBJ) $(FS_DIR)/fs.o \
kernel.elf kernel.elf.stripped kernel.elf.gz
make -C user clean
squeaky: clean
$(RM) -f ./include/arch