-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.new
504 lines (424 loc) · 16.8 KB
/
Makefile.new
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# ##########################-*-makefile-*- ###################################
# 1. Recursive make considered harmful.
# 2. BUILD = system arch on which we are configuring and compiling
# TARGET = system arch for which new compilers tool will generate code
# HOST = system on which K42 will run
# 3. Object/executables go into separate tree from sourcea
# 4. Included makefiles use pattern rules
# 5. Included makefiles included directly from top-level makefile
# 6. Generic pattern rules at the end of this makefile provide basic targets
# ############################################################################
# Basic Strategy of this makefile
# 1. A "bootstrap" phase installs basic include files, builds basic tools
# needed for later compilation, and generates include files using
# these tools
# 2. A "depend" phase which generates dependencies between sources, headers,
# objects, and targets
# 3. A "all" phase, the normal build phase which covers all of the first two
# phases once they've been done and build a kernel, servers, host binaries,
# etc.
# 4. An "install" phase, which moves generated libraries and such into the
# install directory
#
# + "bootstrap" targets build and install basic include files
# tools for standard making.
# * Targets *
# - bootstrap_scripts
# - bootstrap_includes
# - bootstrap_tools
# - bootstrap_generate
# - bootstrap_tools2 (has to run after generate)
# - bootstrap
# - bootstrap_clean
# * Variables *
# - $(bootstrap_incs): a list of all include files that can
# be installed directly without additional generation
# - $(bootstrap_binaries): a list of scripts and binaries that need
# can be built and installed once the base includes are in place
# - $(bootstrap_gens): a list of files to generate for bootstrapping
# using the bootstrap tools
# - $(bootstrap_objs): a list of all targets and intermediates
# built for the base bootstrapping system
#
# + "depend" builds all of the dependencies between targets once the bootstrap
# includes and bootstrap generates are done and installed.
#
# + "all" builds the complete system once all of the bootstrapping and
# dependencies are in place
#
# * Targets *
# includes: rebuild as necessary and install all include files
# libraries: rebuild as necessary and install all libraries
# servers: rebuild as necessary and install all servers
# kernel: rebuild as necessary the kernel zimage
# binaries: rebuild as necessary and install test binaries
# users: install user home directories
# config-files: install system config files
# clean: remove all non-bootstrap targets
#
# * Variables *
# $(host_libraries) -
# $(host_servers) -
# $(host_includes) -
#
# ##############################################################################
#
# Basic build configuration.
D = full
OS = $(shell uname -s)
BUILD = $(shell uname -m)
HOST = powerpc
TARGET = $(BUILD)
SITE = unm
# Build our source and output paths from above.
O = ..
H = .
S = $(O)/$(HOST)/$(D)Deb
B = $(S)/os/kexec
L = ../linux-030
# Install directories, including top level, libraries, and root image
I = $(O)/install/$(HOST)/$(D)Deb
ILIB = $(O)/install/lib/$(HOST)/$(D)Deb
IROOT = $(I)/kitchroot
STUBGEN_INC = $(O)/install/include/stubgen/arch/$(HOST)
TOOLS = $(O)/install/tools/$(OS)_$(BUILD)/$(HOST)
U = /u/kitchawa/k42-packages
IMG = $(U)/$(D)Deb.Img.4
# Include makefile that defines host-specific information
include Make-$(HOST).sub
# 64-bit cross-compile tools.
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)ld
STRIP = $(CROSS_COMPILE)strip
NM = $(CROSS_COMPILE)nm
AR = $(CROSS_COMPILE)ar
AS = $(CROSS_COMPILE)as
OBJDUMP = $(CROSS_COMPILE)objdump
# 32-bit cross-compile tools.
CC32 = $(CROSS32_COMPILE)gcc
LD32 = $(CROSS32_COMPILE)ld
OBJCOPY32 = $(CROSS32_COMPILE)objcopy
STRIP32 = $(CROSS32_COMPILE)strip
# Build machine native-compile tools.
BUILDCC = gcc
BUILDCXX = g++
BUILDCFLAGS = -g -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
BUILDCXXFLAGS = $(BUILDCFLAGS)
MKDIR = mkdir -p
GZIP = gzip
MV = mv
RM = rm -f
CP = cp
PERL = perl
AWK = awk
STUBGEN = $(TOOLS)/stubgen/stubgen
CHMOD = chmod
SED = sed
ECHO = echo
YACC = byacc
EXIT = exit
# For script.sed generated scripts AND NOTHING ELSE
INSTALL = install
EXTRACTPROG = ext_elf64
MKANCHOR = $(strip $(shell cd ..; /bin/pwd))
MKTOOLBIN = $(strip $(shell mkdir -p $(TOOLS); cd $(TOOLS); /bin/pwd))
# Target machine flags
#
# XXX Note that where the code refers to TARGET_MACHINE, it should instead
# refer to HOST_MACHINE. The TARGET_MACHINE macro currently exists
# for compatibility reasons with the old makefile system XXX
CFLAGS = -DTARGET_MACHINE="$(HOST)" -DHOST_MACHINE="$(FULLHOST)" \
-D__GNU_AS__ -U$(HOST) -DGCC3 \
-Wa,-strip-local-absolute -fPIC -mminimal-toc -Wall -Werror -O0 -g \
-DKFS_ENABLED -DK42 -D_REENTRANT -nostdinc $($(HOST)_CFLAGS)
CXXFLAGS = -fno-rtti -nostdinc++ -fno-exceptions $(CFLAGS)
IFLAGS = -I$(O)/install/include \
-I$(IMG)/usr/$(FULLHOST)-linux/include \
-I$(L)/include \
-I$(O)/install/gcc-include/arch/$(HOST) \
-I$(O)/install/include/stubgen/arch/$(HOST) \
$($(HOST)_IFLAGS)
LXIFLAGS = -I$(L)/arch/k42/include \
-I$(L)/include
# Common flags for building specific parts of K42
#
# Linking user-level K42 binaries
bin_lflags = -Wl,-dynamic-linker,/usr/klib/ld64.so.1 \
-Wl,-rpath,/klib:/usr/klib \
-L$(O)/install/lib/$(HOST)/$(D)Deb \
-L$(O)/install/$(HOST)/$(D)Deb/kitchroot/klib \
-L$(IMG)/usr/klib
bin_libs = -lk42sys -lc
bin_lib_deps = $(O)/install/$(HOST)/$(D)Deb/kitchroot/klib/libk42sys.so
# Linking servers
srv_lflags = $(bin_lflags)
srv_libs = -llk26 -lvirtfs -lfs -lsrv -lk42sys -lc
srv_ldeps1 = liblk26.a libvirtfs.a libfs.a libsrv.a
srv_lib_deps = $(addprefix $(O)/install/lib/$(HOST)/$(D)Deb/, $(srv_ldeps1)) \
$(bin_lib_deps)
################################################################################
# Functions for supporting later targets in included makefiles
# Call for expanding a stub directory into a full set of stub generator
# targets
stubgen_targets = $(1)/stub/Stub%.H $(1)/meta/Meta%.H $(1)/meta/TplMeta%.H \
$(1)/xobj/X%.H $(1)/xobj/TplX%.H $(1)/Stub%.C $(1)/X%.C $(1)/tmpl/TplX%.I
stubgen_objects = $(1)/stub/Stub$(2).H $(1)/meta/Meta$(2).H \
$(1)/meta/TplMeta$(2).H $(1)/xobj/X$(2).H $(1)/xobj/TplX$(2).H \
$(1)/Stub$(2).C $(1)/X$(2).C $(1)/tmpl/TplX$(2).I
stubgen_headers = $(STUBGEN_INC)/stub/Stub$(1).H \
$(STUBGEN_INC)/meta/Meta$(1).H $(STUBGEN_INC)/meta/TplMeta$(1).H \
$(STUBGEN_INC)/xobj/X$(1).H $(STUBGEN_INC)/xobj/TplX$(1).H \
$(STUBGEN_INC)/tmpl/TplX$(1).I
# Call for printing status of commands in different forms
# If V=1, we echo the commands as normal, if V=2, show out-of-date depends.
V = 0
ifeq "$(V)" "0"
.SILENT:
status = printf " %-7s %s\n" $(1) "$(subst $(O)/,,$(2))"
else
ifeq "$(V)" "2"
.SILENT:
status = printf " %-7s %s [%s]\n" $(1) \
"$(subst $(O)/,,$(2))" $(notdir $(firstword $?))
endif
endif
################################################################################
# Our non-file targets that don't depend on later variable definitions
.PHONY: k42-vmlinux k42-zImage
.PHONY: includes libraries servers binaries kernel config-files users dirs
.PHONY: config all clean FORCE bootstrap
.PHONY: bootstrap_includes bootstrap_gen bootstrap_tools bootstrap_tools2 bootstrap_clean
# Default target is just the directory skeleton and our bootable kernel.
kernel: dirs k42-vmlinux
k42-vmlinux: dirs includes libraries $(S)/os/servers/baseServers/baseServers $(S)/os/k42-vmlinux
# For some machines we need a compressed kernel.
k42-zImage: dirs $(S)/os/servers/baseServers/baseServers $(S)/os/k42-zImage
all: dirs includes libraries servers binaries users config-files k42-vmlinux
# Just print some debug information and exit.
config:
@echo build $(D)-debug K42 on $(BUILD) $(OS) for $(HOST) from $(OBJS)
# Delete everything we built.
clean:
$(call status, RM, $(wildcard $(OBJS)))
$(RM) $(wildcard $(OBJS))
################################################################################
# Real Rules begin here
################################################################################
# Start by initializating some key variables that are added to as
# submakefiles are included.
################################################################################
# Tools bootstrap rules
#
include tools/build/shared/Make.sub
include tools/build/shared/genmap/Make.sub
include tools/build/shared/k42login/Make.sub
include tools/build/shared/mkserv/Make.sub
include tools/build/shared/relocate/Make.sub
include tools/build/shared/stubgen/elf/Make.sub
include tools/build/shared/stubgen/extract/Make.sub
include tools/build/shared/stubgen/grammar/Make.sub
include tools/build/shared/stubgen/scripts/Make.sub
include tools/build/shared/thinwire/Make.sub
include tools/etc/Make.sub
include tools/hwtools/Make.sub
include tools/misc/Make.sub
include tools/misc/kmon/Make.sub
include tools/misc/ktrace2ltt/Make.sub
include tools/misc/pem/Make.sub
include os/servers/kfs/tools/Make.sub
################################################################################
# Normal Rules
#
# A number of special variables are used over the course of the included
# makefiles. In particular:
# - $(OBJS) contains targets we build that directories
# need to be created for and that we clean
# - $(baseServers_objs) contains objects that need to be included in
# baseServers
# - $(lib_includes) include files that need to be installed
# - $(build_servers) servers that need to be built
# - $(install_binaries) user-level binaries that need to be built
# - $(boot_servers) servers that need to be packaged for booting
# Rule for how to incrementally link our kernel objects.
$(S)/os/k%objs.o:
$(call status, LD, $@)
$(LD) -r $^ -o $@
# Include rules for how to build the kernel itself
# Current subobjects are: kbootobjs.o kinitobjs.o kexceptobjs.o
# kmemobjs.o kprocobjs.o kstubobjs.o kbilgeobjs.o
# ktraceobjs.o ksysobjs.o klinobjs.o
include os/Make.sub
# various related libraries that span multiple directories
# - $(libbase_objs) - $(libk_objs)
# - $(libnative_objs)- $(libemu_objs)
# - $(libfs_objs) - $(libvirt_objs)
# - $(liblk_objs) - $(libsrv_objs)
# Libraries that should be built before building servers and the kernel are
# listed in the variable $(build_libraries)
build_libraries = $(O)/install/lib/$(HOST)/$(D)Deb/libk.a \
$(O)/install/lib/$(HOST)/$(D)Deb/libemu.a \
$(O)/install/lib/$(HOST)/$(D)Deb/libbase.a
include lib/libc/cobj/Make.sub # Cobj stubgen first
include lib/libc/cobj/sys/Make.sub
include lib/libc/alloc/Make.sub
include lib/libc/io/Make.sub # IO stubgen before fslib stubgen
include lib/libc/fslib/Make.sub
include lib/libc/fslib/virtfs/Make.sub
include lib/libc/misc/Make.sub
include lib/libc/scheduler/Make.sub
include lib/libc/stdlib/Make.sub
include lib/libc/sync/Make.sub
include lib/libc/sys/arch/$(HOST)/Make.sub
include lib/libc/sys/Make.sub
include lib/libc/trace/Make.sub
include lib/libc/usr/Make.sub
include lib/lk/Make.sub
include kitch-linux/lib/emu/arch/$(HOST)/Make.sub
include kitch-linux/lib/emu/Make.sub
include lib/gcc/Make.sub
include lib/Make.sub
# Makefiles from kernel objects
include os/boot/arch/$(HOST)/Make.sub
include os/kernel/init/Make.sub
include os/kernel/defines/Make.sub
include os/kernel/exception/Make.sub
include os/kernel/mem/Make.sub
include os/kernel/proc/Make.sub
include os/kernel/stubtest/Make.sub
include os/kernel/bilge/Make.sub
include os/kernel/trace/Make.sub
include os/kernel/sys/Make.sub
include os/kernel/linux/Make.sub
# Include library submakefiles (currently just libk.a)
# This defines the following variables that define hte objects that go in
# Include server submakefiles
include os/servers/dev/Make.sub
include os/servers/k42Ramfs/Make.sub
include os/servers/kfs/Make.sub
include os/servers/mountPoint/Make.sub
include os/servers/loadImage/Make.sub
include os/servers/nfs/Make.sub
include os/servers/ois/Make.sub
include os/servers/pipe/Make.sub
include os/servers/pty/Make.sub
include os/servers/procfs/Make.sub
include os/servers/reboot/arch/$(HOST)/Make.sub
include os/servers/sample/Make.sub
include os/servers/shell/Make.sub
include os/servers/traced/Make.sub
include os/servers/unionfs/Make.sub
include os/servers/userProc/Make.sub
include os/servers/baseServers/Make.sub # has to be last of the servers
include os/servers/Make.sub # construct bootServers.o
include usr/Make.sub
include bin/sysctl/Make.sub # build host user-land tools
include bin/Make.sub
include kitch-linux/tests/linux/Make.sub
include kitch-linux/tests/mixed/Make.sub
include kitch-linux/tests/pthread/Make.sub
include kitch-linux/etc/Make.sub # install configs in kitchroot
include kitch-linux/ketc/Make.sub
include kitch-linux/users/mysql/Make.sub
include kitch-linux/users/pem/Make.sub
include kitch-linux/users/pftest/Make.sub
include kitch-linux/users/postmark/Make.sub
include kitch-linux/users/regress/Make.sub
include kitch-linux/users/regress-hw/Make.sub
include kitch-linux/users/root/Make.sub
################################################################################
# Rules for building kernel libraries that span directories
################################################################################
OBJS += $(build_libraries)
OBJS += $(libk_objs) $(libbase_objs)
$(O)/install/lib/$(HOST)/$(D)Deb/libk.a: $(libk_objs)
$(call status, AR, $@)
$(AR) crs $@ $?
$(O)/install/lib/$(HOST)/$(D)Deb/libbase.a: $(libbase_objs)
$(call status, AR, $@)
$(AR) crs $@ $?
################################################################################
# Bootstrapping Rules
# ##############################################################################
bootstrap_objs += $(bootstrap_scrs) $(bootstrap_incs) $(bootstrap_binaries) $(bootstrap_gens) $(bootstrap_binaries2)
bootstrap_scripts: dirs $(bootstrap_scrs)
bootstrap_includes: dirs bootstrap_scripts $(bootstrap_incs)
bootstrap_tools: dirs bootstrap_includes $(bootstrap_binaries)
bootstrap_generate: dirs bootstrap_scripts bootstrap_includes bootstrap_tools
bootstrap_generate: $(call stubgen_headers,Obj)
bootstrap_generate: $(bootstrap_gens)
bootstrap_tools2: dirs bootstrap_generate $(bootstrap_binaries2)
bootstrap_clean:
$(call status, RM, $(wildcard $(bootstrap_objs)))
$(RM) -f $(wildcard $(bootstrap_objs))
bootstrap: dirs bootstrap_scripts bootstrap_includes bootstrap_tools bootstrap_generate bootstrap_tools2
###############################################################################
# Phony targets expanded from rules defined above
$(build_servers): $(build_libraries)
servers: libraries $(build_servers)
libraries: includes $(build_libraries)
binaries: $(install_binaries) $(build_libraries)
includes: $(lib_includes)
configs: $(install_configs)
users: $(install_users)
kitchroot: servers binaries configs users
# Now that OBJS is totally expanded, generate our directory list from it.
DIRS = $(sort $(foreach obj, $(OBJS) $(install_configs) $(install_users) $(install_binaries) $(install_servers) $(bootstrap_incs) $(bootstrap_gens) $(bootstrap_scrs) $(bootstrap_binaries) $(bootstrap_binaries2) $(bootstrap_objs), $(dir $(obj))))
dirs: $(DIRS)
# This is always the last rule: it needs OBJS to be totally expanded.
$(DIRS):
$(call status, MKDIR, $@)
$(MKDIR) $@
showdirs:
echo $(DIRS)
showobjs:
echo $(OBJS)
showlibbase:
echo $(libbase_objs)
################################################################################
# Default pattern rules
#
# These pattern rules are sufficient to generate many simple targets, especially
# by customizing a dependency with a customization of a cflag or include. Many
# targets still need custom pattern rules, however, and those are declared in
# makefiles that are included prior to these rules
# Basic C and C++ compilation includes
$(S)/%.o: $(H)/%.C
$(call status, CXX, $@)
$(CXX) $(CXXFLAGS) $(IFLAGS) -c $< -o $@
$(S)/%.o: $(S)/%.C
$(call status, CXX, $@)
$(CXX) $(CXXFLAGS) $(IFLAGS) -c $< -o $@
$(S)/%.o: $(H)/%.c
$(call status, CC, $@)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
$(S)/%.o: $(S)/%.c
$(call status, CC, $@)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
# Basic include file installation
$(O)/install/include/%.H: $(H)/lib/libc/%.H
$(call status, INSTALL, $@)
$(CP) $< $@
$(O)/install/include/%.h: $(H)/lib/libc/%.h
$(call status, INSTALL, $@)
$(CP) $< $@
$(O)/install/include/%.I: $(H)/lib/libc/%.I
$(call status, INSTALL, $@)
$(CP) $< $@
$(O)/install/include/%.C: $(H)/lib/libc/%.C
$(call status, INSTALL, $@)
$(CP) $< $@
$(O)/install/include/%.H: $(H)/os/kernel/%.H
$(call status, INSTALL, $@)
$(CP) $< $@
$(O)/install/include/%.h: $(H)/os/kernel/%.h
$(call status, INSTALL, $@)
$(CP) $< $@
# Many stubgen include file installations
$(O)/install/include/%.H: $(S)/lib/libc/%.H
$(call status, INSTALL, $@)
$(CP) $< $@
$(O)/install/include/%.I: $(S)/lib/libc/%.I
$(call status, INSTALL, $@)
$(CP) $< $@