-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (51 loc) · 1.71 KB
/
Copy pathMakefile
File metadata and controls
65 lines (51 loc) · 1.71 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
BINARY=os.bin
CODEDIRS=. lib
INCDIRS=. ./include/ # can be list
ASDIRS=./lib/assembler
CCPATH=~/opt/cross/bin
CC=i686-elf-gcc
ASM=i686-elf-as
OPT=-O2
# generate files that encode make rules for the .h dependencies
DEPFLAGS=-MP -MD
# automatically add the -I onto each include directory
CFLAGS=-std=gnu99 -ffreestanding -Wall -Wextra -g $(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEPFLAGS)
# for-style iteration (foreach) and regular expression completions (wildcard)
CFILES=$(foreach D,$(CODEDIRS),$(wildcard $(D)/*.c))
ASFILES=$(foreach D,$(ASDIRS),$(wildcard $(D)/*.s))
# regular expression replacement
OBJECTS=$(patsubst %.c,%.o,$(CFILES))
ASMBS=$(patsubst %.s,%.o,$(ASFILES))
DEPFILES=$(patsubst %.c,%.d,$(CFILES))
all: $(BINARY)
$(BINARY): $(OBJECTS) $(ASMBS)
@echo "Linking ... "
$(CCPATH)/$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^
@echo "Done":
# only want the .c file dependency here, thus $< instead of $^.
#
%.o:%.c
$(CCPATH)/$(CC) $(CFLAGS) -c -o $@ $<
%.o:%.s
# $(notdir $@) - to get basename, later on to put everything (.o files) in one directory
# $(CCPATH)/$(CC) $(CFLAGS) -c -o $@ $<
$(CCPATH)/$(ASM) -o $@ $<
clean:
rm -rf $(BINARY) $(OBJECTS) $(ASMBS) $(DEPFILES)
# shell commands are a set of keystrokes away
distribute: clean
tar zcvf dist.tgz *
# @ silences the printing of the command
# $(info ...) prints output
diff:
$(info The status of the repository, and the volume of per-file changes:)
@git status
@git diff --stat
# include the dependencies
-include $(DEPFILES)
run:
qemu-system-i386 -kernel $(BINARY)
debug:
qemu-system-i386 -s -S -kernel $(BINARY)
# add .PHONY so that the non-targetfile - rules work even if a file with the same name exists.
.PHONY: all clean distribute diff