Modules/USB - Working on driver support, little headache
[tpg/acess2.git] / 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
19 MAKEDEP         = $(CC) -M
20
21 CPPFLAGS        += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\"
22 CPPFLAGS        += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DARCHDIR_IS_$(ARCHDIR)=1
23 CPPFLAGS        += -DKERNEL_VERSION=$(KERNEL_VERSION)
24 CFLAGS          += -Wall -Werror -fno-stack-protector -Wstrict-prototypes -g
25 CFLAGS          += -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wuninitialized
26 CFLAGS          += -O3
27 LDFLAGS         += -T arch/$(ARCHDIR)/link.ld -g
28
29 OBJDIR := obj-$(ARCH)/
30 #OBJSUFFIX := .$(ARCH)
31
32 ifeq ($(DEBUG_BUILD),yes)
33         LDFLAGS += -g
34         CFLAGS += -g
35 endif
36
37 ifeq ($(AS_SUFFIX),)
38         AS_SUFFIX = S
39 endif
40
41 BUILDINFO_OBJ := $(OBJDIR)buildinfo.o$(OBJSUFFIX)
42 BUILDINFO_SRC := $(OBJDIR)buildinfo.c$(OBJSUFFIX)
43
44 OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ))
45 OBJ += heap.o drvutil.o logging.o debug.o lib.o adt.o time.o
46 OBJ += messages.o modules.o syscalls.o system.o
47 OBJ += threads.o mutex.o semaphore.o
48 OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o
49 OBJ += binary.o bin/elf.o bin/pe.o
50 OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o
51 OBJ += vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o vfs/mmap.o
52 OBJ += vfs/fs/root.o vfs/fs/devfs.o
53 OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
54
55 OBJ := $(addsuffix $(OBJSUFFIX), $(OBJ))
56 OBJ := $(addprefix $(OBJDIR), $(OBJ))
57
58 MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES)))
59 BIN = ../Acess2.$(ARCH).bin
60 GZBIN = ../Acess2.$(ARCH).gz
61
62 DEPFILES := $(OBJ:%$(OBJSUFFIX)=%.dep$(OBJSUFFIX))
63
64 SRCFILES  = $(OBJ:$(OBJDIR)%.o$(OBJSUFFIX)=%.c)
65 SRCFILES := $(SRCFILES:$(OBJDIR)%.ao$(OBJSUFFIX)=%.$(AS_SUFFIX))
66
67 OBJ += $(BUILDINFO_OBJ)
68
69 .PHONY: all clean install apidoc
70
71 all: $(BIN)
72
73 clean:
74 #       $(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt $(OBJ) $(DEPFILES)
75         @$(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt -r $(OBJDIR) $(OBJ) $(DEPFILES) $(BUILDINFO_SRC)
76
77 install: $(BIN) 
78         cp $(BIN) $(BIN)_
79         $(STRIP) $(BIN)_
80         gzip -c $(BIN)_ > ../Acess2.$(ARCH).gz
81         $(RM) $(BIN)_
82         $(xCP) ../Acess2.$(ARCH).gz $(DISTROOT)
83
84 apidoc:
85         doxygen Doxyfile.api
86
87 $(BIN): $(OBJ) $(MODS) arch/$(ARCHDIR)/link.ld Makefile
88         @echo --- LD -o $(BIN)
89         @$(LD) $(LDFLAGS) -o $(BIN) $(OBJ) $(MODS) --defsym __buildnum=$$(( $(BUILD_NUM) + 1 )) -Map ../Map.$(ARCH).txt
90         $(DISASM) -S $(BIN) > $(BIN).dsm
91         @wc -l $(SRCFILES) include/*.h > LineCounts.$(ARCH).txt
92         @echo BUILD_NUM = $$(( $(BUILD_NUM) + 1 )) > Makefile.BuildNum.$(ARCH)
93         $(POSTBUILD)
94
95 $(OBJDIR)%.ao$(OBJSUFFIX): %.$(AS_SUFFIX) Makefile
96         @echo --- AS -o $@
97         @mkdir -p $(dir $@)
98         @$(AS) $(ASFLAGS) $< -o $@
99 ifeq ($(AS_SUFFIX),S)
100         @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $(OBJDIR)$*.ao.dep$(OBJSUFFIX) $<
101 endif
102
103 $(OBJDIR)%.o$(OBJSUFFIX): %.c Makefile
104 #       if exists %*/Makefile
105 #       @make -C %*/ all
106 #       else
107         @echo --- CC -o $@
108         @mkdir -p $(dir $@)
109         @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
110         @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $(OBJDIR)$*.o.dep$(OBJSUFFIX) $<
111 #       endif
112
113 %.xo.$(ARCH):
114         @BUILDTYPE=static make -C $* all
115
116 include/syscalls.h include/syscalls.inc.asm:    syscalls.lst Makefile GenSyscalls.pl
117         perl GenSyscalls.pl
118
119 Makefile:       ../Makefile.cfg arch/$(ARCHDIR)/Makefile
120
121 $(BUILDINFO_SRC): $(filter-out $(BUILDINFO_OBJ), $(OBJ)) $(MODS) arch/$(ARCHDIR)/link.ld Makefile
122         @echo "#include <acess.h>" > $@
123         @echo "const char gsGitHash[] = \""`git log -n 1 | head -n 1 | awk '{print $$2}'`"\";" >> $@
124         @echo "const int giBuildNumber = $(BUILD_NUM);" >> $@
125 $(BUILDINFO_OBJ): $(BUILDINFO_SRC)
126         @echo --- CC -o $@
127         @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
128
129 # Dependency Files
130 -include $(DEPFILES)

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