All programs should die gracefully now since fixing sbrk to return -1
[akaros.git] / kern / Makefrag
1 #
2 # Makefile fragment for ROS kernel.
3 # This is NOT a complete makefile;
4 # you must run GNU make in the top-level directory
5 # where the GNUmakefile is located.
6 #
7
8 OBJDIRS += kern
9 CC=ivycc --deputy
10
11 KERN_LDFLAGS := $(LDFLAGS) -Lobj/ivylib -T kern/kernel.ld
12
13 # entry.S must be first, so that it's the first code in the text segment!!!
14 #
15 # We also snatch the use of a couple handy source files
16 # from the lib directory, to avoid gratuitous code duplication.
17 KERN_SRCFILES :=        kern/entry.S \
18                         kern/smp_entry.S \
19                         kern/init.c \
20                         kern/console.c \
21                         kern/monitor.c \
22                         kern/pmap.c \
23                         kern/env.c \
24                         kern/kclock.c \
25                         kern/picirq.c \
26                         kern/printf.c \
27                         kern/trap.c \
28                         kern/trapentry.S \
29                         kern/sched.c \
30                         kern/syscall.c \
31                         kern/kdebug.c \
32                         kern/apic.c \
33                         kern/testing.c \
34                         kern/atomic.c \
35                         kern/smp.c \
36                         lib/printfmt.c \
37                         lib/readline.c \
38                         lib/string.c \
39                         lib/timer.c
40
41 # Only build files if they exist.
42 KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
43
44 KERN_BINFILES :=        user_newlib/hello
45 #                                       user/null \
46 #                                       user/hello \
47 #                                       user_newlib/null \
48 #                               user/hello \
49 #                               user/buggyhello \
50 #                               user/evilhello \
51 #                               user/testbss \
52 #                               user/divzero \
53 #                               user/breakpoint \
54 #                               user/softint \
55 #                               user/badsegment \
56 #                               user/faultread \
57 #                               user/faultreadkernel \
58 #                               user/faultwrite \
59 #                               user/faultwritekernel \
60 #                               user_newlib/null \
61
62 KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
63 KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
64 KERN_OBJFILES := $(patsubst obj/lib/%, obj/kern/%, $(KERN_OBJFILES))
65
66 KERN_BINFILES := $(patsubst %, $(OBJDIR)/%, $(KERN_BINFILES))
67
68 # How to build kernel object files
69 $(OBJDIR)/kern/%.o: kern/%.c
70         @echo + cc $<
71         @mkdir -p $(@D)
72         $(V)$(CC) $(KERN_CFLAGS) -c -o $@ $<
73
74 $(OBJDIR)/kern/%.o: kern/%.S
75         @echo + as $<
76         @mkdir -p $(@D)
77         $(V)$(CC) $(KERN_CFLAGS) -c -o $@ $<
78
79 $(OBJDIR)/kern/%.o: lib/%.c
80         @echo + cc $<
81         @mkdir -p $(@D)
82         $(V)$(CC) $(KERN_CFLAGS) -c -o $@ $<
83
84 # How to build the kernel itself
85 $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES) kern/kernel.ld $(OBJDIR)/ivylib/libivykern.a
86         @echo + ld $@
87         $(V)$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) -livykern $(GCC_LIB) -b binary $(KERN_BINFILES)
88         $(V)$(OBJDUMP) -S $@ > $@.asm
89         $(V)$(NM) -n $@ > $@.sym
90
91 # How to build the Bochs disk image
92 $(OBJDIR)/kern/bochs.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
93         @echo + mk $@
94         $(V)dd if=/dev/zero of=$(OBJDIR)/kern/bochs.img~ count=10000 2>/dev/null
95         $(V)dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/bochs.img~ conv=notrunc 2>/dev/null
96         $(V)dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/bochs.img~ seek=1 conv=notrunc 2>/dev/null
97         $(V)mv $(OBJDIR)/kern/bochs.img~ $(OBJDIR)/kern/bochs.img
98
99 all: $(OBJDIR)/kern/bochs.img
100
101 grub: $(OBJDIR)/ros-grub
102
103 $(OBJDIR)/ros-grub: $(OBJDIR)/kern/kernel
104         @echo + oc $@
105         $(V)$(OBJCOPY) --adjust-vma=0x10000000 $^ $@