]> git.buserror.net Git - polintos/scott/priv.git/blob - lib/kernel/Makefile
Initial checkin from Perforce.
[polintos/scott/priv.git] / lib / kernel / Makefile
1 # NOTE: due to suckage of make that I can't figure out how to work
2 # around, you'll have to run make twice after you update a .cdl file
3 # in order to make sure that any code that includes the generated
4 # headers has been rebuilt.  This is despite having an explicit
5 # dependency of the .cc file on the normal .h, of the normal .h on
6 # the generated .h, of the generated headers on the server directory,
7 # and of the server directory on the CDL file.  The CDL->directory rule
8 # is used to generated the headers, but even if it's done specifically
9 # for the .cc file up the chain, it doesn't rebuild the .cc file.
10
11 include ../../Makefile.target
12 TOP := $(shell pwd)
13
14 INCS := -Iinclude -I../include/c++ -I../include/generated/c++ \
15         -I../include/c
16
17 DEFS += -D_KERNEL
18
19 CXXFLAGS += $(INCS) $(DEFS) -Wall -Werror -O3 -g3 -fno-rtti \
20             -fno-exceptions -fno-builtin
21
22 ASFLAGS += $(INCS)
23
24 .PHONY: symlinks all default rerun dep servers clean distclean
25
26 all: default
27
28 symlinks:
29         rm -f include/arch
30         ln -sfn arch-$(ARCH) include/arch
31
32 # Make sure "make" treats thse as the right type of variable
33 # when += is used later.
34 OBJS :=
35 DIRS :=
36
37 # Must come first: contains boot entry code
38 include arch/$(ARCH)/Makefile
39
40 include core/Makefile
41 include mem/Makefile
42 include io/Makefile
43 include lib/Makefile
44
45 # Must come last: contains kernel target
46 include arch/$(ARCH)/Makefile.final
47
48 clean: $(EXTRACLEAN)
49         rm -rf $(foreach dir,$(DIRS),$(dir)*.o $(dir)*-server)
50         rm -f kernel kernel.stripped
51
52 distclean: clean
53         rm -f .depend .gdb_history include/arch
54
55 # Every .o file which has a corresponding .cdl file will
56 # depend on the server stubs.
57
58 SERVERS := $(foreach obj,$(OBJS),$(wildcard $(obj:.o=).cdl))
59 SERVERS := $(SERVERS:%.cdl=%) 
60
61 $(SERVERS:%=%-server): %-server: %.cdl $(TOP)/../ifaces
62         rm -rf "$(BUILDDIR)/$@"
63         $(IDLC) -t $(ARCH) -l c++ -r -i "$(TOP)/../ifaces" -o "$(BUILDDIR)/$@" "$<"
64
65 $(SERVERS:%=%.cc): %.cc: %-server
66
67 servers: symlinks $(SERVERS:%=%-server)
68
69 dep: servers
70         rm -f .depend
71         for i in $(OBJS:.o=); do \
72                 for j in cc S; do \
73                         if [ -e "$$i".$$j ]; then \
74                                 FILE="$$i".$$j; \
75                         fi; \
76                 done; \
77                 \
78                 if [ "$$FILE" ]; then \
79                         $(CXX) $(CXXFLAGS) -M -MT "$$i".o "$$FILE" >> .depend; \
80                 fi \
81         done; \
82         for i in $(SERVERS); do \
83                 $(IDLC) -M -l c++ -r -i "$(TOP)/../ifaces" -o "$$i-server" "$$i.cdl" >> .depend; \
84         done
85
86 ifeq (.depend,$(wildcard .depend))
87 include .depend
88 default: kernel kernel.stripped
89 else
90 rerun: dep
91         @$(MAKE)
92
93 default: rerun
94 endif