-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.apk
343 lines (278 loc) · 9.88 KB
/
Makefile.apk
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# Root 15410 Makefile
# Do not edit this file
#################### RULE HEADER ####################
.PHONY: update query_update print html_doc
all: query_update bootfd.img
############## VARIABLE DEFINITIONS #################
DOC = doxygen
MAKE = gmake
CC = gcc-3.4
LD = ld
AR = ar
OBJCOPY = objcopy
PROJROOT = $(PWD)
# All paths relative to PROJROOT unless otherwise noted
410KDIR = 410kern
410SDIR = spec
410UDIR = 410user
BOOTDIR = boot
STUKDIR = kern
STUUDIR = user
EXTRADIR ?= 410extra
BUILDDIR = temp
# Relative to {410,STU}UDIR
UPROGDIR = progs
# By default, we are offline
UPDATE_METHOD = offline
# Suffix for dependency files
DEP_SUFFIX = dep
###########################################################################
# Libraries!
# These may be overwridden by {,$(STUKDIR)/,$(STUUDIR)/}config.mk
###########################################################################
410KERNEL_LIBS = \
libboot.a \
libelf.a \
liblmm.a \
libmalloc.a \
libmisc.a \
libRNG.a \
libsimics.a \
libstdio.a \
libstdlib.a \
libstring.a \
libx86.a \
## Can't have thrgrp be a default as we don't ship with the requisite files
## in user/ like we did with P2.
410USER_LIBS_EARLY = # libthrgrp.a
410USER_LIBS_LATE = libRNG.a libx86.a libsimics.a libstdio.a libstdlib.a libstring.a libmalloc.a
STUDENT_LIBS_EARLY = libthread.a
STUDENT_LIBS_LATE = libsyscall.a
###########################################################################
# Details of library structure (you do NOT have to read this part!!)
###########################################################################
# _EARLY means "specified early in the compiler command line" and so
# can be taken to mean "can depend on all _LATE files"
# _LATE means "specified late in the compiler command line" and so
# might be taken as "there be daemons here"; in particular
# these libraries may not depend on _EARLY libraries
# or any library in the list before them.
#
# The full command line order is
# 410USER_LIBS_EARLY -- can depend on everything
# STUDENT_LIBS_EARLY -- can depend only on _LATE libs
# 410USER_LIBS_LATE -- must not depend on _EARLY libs
# STUDENT_LIBS_LATE -- must not depend on any other lib group
################# DETERMINATION OF INCLUSION BEHAVIORS #####################
ifeq (0,$(words $(filter %clean,$(MAKECMDGOALS))))
ifeq (0,$(words $(filter print,$(MAKECMDGOALS))))
ifeq (0,$(words $(filter sample,$(MAKECMDGOALS))))
ifeq (0,$(words $(filter %update,$(MAKECMDGOALS))))
DO_INCLUDE_DEPS=1
endif
endif
endif
endif
################ CONFIGURATION INCLUSION #################
-include config.mk
# Infrastructure configuration files
# These may look like fun, but they are NOT FOR STUDENT USE without
# instructor permisison. Almost anything you want to do can be done
# via the top-level config.mk.
-include $(STUKDIR)/config.mk
-include $(STUUDIR)/config.mk
-include $(EXTRADIR)/extra-early.mk
############### TARGET VARIABLES ###############
# FIXME 410ULIBS_LATE is a temporary gross hack; fix later
PROGS = $(410REQPROGS) $(410REQBINPROGS) \
$(STUDENTREQPROGS) $(410TESTS) $(STUDENTTESTS) \
$(EXTRA_TESTS) $(EXTRA_410_TESTS)
410ULIBS_EARLY = $(patsubst %,$(410UDIR)/%,$(410USER_LIBS_EARLY))
410ULIBS_LATE = $(patsubst %,$(410UDIR)/%,$(410USER_LIBS_LATE)) \
$(patsubst %,$(410UDIR)/%,$(410USER_LIBS_LATE))
STUULIBS_EARLY = $(patsubst %,$(STUUDIR)/%,$(STUDENT_LIBS_EARLY))
STUULIBS_LATE = $(patsubst %,$(STUUDIR)/%,$(STUDENT_LIBS_LATE))
################# MISCELLANEOUS VARAIBLES ##############
CRT0 = $(410UDIR)/crt0.o
########### MAKEFILE FILE INCLUSION ##############
# These are optional so that we can use the same Makefile for P1,2,3
# Again, these files are NOT FOR STUDENT USE, and unlike the above,
# we probably won't give you permission to overwrite these. :)
# Boot loader P4
-include $(BOOTDIR)/boot.mk
# Include 410kern control, responsible for 410kern libraries, objects, interim
-include $(410KDIR)/kernel.mk
# Include 410user control, responsible for 410user libraries and programs
-include $(410UDIR)/user.mk
# Infrastructure
-include $(EXTRADIR)/extra-late.mk
# Top level targets
-include $(410KDIR)/toplevel.mk
############# BUILD PARAMETER VARIABLES ################
# Note that this section DEPENDS UPON THE INCLUDES ABOVE
# When generating includes, we do so in the order we do so that it is always
# possible to match <lib/header.h> from 410kern/lib exactly, or from kern/lib
# if so desired, but that files without directory prefixes will match
# 410kern/inc, kern/, kern/inc, then the 410kern/lib/* entries according to
# 410KERNEL_LIBS, which is under external control.
KCFLAGS = -nostdinc -fno-strict-aliasing -fno-builtin -Wall -gstabs -Werror -O0 -m32
KLDFLAGS = -static -Ttext 100000 --fatal-warnings -melf_i386
KINCLUDES = -I$(410KDIR) -I$(410KDIR)/inc \
-I$(410SDIR) \
-I$(STUKDIR) -I$(STUKDIR)/inc \
$(patsubst lib%.a,-I$(410KDIR)/%,$(410KERNEL_LIBS))
UCFLAGS = -nostdinc -fno-strict-aliasing -fno-builtin -Wall -gstabs -Werror -O0 -m32
ULDFLAGS = -static -Ttext 1000000 --fatal-warnings -melf_i386 --entry=_main
UINCLUDES = -I$(410SDIR) -I$(410UDIR) -I$(410UDIR)/inc \
-I$(STUUDIR)/inc \
$(patsubst %.a,-I$(410UDIR)/%,$(410USER_LIBS_EARLY) $(410USER_LIBS_LATE)) \
$(patsubst %.a,-I$(STUUDIR)/%,$(STUDENT_LIBS_EARLY) $(STUDENT_LIBS_LATE))
TMP_410KOBJS_NOT_DOTO = $(filter-out %.o,$(ALL_410KOBJS))
ifneq (,$(TMP_410KOBJS_NOT_DOTO))
$(error "Feeling nervous about '$(TMP_410KOBJS_NOT_DOTO)'")
endif
ALL_410KOBJS_DEPS = $(ALL_410KOBJS:%.o=%.$(DEP_SUFFIX))
TMP_410UOBJS_NOT_DOTO = $(filter-out %.o,$(ALL_410UOBJS))
ifneq (,$(TMP_410UOBJS_NOT_DOTO))
$(error "Feeling nervous about '$(TMP_410UOBJS_NOT_DOTO)'")
endif
ALL_410UOBJS_DEPS = $(ALL_410UOBJS:%.o=%.$(DEP_SUFFIX))
TMP_STUKOBJS_NOT_DOTO = $(filter-out %.o,$(ALL_STUKOBJS))
ifneq (,$(TMP_STUKOBJS_NOT_DOTO))
$(error "Feeling nervous about '$(TMP_STUKOBJS_NOT_DOTO)'")
endif
ALL_STUKOBJS_DEPS = $(ALL_STUKOBJS:%.o=%.$(DEP_SUFFIX))
TMP_STUUOBJS_NOT_DOTO = $(filter-out %.o,$(ALL_STUUOBJS))
ifneq (,$(TMP_STUUOBJS_NOT_DOTO))
$(error "Feeling nervous about '$(TMP_STUUOBJS_NOT_DOTO)'")
endif
ALL_STUUOBJS_DEPS = $(ALL_STUUOBJS:%.o=%.$(DEP_SUFFIX))
STUUPROGS_DEPS = $(STUUPROGS:%=%.dep)
410UPROGS_DEPS = $(410UPROGS:%=%.dep)
############## UPDATE RULES #####################
update:
./update.sh $(UPDATE_METHOD)
query_update:
./update.sh $(UPDATE_METHOD) query
################### GENERIC RULES ######################
%.$(DEP_SUFFIX): %.S
$(CC) $(CFLAGS) -DASSEMBLER $(INCLUDES) -M -MP -MF $@ -MT $(<:.S=.o) $<
%.$(DEP_SUFFIX): %.s
@echo "You should use the .S file extension rather than .s"
@echo ".s does not support precompiler directives (like #include)"
@false
%.$(DEP_SUFFIX): %.c
$(CC) $(CFLAGS) $(INCLUDES) -M -MP -MF $@ -MT $(<:.c=.o) $<
%.o: %.S
$(CC) $(CFLAGS) -DASSEMBLER $(INCLUDES) -c -o $@ $<
$(OBJCOPY) -R .comment -R .note $@ $@
%.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
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
$(OBJCOPY) -R .comment -R .note $@ $@
%.a:
rm -f $@
$(AR) rc $@ $^
################ PATTERNED VARIABLE ASSIGNMENTS ##################
$(410KDIR)/%: CFLAGS=$(KCFLAGS)
$(410KDIR)/%: INCLUDES=$(KINCLUDES)
$(410KDIR)/%: LDFLAGS=$(KLDFLAGS)
$(STUKDIR)/%: CFLAGS=$(KCFLAGS)
$(STUKDIR)/%: INCLUDES=$(KINCLUDES)
$(STUKDIR)/%: LDFLAGS=$(KLDFLAGS)
$(410UDIR)/%: CFLAGS=$(UCFLAGS)
$(410UDIR)/%: INCLUDES=$(UINCLUDES)
$(410UDIR)/%: LDFLAGS=$(ULDFLAGS)
$(STUUDIR)/%: CFLAGS=$(UCFLAGS)
$(STUUDIR)/%: INCLUDES=$(UINCLUDES)
$(STUUDIR)/%: LDFLAGS=$(ULDFLAGS)
################# USERLAND PROGRAM UNIFICATION RULES #################
$(410REQPROGS:%=$(BUILDDIR)/%): \
$(BUILDDIR)/%: $(410UDIR)/$(UPROGDIR)/%
mkdir -p $(BUILDDIR)
cp $< $@
$(410REQBINPROGS:%=$(BUILDDIR)/%): \
$(BUILDDIR)/%: $(410UDIR)/$(UPROGDIR)/%
mkdir -p $(BUILDDIR)
cp $< $@
$(410TESTS:%=$(BUILDDIR)/%) : \
$(BUILDDIR)/% : $(410UDIR)/$(UPROGDIR)/%
mkdir -p $(BUILDDIR)
cp $< $@
$(EXTRA_410_TESTS:%=$(BUILDDIR)/%) : \
$(BUILDDIR)/% : $(410UDIR)/$(UPROGDIR)/%
mkdir -p $(BUILDDIR)
cp $< $@
$(STUDENTREQPROGS:%=$(BUILDDIR)/%) : \
$(BUILDDIR)/% : $(STUUDIR)/$(UPROGDIR)/%
mkdir -p $(BUILDDIR)
cp $< $@
$(STUDENTTESTS:%=$(BUILDDIR)/%) : \
$(BUILDDIR)/% : $(STUUDIR)/$(UPROGDIR)/%
mkdir -p $(BUILDDIR)
cp $< $@
############## MISCELLANEOUS TARGETS #################
html_doc:
$(DOC) doxygen.conf
print:
enscript -2r -p kernel.ps README.dox \
`find ./kern/ -type f -regex '.*\.[chS]' | sort`
################# CLEANING RULES #####################
.PHONY: clean veryclean
clean:
rm -f $(CRT0)
rm -f $(FINALCLEANS)
rm -f $(ALL_410KOBJS)
rm -f $(ALL_410KOBJS_DEPS)
rm -f $(410KCLEANS)
rm -f $(ALL_410UOBJS)
rm -f $(ALL_410UOBJS_DEPS)
rm -f $(410UCLEANS)
rm -f $(410UPROGS:%=%.o)
rm -f $(410UPROGS_DEPS)
rm -f $(ALL_STUKOBJS)
rm -f $(ALL_STUKOBJS_DEPS)
rm -f $(STUKCLEANS)
rm -f $(ALL_STUUOBJS)
rm -f $(ALL_STUUOBJS_DEPS)
rm -f $(STUUCLEANS)
rm -f $(STUUPROGS:%=%.o)
rm -f $(STUUPROGS_DEPS)
rm -f $(BOOT_CLEANS)
veryclean: clean
rm -rf doc kernel.ps bootfd.img kernel $(BUILDDIR)
rm -f $(FINALVERYCLEANS)
%clean:
$(error "Unknown cleaning target")
########### DEPENDENCY FILE INCLUSION ############
ifeq (1,$(DO_INCLUDE_DEPS))
ifneq (,$(ALL_410KOBJS))
-include $(ALL_410KOBJS_DEPS)
endif
ifneq (,$(ALL_STUKOBJS))
-include $(ALL_STUKOBJS_DEPS)
endif
ifneq (,$(ALL_410UOBJS))
-include $(ALL_410UOBJS_DEPS)
endif
ifneq (,$(ALL_STUUOBJS))
-include $(ALL_STUUOBJS_DEPS)
endif
ifneq (,$(410UPROGS_DEPS))
-include $(410UPROGS_DEPS)
endif
ifneq (,$(STUUPROGS_DEPS))
-include $(STUUPROGS_DEPS)
endif
endif
########### MANDATE CLEANING AS ONLY TARGETS ############
ifneq (0,$(words $(filter %clean,$(MAKECMDGOALS))))
# The target includes a make target
ifneq (0, $(words $(filter-out %clean,$(MAKECMDGOALS))))
# There is another target on the list
$(error "Clean targets must run by themselves")
endif
endif