Merge branch 'master' of git://localhost/acess2
[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 logging.o debug.o lib.o libc.o adt.o time.o
55 OBJ += drvutil_video.o drvutil_disk.o
56 OBJ += messages.o modules.o syscalls.o system.o
57 OBJ += threads.o mutex.o semaphore.o workqueue.o events.o rwlock.o
58 OBJ += drv/zero-one.o drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o
59 OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_vt100.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o
60 OBJ += binary.o bin/elf.o bin/pe.o
61 OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o
62 OBJ += vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o vfs/mmap.o
63 OBJ += vfs/fs/root.o vfs/fs/devfs.o
64 OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
65
66 OBJ := $(addsuffix $(OBJSUFFIX), $(OBJ))
67 OBJ := $(addprefix $(OBJDIR), $(OBJ))
68
69 MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES)))
70
71 DEPFILES := $(OBJ:%$(OBJSUFFIX)=%.dep$(OBJSUFFIX))
72
73 SRCFILES  = $(OBJ:$(OBJDIR)%.o$(OBJSUFFIX)=%.c)
74 SRCFILES := $(SRCFILES:$(OBJDIR)%.ao$(OBJSUFFIX)=%.$(AS_SUFFIX))
75
76 OBJ += $(BUILDINFO_OBJ)
77
78 .PHONY: all clean install apidoc
79
80 all: $(BIN)
81
82 clean:
83         @$(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt
84         @$(RM) -r $(OBJDIR) $(OBJ) $(DEPFILES) $(BUILDINFO_SRC)
85
86 # Creates a stripped and compressed copy of the kernel
87 # and installs it to the target
88 install: $(BIN) 
89         $(xCP) $(GZBIN) $(DISTROOT)
90
91 # Compile API documentation
92 apidoc:
93         doxygen Doxyfile.api
94
95 # Output binary
96 # - Links kernel
97 # - Disassembles it
98 # - Gets a line count
99 # - Increments the build count
100 # - Does whatever architecture defined rules
101 $(BIN): $(OBJ) $(MODS) arch/$(ARCHDIR)/link.ld Makefile ../../BuildConf/$(ARCH)/Makefile.cfg ../../BuildConf/$(ARCH)/$(PLATFORM).mk
102         @echo --- LD -o $(BIN)
103         @$(LD) $(LDFLAGS) -o $(BIN) $(OBJ) $(MODS) --defsym __buildnum=$$(( $(BUILD_NUM) + 1 )) -Map ../Map.$(ARCH).txt
104         @$(DISASM) -S $(BIN) > $(BIN).dsm
105         @wc -l $(SRCFILES) include/*.h > LineCounts.$(ARCH).txt
106         @echo BUILD_NUM = $$(( $(BUILD_NUM) + 1 )) > Makefile.BuildNum.$(ARCH)
107         $(POSTBUILD)
108         @cp $(BIN) $(BIN)_
109         @$(STRIP) $(BIN)_
110         @gzip -c $(BIN)_ > $(GZBIN)
111         @$(RM) $(BIN)_
112
113 # Assembly Sources
114 $(OBJDIR)%.ao$(OBJSUFFIX): %.$(AS_SUFFIX) Makefile
115         @echo --- AS -o $@
116         @mkdir -p $(dir $@)
117         @$(AS) $(ASFLAGS) $< -o $@
118 ifeq ($(AS_SUFFIX),S)
119         @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $(OBJDIR)$*.ao.dep$(OBJSUFFIX) $<
120 endif
121
122 # C Sources
123 $(OBJDIR)%.o$(OBJSUFFIX): %.c Makefile
124         @echo --- CC -o $@
125         @mkdir -p $(dir $@)
126         @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
127         @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $(OBJDIR)$*.o.dep$(OBJSUFFIX) $<
128
129 # Build-time linked modules
130 %.xo.$(ARCH):
131         @BUILDTYPE=static make -C $* all
132
133 # System call lists
134 include/syscalls.h include/syscalls.inc.asm:    syscalls.lst Makefile GenSyscalls.pl
135         perl GenSyscalls.pl
136
137 # Rules based on the makefile
138 Makefile:       ../../Makefile.cfg arch/$(ARCHDIR)/Makefile
139
140 # Build-time information (git hash and build number)
141 $(BUILDINFO_SRC): $(filter-out $(BUILDINFO_OBJ), $(OBJ)) $(MODS) arch/$(ARCHDIR)/link.ld Makefile
142         @echo "#include <acess.h>" > $@
143         @echo "const char gsGitHash[] = \""`git log -n 1 | head -n 1 | awk '{print $$2}'`"\";" >> $@
144         @echo "const int giBuildNumber = $(BUILD_NUM);" >> $@
145 # Compile rule for buildinfo (needs a special one because it's not a general source file)
146 $(BUILDINFO_OBJ): $(BUILDINFO_SRC)
147         @echo --- CC -o $@
148         @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
149
150 # Dependency Files
151 -include $(DEPFILES)

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