-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.in
178 lines (161 loc) · 5.51 KB
/
Makefile.in
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright (c) 2018, Suphanat Chunhapanya
# This file is part of Kelner.
#
# Kelner is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Kelner is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Kelner. If not, see <https://www.gnu.org/licenses/>.
ARCH = @KELNER_ARCH@
NASMFLAGS = -f bin
RUSTFLAGS = -Z pre-link-arg=-nostartfiles -Z pre-link-arg=-Tlayout.ld
CLIPPYFLAGS = --all-features --all-targets
QEMUMEM = 128M
MANIFESTPATH = kernel/Cargo.toml
TARGETDIR = target
CLEANFILES = build $(TARGETDIR)
DEEPCLEANFILES = .bin
DISTCLEANFILES = @KELNER_CONFIG_FILES@ config.log config.status
TARGET = $(ARCH)-unknown-none
STANDARD_LIBS = alloc
CUSTOMIZED_CARGO = .bin/cargo
CUSTOMIZED_CARGO_CMD = RUSTUP_TOOLCHAIN=$(shell cat rust-toolchain) \
$(CUSTOMIZED_CARGO)
STANDARD_LIB_FILENAMES = $(addsuffix .rlib, $(addprefix lib, $(STANDARD_LIBS)))
VERBOSE =
@KELNER_VERBOSE@ VERBOSE = --verbose
@KELNER_FATAL_WARNINGS@ NASMFLAGS += -Werror
@KELNER_FATAL_WARNINGS@ RUSTFLAGS += -D warnings
@KELNER_FATAL_WARNINGS@ CLIPPYFLAGS += -- -D warnings
.PHONY: all
all: build/disk
.PHONY: clean
clean:
rm -rf $(CLEANFILES)
.PHONY: deepclean
deepclean:
rm -rf $(CLEANFILES) $(DEEPCLEANFILES)
.PHONY: distclean
distclean:
rm -rf $(CLEANFILES) $(DEEPCLEANFILES) $(DISTCLEANFILES)
.PHONY: qemu
qemu: build/disk
qemu-system-$(ARCH) -m $(QEMUMEM) -drive file=$<,format=raw
.PHONY: debug
debug: build/diskdev
qemu-system-$(ARCH) -m $(QEMUMEM) -s -drive file=$<,format=raw \
-monitor tcp:127.0.0.1:1235,server,nowait & \
sleep 15 && gdb && fg
.PHONY: check
check:
mkdir -p build
cargo test \
$(VERBOSE) \
--manifest-path $(MANIFESTPATH) \
--target-dir $(TARGETDIR)
cargo clippy \
$(VERBOSE) \
--manifest-path $(MANIFESTPATH) \
--target-dir $(TARGETDIR) \
$(CLIPPYFLAGS)
.PHONY: doc
doc:
cargo doc \
$(VERBOSE) \
--manifest-path $(MANIFESTPATH) \
--target-dir $(TARGETDIR)
.PHONY: privdoc
privdoc:
cargo doc --document-private-items \
$(VERBOSE) \
--manifest-path $(MANIFESTPATH) \
--target-dir $(TARGETDIR)
build/packages/sample_elf: packages/sample_elf.c
mkdir -p build/packages
gcc -std=c99 -static -O0 packages/sample_elf.c \
-o build/packages/sample_elf
build/disk: build/kernel build/packages/sample_elf bootloader/*
mkdir -p build
nasm $(NASMFLAGS) -o $@ \
-D SAMPLE_ELF_FILE=$(word 2, $^) \
-D KERNEL_FILE=../$< -ibootloader/ \
-D ENTRY_POINT=$(shell objdump -f $(TARGETDIR)/$(TARGET)/release/kernel | \
grep "start address" | cut -d ' ' -f 3) \
-D BSS_SIZE=$(shell size -x $(TARGETDIR)/$(TARGET)/release/kernel | \
awk '{$$1=$$1};1' | tail -n 1 | cut -d ' ' -f 3) \
bootloader/disk.asm
build/diskdev: build/kerneldev build/packages/sample_elf bootloader/*
mkdir -p build
nasm $(NASMFLAGS) -o $@ \
-D SAMPLE_ELF_FILE=$(word 2, $^) \
-D KERNEL_FILE=../$< -ibootloader/ \
-D ENTRY_POINT=$(shell objdump -f $(TARGETDIR)/$(TARGET)/debug/kernel | \
grep "start address" | cut -d ' ' -f 3) \
-D BSS_SIZE=$(shell size -x $(TARGETDIR)/$(TARGET)/debug/kernel | \
awk '{$$1=$$1};1' | tail -n 1 | cut -d ' ' -f 3) \
bootloader/disk.asm
build/kernel: $(CUSTOMIZED_CARGO) \
$(addprefix $(TARGETDIR)/$(TARGET)/release/, $(STANDARD_LIB_FILENAMES)) \
$(shell find kernel -type f)
mkdir -p build
$(CUSTOMIZED_CARGO_CMD) rustc \
$(VERBOSE) \
--target kernel/targets/$(TARGET).json \
--manifest-path $(MANIFESTPATH) \
--target-dir $(TARGETDIR) \
--release -- $(RUSTFLAGS)
objcopy -O binary -S $(TARGETDIR)/$(TARGET)/release/kernel $@
build/kerneldev: $(CUSTOMIZED_CARGO) \
$(addprefix $(TARGETDIR)/$(TARGET)/debug/, $(STANDARD_LIB_FILENAMES)) \
$(shell find kernel -type f)
mkdir -p build
$(CUSTOMIZED_CARGO_CMD) rustc \
$(VERBOSE) \
--target kernel/targets/$(TARGET).json \
--manifest-path $(MANIFESTPATH) \
--target-dir $(TARGETDIR) \
-- $(RUSTFLAGS)
objcopy -O binary -S $(TARGETDIR)/$(TARGET)/debug/kernel $@
# Compile our customized Cargo.
$(CUSTOMIZED_CARGO): $(shell find cargo -type f)
mkdir -p $(TARGETDIR)
mkdir -p $(dir $@)
cargo build \
--manifest-path cargo/Cargo.toml \
--target-dir $(TARGETDIR) \
--release
cp $(TARGETDIR)/release/cargo $(CUSTOMIZED_CARGO)
# Compile all standard libraries dependencies for debug environment.
# Please note that when the target json file changes, this will not recompile.
# I still don't know how to force Cargo to compile in this case.
$(TARGETDIR)/$(TARGET)/debug/lib%.rlib: \
rust/src/lib%/Cargo.toml \
$(CUSTOMIZED_CARGO) \
kernel/targets/$(TARGET).json
$(CUSTOMIZED_CARGO_CMD) rustc \
$(VERBOSE) \
--manifest-path $< \
--target kernel/targets/$(TARGET).json \
--target-dir $(TARGETDIR) \
-- -A unused_attributes
# Compile all standard libraries dependencies for release environment.
# Please note that when the target json file changes, this will not recompile.
# I still don't know how to force Cargo to compile in this case.
$(TARGETDIR)/$(TARGET)/release/lib%.rlib: \
rust/src/lib%/Cargo.toml \
$(CUSTOMIZED_CARGO) \
kernel/targets/$(TARGET).json
$(CUSTOMIZED_CARGO_CMD) rustc \
$(VERBOSE) \
--manifest-path $< \
--target kernel/targets/$(TARGET).json \
--target-dir $(TARGETDIR) \
--release \
-- -A unused_attributes