1 | #===================================================================== |
---|
2 | # ALMOS-kernel Makefile # |
---|
3 | #===================================================================== |
---|
4 | |
---|
5 | include ../common.mk |
---|
6 | |
---|
7 | KERNEL_REV ?=current |
---|
8 | |
---|
9 | DIRS= cpu/$(CPU) \ |
---|
10 | arch/$(ARCH) \ |
---|
11 | drivers/$(DRVRS) \ |
---|
12 | kern \ |
---|
13 | mm \ |
---|
14 | fs/devfs \ |
---|
15 | fs/sysfs \ |
---|
16 | fs/ext2 \ |
---|
17 | fs/fat32 \ |
---|
18 | fs/ramfs \ |
---|
19 | vfs \ |
---|
20 | libk \ |
---|
21 | ksh |
---|
22 | |
---|
23 | ifndef CPU |
---|
24 | $(error CPU variable is not defined) |
---|
25 | endif |
---|
26 | |
---|
27 | LFLAGS = -T$(OBJDIR)/kldscript $(CPULFLAGS) |
---|
28 | |
---|
29 | INCLUDES= $(foreach DIR,$(DIRS),-I$(DIR)) -I$(OBJDIR)/kern/ |
---|
30 | |
---|
31 | CFLAGS = $(INCLUDES) -fno-builtin -static -Wall -Werror -MMD -Wundef |
---|
32 | ifeq ($(MODE),DEBUG) |
---|
33 | CFLAGS += -g -O0 -fno-inline |
---|
34 | else |
---|
35 | CFLAGS += -O2 |
---|
36 | endif |
---|
37 | CFLAGS += $(CPUCFLAGS) |
---|
38 | |
---|
39 | CFILES= $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.c)) |
---|
40 | SFILES= $(wildcard cpu/$(CPU)/*.S) |
---|
41 | |
---|
42 | OBJS= $(addprefix $(OBJDIR)/, $(CFILES:.c=.o) $(SFILES:.S=.o)) |
---|
43 | DEPS= $(OBJS:.o=.d) |
---|
44 | |
---|
45 | OBJDIRS= $(addprefix $(OBJDIR)/, $(DIRS)) |
---|
46 | |
---|
47 | # Kernel bin file name |
---|
48 | ifeq ($(KERNEL_REV),current) |
---|
49 | TARGET=$(OBJDIR)/almos-mk-$(ARCH)-$(CPU) |
---|
50 | else |
---|
51 | TARGET=$(OBJDIR)/almos-mk-$(ARCH)-$(CPU)-$(KERNEL_REV) |
---|
52 | endif |
---|
53 | |
---|
54 | |
---|
55 | .PHONY: clean timestamp |
---|
56 | |
---|
57 | |
---|
58 | $(TARGET): $(OBJDIRS) $(OBJDIR)/kldscript timestamp $(OBJS) |
---|
59 | @echo ' [ LD ] '$@.elf |
---|
60 | @$(LD) -o $@.elf $(OBJS) $(LFLAGS) |
---|
61 | @echo ' [ NM ] '$@.elf.nm |
---|
62 | @$(NM) $@.elf > $@.elf.nm |
---|
63 | @echo ' [ COPY ] '$@.bin |
---|
64 | @$(OCPY) -O binary $@.elf $@.bin |
---|
65 | @echo -e '\n [ DONE ] \n' |
---|
66 | $(ODMP) $(DUMPFLAGS) -d $@.elf > $@.dump |
---|
67 | |
---|
68 | |
---|
69 | timestamp: |
---|
70 | @echo "Compile flags: $(CFLAGS)" |
---|
71 | @echo '#define ALMOS_DATE "'$(shell date +"%d %B %Y - %T")'"' > $(OBJDIR)/kern/almOS-date.h |
---|
72 | |
---|
73 | $(OBJDIR)/kldscript: arch/$(ARCH)/kldscript.h arch/$(ARCH)/arch-config.h |
---|
74 | @echo ' [ CPP ] '$< |
---|
75 | @cpp $< | grep -v "#" | grep . > $@ |
---|
76 | |
---|
77 | $(OBJDIR)/%.o: %.c |
---|
78 | @echo ' [ CC ] '$< |
---|
79 | cpp $(INCLUDES) $< out.cpp |
---|
80 | @$(CC) $(CFLAGS) -c $< -o $@ |
---|
81 | ifneq ($(MODE),DEBUG) |
---|
82 | @$(STRIP) -x -R .pdr -R .gnu.attributes -R .reginfo -R .comment $@ |
---|
83 | endif |
---|
84 | |
---|
85 | $(OBJDIR)/%.o: %.S |
---|
86 | @echo ' [ AS ] '$< |
---|
87 | @$(CC) $(CFLAGS) -c $< -o $@ |
---|
88 | ifneq ($(MODE),DEBUG) |
---|
89 | @$(STRIP) -x -R .pdr -R .gnu.attributes -R .reginfo -R .comment $@ |
---|
90 | endif |
---|
91 | |
---|
92 | clean: |
---|
93 | rm -rf $(OBJDIR) out.cpp |
---|
94 | |
---|
95 | $(OBJDIRS): |
---|
96 | @echo ' [ MKDIR ] '$@ |
---|
97 | @mkdir -p $@ |
---|
98 | |
---|
99 | |
---|
100 | -include $(DEPS) |
---|