-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
190 lines (146 loc) · 4.36 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# Top-level Makefile for certikos64
#
ifndef V
V := @
else
V :=
endif
ARCH := i386
COMP_NAME := "ccomp"
ENABLE_CCOMP := 0
COMP_NAME := "cc"
# Cross-compiler toolchain
#
# This Makefile will automatically use a cross-compiler toolchain installed
# as 'pios-*' or 'i386-elf-*', if one exists. If the host tools ('gcc',
# 'objdump', and so forth) compile for a 32-bit x86 ELF target, that will
# be detected as well. If you have the right compiler toolchain installed
# using a different name, set GCCPREFIX explicitly in conf/env.mk
# try to infer the correct GCCPREFIX
ifndef GCCPREFIX
GCCPREFIX := $(shell sh misc/gccprefix.sh)
endif
# Directories
TOP := .
SRCDIR := $(TOP)
OBJDIR := $(TOP)/obj
UTILSDIR := $(TOP)/misc
TESTDIR := $(TOP)/test
OBJDIRS :=
# Compiler and Linker
CC := $(GCCPREFIX)gcc
LD := $(GCCPREFIX)ld
CFLAGS := -MD -Wno-strict-aliasing -Wno-unused-function -pipe -fno-builtin -nostdinc -fno-stack-protector
LDFLAGS := -nostdlib
ifeq (ENABLE_CCOMP, 1)
CCOMP := ccomp
CCOMP_CFLAGS := -finline-asm -fpacked-structs -fno-sse
CLIGHTGEN := clightgen
CLIGHTGEN_FLAGS := -fall
ifeq ($(V),)
CCOMP_CFLAGS += -v
endif
else
# Uncomment following two lines when you suspect differences between gcc and
# compcert cause problems.
CCOMP := $(GCCPREFIX)gcc
CCOMP_CFLAGS := -MD -Wno-strict-aliasing -Wno-unused-function -pipe -fno-builtin -nostdinc -fno-stack-protector -O2 -g -m32 -D__COMPCERT__
endif
# other tools
PERL := perl
OBJDUMP := $(GCCPREFIX)objdump
OBJCOPY := $(GCCPREFIX)objcopy
DD := $(GCCPREFIX)dd
NM := $(GCCPREFIX)nm
CSCOPE := cscope
# others
GCC_LIB32 := $(shell $(CC) $(CFLAGS) -m32 -print-libgcc-file-name)
ifeq ($(ARCH), amd64)
GCC_LIB64 := $(shell $(CC) $(CFLAGS) -m64 -print-libgcc-file-name)
endif
# If this is the first time building CertiKOS64, please follow the instructions
# in HOW_TO_MAKE_DISK_IMAGE to create a disk image file manually and put it in
# directory $(OBJDIR)/ (default: obj/)
CERTIKOS_IMG := certikos.img
# bochs
BOCHS := bochs
BOCHS_OPT := -q
# try to generate a unique GDB port
GDBPORT := $(shell expr `id -u` % 5000 + 25000)
# qemu
QEMU := qemu-system-x86_64
QEMUOPTS := -smp 4 -hda $(CERTIKOS_IMG) -serial mon:stdio -gdb tcp::$(GDBPORT) -m 2048 -k en-us -hdb certikos_disk.img
QEMUOPTS_KVM := -cpu host -enable-kvm
QEMUOPTS_BIOS := -L $(UTILSDIR)/qemu/
# Targets
.PHONY: all boot kern user deps qemu qemu-nox qemu-gdb mkfs
all: boot kern user link
@./make_image.py
ifdef TEST
@echo "***"
@echo "*** Use Ctrl-a x to exit qemu"
@echo "***"
$(V)$(QEMU) -nographic $(QEMUOPTS)
endif
@echo "All targets are done."
install_img: install_boot install_sys install_user
@echo "CertiKOS is installed on the disk image."
bochs: $(CERTIKOS_IMG) .bochsrc
@echo + start bochs
$(V)$(BOCHS) $(BOCHS_OPT)
.gdbinit: .gdbinit.tmpl
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
@./scripts/set_auto_load.sh
# QEMU doesn't truncate the pcap file. Work around this.
pre-qemu: .gdbinit
@rm -f qemu.pcap
$(V)cp newfs/certikos_disk_new.img certikos_disk.img
qemu: $(CERTIKOS_IMG) pre-qemu
$(V)$(QEMU) $(QEMUOPTS)
qemu-nox: $(CERTIKOS_IMG) pre-qemu
@echo "***"
@echo "*** Use Ctrl-a x to exit qemu"
@echo "***"
$(V)$(QEMU) -nographic $(QEMUOPTS)
qemu-gdb: $(CERTIKOS_IMG) pre-qemu
@echo "***"
@echo "*** Now run 'gdb'." 1>&2
@echo "***"
$(V)$(QEMU) $(QEMUOPTS) -S
qemu-nox-gdb: $(CERTIKOS_IMG) pre-qemu
@echo "***"
@echo "*** Now run 'gdb'." 1>&2
@echo "***"
$(V)$(QEMU) -nographic $(QEMUOPTS) -S
gdb: pre-qemu
@gdb
qemu-kvm: $(CERTIKOS_IMG)
$(V)$(QEMU) $(QEMUOPTS) $(QEMUOPTS_KVM)
qemu-bios: $(CERTIKOS_IMG)
$(V)$(QEMU) $(QEMUOPTS) $(QEMUOPTS_BIOS)
iso: all
$(V)cp $(OBJDIR)/kern/kernel $(UTILSDIR)/iso/boot/kernel
$(V)grub-mkrescue -o $(CERTIKOS_IMG) $(UTILSDIR)/iso
package:
$(V)tar czf ../certikos.tar.gz --exclude=obj --exclude=cscope.* .
cscope:
$(V)rm -rf cscope.*
$(V)find . -name "*.[chsS]" > cscope.files
$(V)cscope -bkq -i cscope.files
# Sub-makefiles
include boot/Makefile.inc
include user/Makefile.inc
include kern/Makefile.inc
deps: $(OBJDIR)/.deps
$(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(dir)/*.d))
$(V)mkdir -p $(@D)
$(V)$(PERL) $(UTILSDIR)/mergedep.pl $@ $^
-include $(OBJDIR)/.deps
clean:
$(V)rm -rf $(OBJDIR) .gdbinit certikos.img
$(V)find . -name "*.[v]" -delete
mkfs:
@echo "Copying the new file system disk image..."
$(V)cp newfs/certikos_disk_new.img certikos_disk.img
@echo "Done."