-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (73 loc) · 2.2 KB
/
Copy pathMakefile
File metadata and controls
93 lines (73 loc) · 2.2 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
82
83
84
85
86
87
88
89
90
91
92
93
# Makefile for the project.
# Best viewed with tabs set to 4 spaces.
CC = gcc
LD = ld
BI = ./bin
BU = ./build
RC = ./src
# Where to locate the kernel in memory
KERNEL_ADDR = 0x1000
# Compiler flags
#-fno-builtin: Don't recognize builtin functions that do not begin
# with '__builtin_' as prefix.
#
#-fomit-frame-pointer: Don't keep the frame pointer in a register for
# functions that don't need one.
#
#-make-program-do-what-i-want-it-to-do:
# Turn on all friendly compiler flags.
#
#-O2: Turn on all optional optimizations except for loop
# unrolling and function inlining.
#
#-c: Compile or assemble the source files, but do not link.
#
#-Wall: All of the `-W' options combined (all warnings on)
CCOPTS = -Wall -g -m32 -c -fomit-frame-pointer -O2 -fno-builtin
# Linker flags
#-nostartfiles: Do not use the standard system startup files when linking.
#
#-nostdlib: Don't use the standard system libraries and startup files
# when linking. Only the files you specify will be passed
# to the linker.
#
LDOPTS = -nostartfiles -nostdlib -melf_i386
# Makefile targets
all: bootblock buildimage kernel image
kernel: $(BI)/kernel.o
$(LD) $(LDOPTS) -Ttext $(KERNEL_ADDR) -o $(BU)/kernel $<
bootblock: $(BI)/bootblock.o
$(LD) $(LDOPTS) -Ttext 0x0 -o $(BU)/bootblock $<
buildimage: $(BI)/buildimage.o
$(CC) -o $(BU)/buildimage $<
# Build an image to put on the floppy
image: $(BU)/bootblock $(BU)/buildimage $(BU)/kernel
$(BU)/buildimage --extended $(BU)/bootblock $(BU)/kernel
# Put the image on the usb stick (these two stages are independent, as both
# vmware and bochs can run using only the image file stored on the harddisk)
boot: image
dd if=./image of=/dev/sdb bs=512
# Clean up!
# Cannot delete bootblock.o
clean:
rm -f $(BU)/*
rm -f $(BI)/buildimage.o $(BI)/kernel.o
# No, really, clean up!
distclean: clean
rm -f *~
rm -f \#*
rm -f *.bak
rm -f serial.out
rm -f bochsout.txt
# How to compile buildimage
$(BI)/buildimage.o:
$(CC) -c -o $@ $(RC)/buildimage.c
# How to compile a C file
$(BI)/%.o:$(RC)/%.c
$(CC) $(CCOPTS) -o $@ $<
# How to assemble
$(BI)/%.o:$(RC)/%.s
$(CC) $(CCOPTS) -o $@ $<
# How to produce assembler input from a C file
$(RC)/%.s:$(RC)/%.c
$(CC) $(CCOPTS) -S -o $@ $<