-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (112 loc) · 3.86 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
# Root 18-342 Makefile
# Borrowed from 15410 Makefile -- thanks nwf and co.
#
# Change this to blank if you are on the gumstix
CCPREFIX = arm-linux-
#CCPREFIX =
MAKEFLAGS += -rR
############### RULE HEADER #####################
# The packages are all phony targets. They produce files in the bin directory.
# Make sure there are no name clashes. Add new ones here if you make your own
# tests (which I recommend you do).
PACKAGES = hello exit twister splat typo rot13 mole
.PHONY: all package clean clobber $(PACKAGES)
all: package kernel
############### ENVIRONMENT #####################
CC = $(CCPREFIX)gcc
LD = $(CCPREFIX)ld
AR = $(CCPREFIX)ar
OBJCOPY = $(CCPREFIX)objcopy
RM = rm -f
ROOT = $(PWD)
KDIR = $(ROOT)/kernel
UDIR = $(ROOT)/uboot
TDIR = $(ROOT)/tasks
TLIBCDIR = $(TDIR)/libc
LIBGCC = `$(CC) -print-libgcc-file-name`
############## CONFIGURATION ####################
# Entry point addresses
KLOAD_ADDR = 0xa3000000
TLOAD_ADDR = 0xa0000000
# These are extra warning that you may find helpful. These may give spurious
# warnings but are good for debugging code.
CWARNINGS_NOISY = -Wformat=2 -Wstrict-aliasing=2 -Wshadow -Wcast-qual \
-Wstrict-prototypes -Wold-style-definition
CWARNINGS_SAFE = -Wall -Wextra -Wno-unused-parameter -Wpointer-arith \
-Wwrite-strings -Wsystem-headers
CWARNINGS = -Werror $(CWARNINGS_SAFE)
CWARNINGS1 = $(CWARNINGS_SAFE) $(CWARNINGS_NOISY)
KCFLAGS = -O3 -ffreestanding -ffixed-r8 -nostdinc $(CWARNINGS)
TCFLAGS = -O3 -ffreestanding -nostdinc $(CWARNINGS)
ASFLAGS = -nostdinc -Wall -Wextra -Werror -DASSEMBLER
KLDFLAGS = -nostdlib -N --fatal-warnings --warn-common -Ttext $(KLOAD_ADDR)
TLDFLAGS = -nostdlib -N --fatal-warnings --warn-common -Ttext $(TLOAD_ADDR)
KINCLUDES = -I$(UDIR)/include -I$(KDIR)/include
TINCLUDES = -I$(TLIBCDIR)/include
########### SUBFOLDER INCLUDES ##################
include $(UDIR)/uboot.mk
include $(KDIR)/kernel.mk
include $(TDIR)/tasks.mk
########### PATTERNED VARIABLES #################
$(TDIR)/%: INCLUDES=$(TINCLUDES)
$(KDIR)/%: INCLUDES=$(KINCLUDES)
$(UDIR)/%: INCLUDES=$(KINCLUDES)
$(TDIR)/%: CFLAGS=$(TCFLAGS)
$(KDIR)/%: CFLAGS=$(KCFLAGS)
$(UDIR)/%: CFLAGS=$(KCFLAGS)
$(TDIR)/%: LDFLAGS=$(TLDFLAGS)
$(KDIR)/%: LDFLAGS=$(KLDFLAGS)
$(UDIR)/%: LDFLAGS=$(KLDFLAGS)
############### PACKAGE RULES ###################
package: $(PACKAGES)
kernel : $(KERNEL).bin
############### GENERIC RULES ###################
%.dep: %.S
@echo DEP $(notdir $<)
@$(CC) $(ASFLAGS) -DASSEMBLER $(INCLUDES) -M -MP -MF $@ -MT $(<:.S=.o) $<
%.dep: %.s
@echo "You should use the .S file extension rather than .s"
@echo ".s does not support precompiler directives (like #include)"
@false
%.dep: %.c
@echo DEP $(notdir $<)
@$(CC) $(CFLAGS) $(INCLUDES) -M -MP -MF $@ -MT $(<:.c=.o) $<
%.o: %.S
@echo CC $(notdir $<)
@$(CC) $(ASFLAGS) $(INCLUDES) -c -o $@ $<
%.o: %.s
@echo "You should use the .S file extension rather than .s"
@echo ".s does not support precompiler directives (like #include)"
@false
%.o: %.c
@echo CC $(notdir $<)
@$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
%.a:
@echo AR $(notdir $@)
@$(AR) rc $@ $^
%.bin: %
@echo OBJCOPY $(notdir $<) $(notdir $@)
@$(OBJCOPY) -O binary $< $@
############### CLEANING RULES ##################
clean:
@echo CLEAN objects
@$(RM) $(ALL_OBJS)
@echo CLEAN deps
@$(RM) $(ALL_OBJS:%.o=%.dep)
@echo CLEAN archives/misc
@$(RM) $(ALL_CLEANS)
clobber: clean
@echo CLEAN packages
@$(RM) $(PACKAGE_TARGETS)
@echo CLEAN package bins
@$(RM) $(PACKAGE_TARGETS:%=%.bin)
@echo CLEAN others
@$(RM) $(ALL_CLOBBERS)
########### DEPENDENCY FILE INCLUSION ############
ifeq (0,$(words $(findstring clean,$(MAKECMDGOALS))))
ifeq (0,$(words $(findstring clobber,$(MAKECMDGOALS))))
ifneq (,$(ALL_OBJS))
-include $(ALL_OBJS:.o=.dep)
endif
endif
endif