Kernel - Added /Devices/{zero,one,null}
[tpg/acess2.git] / KernelLand / Kernel / Makefile
1 # Acess2 Kernel
2 # Root Makefile
3 # NOTE: Does some voodoo to allow differing architecture builds to co-exist
4 # - The built objects and dependency files are suffixed with the arch name
5 # - The final binary is Acess2.<ARCH>.bin
6
7 -include ../Makefile.cfg
8
9 -include arch/$(ARCHDIR)/Makefile
10
11 -include Makefile.BuildNum.$(ARCH)
12
13 ifeq ($(BUILD_NUM),)
14 BUILD_NUM = 0
15 endif
16
17 KERNEL_VERSION = $(ACESS_VERSION)
18 MAKEDEP         = $(CC) -M
19
20 ifeq ($(AS_SUFFIX),)
21         AS_SUFFIX = S
22 endif
23
24 ASFLAGS         += -D ARCHDIR_IS_$(ARCHDIR)=1 -D PLATFORM_is_$(PLATFORM)=1
25 CPPFLAGS        += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\"
26 CPPFLAGS        += -D ARCH=$(ARCH) -D ARCHDIR=$(ARCHDIR) -D PLATFORM=\"$(PLATFORM)\" -D ARCHDIR_IS_$(ARCHDIR)=1 -D PLATFORM_is_$(PLATFORM)=1
27 CPPFLAGS        += -D KERNEL_VERSION=$(KERNEL_VERSION) -ffreestanding
28 CFLAGS          += -Wall -fno-stack-protector -Wstrict-prototypes -g
29 CFLAGS          += -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wuninitialized
30 CFLAGS          += -O3
31 LDFLAGS         += -T arch/$(ARCHDIR)/link.ld -g
32
33 ifeq ($(PLATFORM),default)
34         OBJDIR := obj-$(ARCH)/
35         #OBJSUFFIX := .$(ARCH)
36         BIN := ../Acess2.$(ARCH).bin
37         GZBIN := ../Acess2.$(ARCH).gz
38 else
39         OBJDIR := obj-$(ARCH)-$(PLATFORM)/
40         #OBJSUFFIX := .$(ARCH)-$(PLATFORM)
41         BIN := ../Acess2.$(ARCH)-$(PLATFORM).bin
42         GZBIN := ../Acess2.$(ARCH)-$(PLATFORM).gz
43 endif
44
45 ifeq ($(DEBUG_BUILD),yes)
46         LDFLAGS += -g
47         CFLAGS += -g
48 endif
49
50 BUILDINFO_OBJ := $(OBJDIR)buildinfo.o$(OBJSUFFIX)
51 BUILDINFO_SRC := $(OBJDIR)buildinfo.c$(OBJSUFFIX)
52
53 OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ))
54 OBJ += heap.o drvutil.o logging.o debug.o lib.o adt.o time.o
55 OBJ += messages.o modules.o syscalls.o system.o
56 OBJ += threads.o mutex.o semaphore.o workqueue.o events.o
57 OBJ += drv/zero-one.o drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o
58 OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_vt100.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o
59 OBJ += binary.o bin/elf.o bin/pe.o
60 OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o
61 OBJ += vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o vfs/mmap.o
62 OBJ += vfs/fs/root.o vfs/fs/devfs.o
63 OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
64
65 OBJ := $(addsuffix $(OBJSUFFIX), $(OBJ))
66 OBJ := $(addprefix $(OBJDIR), $(OBJ))
67
68 MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES)))
69
70 DEPFILES := $(OBJ:%$(OBJSUFFIX)=%.dep$(OBJSUFFIX))
71
72 SRCFILES  = $(OBJ:$(OBJDIR)%.o$(OBJSUFFIX)=%.c)
73 SRCFILES := $(SRCFILES:$(OBJDIR)%.ao$(OBJSUFFIX)=%.$(AS_SUFFIX))
74
75 OBJ += $(BUILDINFO_OBJ)
76
77 .PHONY: all clean install apidoc
78
79 all: $(BIN)
80
81 clean:
82         @$(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt
83         @$(RM) -r $(OBJDIR) $(OBJ) $(DEPFILES) $(BUILDINFO_SRC)
84
85 # Creates a stripped and compressed copy of the kernel
86 # and installs it to the target
87 install: $(BIN) 
88         @cp $(BIN) $(BIN)_
89         @$(STRIP) $(BIN)_
90         @gzip -c $(BIN)_ > $(GZBIN)
91         @$(RM) $(BIN)_
92         $(xCP) $(GZBIN) $(DISTROOT)
93
94 # Compile API documentation
95 apidoc:
96         doxygen Doxyfile.api
97
98 # Output binary
99 # - Links kernel
100 # - Disassembles it
101 # - Gets a line count
102 # - Increments the build count
103 # - Does whatever architecture defined rules
104 $(BIN): $(OBJ) $(MODS) arch/$(ARCHDIR)/link.ld Makefile ../../BuildConf/$(ARCH)/Makefile.cfg ../../BuildConf/$(ARCH)/$(PLATFORM).mk
105         @echo --- LD -o $(BIN)
106         @$(LD) $(LDFLAGS) -o $(BIN) $(OBJ) $(MODS) --defsym __buildnum=$$(( $(BUILD_NUM) + 1 )) -Map ../Map.$(ARCH).txt
107         @$(DISASM) -S $(BIN) > $(BIN).dsm
108         @wc -l $(SRCFILES) include/*.h > LineCounts.$(ARCH).txt
109         @echo BUILD_NUM = $$(( $(BUILD_NUM) + 1 )) > Makefile.BuildNum.$(ARCH)
110         $(POSTBUILD)
111
112 # Assembly Sources
113 $(OBJDIR)%.ao$(OBJSUFFIX): %.$(AS_SUFFIX) Makefile
114         @echo --- AS -o $@
115         @mkdir -p $(dir $@)
116         @$(AS) $(ASFLAGS) $< -o $@
117 ifeq ($(AS_SUFFIX),S)
118         @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $(OBJDIR)$*.ao.dep$(OBJSUFFIX) $<
119 endif
120
121 # C Sources
122 $(OBJDIR)%.o$(OBJSUFFIX): %.c Makefile
123         @echo --- CC -o $@
124         @mkdir -p $(dir $@)
125         @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
126         @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $(OBJDIR)$*.o.dep$(OBJSUFFIX) $<
127
128 # Build-time linked modules
129 %.xo.$(ARCH):
130         @BUILDTYPE=static make -C $* all
131
132 # System call lists
133 include/syscalls.h include/syscalls.inc.asm:    syscalls.lst Makefile GenSyscalls.pl
134         perl GenSyscalls.pl
135
136 # Rules based on the makefile
137 Makefile:       ../../Makefile.cfg arch/$(ARCHDIR)/Makefile
138
139 # Build-time information (git hash and build number)
140 $(BUILDINFO_SRC): $(filter-out $(BUILDINFO_OBJ), $(OBJ)) $(MODS) arch/$(ARCHDIR)/link.ld Makefile
141         @echo "#include <acess.h>" > $@
142         @echo "const char gsGitHash[] = \""`git log -n 1 | head -n 1 | awk '{print $$2}'`"\";" >> $@
143         @echo "const int giBuildNumber = $(BUILD_NUM);" >> $@
144 # Compile rule for buildinfo (needs a special one because it's not a general source file)
145 $(BUILDINFO_OBJ): $(BUILDINFO_SRC)
146         @echo --- CC -o $@
147         @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
148
149 # Dependency Files
150 -include $(DEPFILES)

UCC git Repository :: git.ucc.asn.au