-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
81 lines (66 loc) · 1.45 KB
/
Makefile
File metadata and controls
81 lines (66 loc) · 1.45 KB
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
# Directories and files
OUT ?= ironOS
BUILD_DIR ?= build
SRC_DIR := src
INC_DIR := include
LINKER_SCRIPTS_DIR := linker-scripts
# Export environment variables needed for package.sh
export OUT
export BUILD_DIR
export ISO_NAME := $(OUT).iso
# Compiler and linker definitions
CC := $(TOOLCHAIN_PREFIX)gcc
LD := $(TOOLCHAIN_PREFIX)ld
# Internal compile flags
CFLAGS += \
-Wall \
-Wextra \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-lto \
-fno-PIC \
-ffunction-sections \
-fdata-sections \
-m64 \
-march=x86-64 \
-mabi=sysv \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone \
-mcmodel=kernel
CPPFLAGS += \
-I include \
-MMD \
-MP
LDFLAGS += \
-m elf_x86_64 \
-nostdlib \
-static \
-z max-page-size=0x1000 \
--gc-sections \
-T $(LINKER_SCRIPTS_DIR)/linker.ld
# Source files
SRCS := $(shell find $(SRC_DIR) -type f \( -name '*.c' -o -name '*.S' \))
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
# Rules
.PHONY: all clean
all: $(BUILD_DIR)/$(ISO_NAME)
$(BUILD_DIR)/$(ISO_NAME): $(BUILD_DIR)/$(OUT)
./package.sh
$(BUILD_DIR)/$(OUT): $(OBJS)
mkdir -p $(dir $@)
$(LD) $(LDFLAGS) $(OBJS) -o $@
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR)/%.S.o: %.S
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
clean:
rm -rf $(BUILD_DIR)
-include $(DEPS)