Moved some functions into kern/testing
[akaros.git] / kern / Makefrag
1 #
2 # Makefile fragment for JOS 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 -nostdlib
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                         lib/printfmt.c \
35                         lib/readline.c \
36                         lib/string.c
37
38 # Only build files if they exist.
39 KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
40
41 KERN_BINFILES :=        user/hello \
42                         user/buggyhello \
43                         user/evilhello \
44                         user/testbss \
45                         user/divzero \
46                         user/breakpoint \
47                         user/softint \
48                         user/badsegment \
49                         user/faultread \
50                         user/faultreadkernel \
51                         user/faultwrite \
52                         user/faultwritekernel
53
54 KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
55 KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
56 KERN_OBJFILES := $(patsubst obj/lib/%, obj/kern/%, $(KERN_OBJFILES))
57
58 KERN_BINFILES := $(patsubst %, $(OBJDIR)/%, $(KERN_BINFILES))
59
60 # How to build kernel object files
61 $(OBJDIR)/kern/%.o: kern/%.c
62         @echo + cc $<
63         @mkdir -p $(@D)
64         $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
65
66 $(OBJDIR)/kern/%.o: kern/%.S
67         @echo + as $<
68         @mkdir -p $(@D)
69         $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
70
71 $(OBJDIR)/kern/%.o: lib/%.c
72         @echo + cc $<
73         @mkdir -p $(@D)
74         $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
75
76 # How to build the kernel itself
77 $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES) kern/kernel.ld $(OBJDIR)/ivylib/libivykern.a
78         @echo + ld $@
79         $(V)$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) -livykern $(GCC_LIB) -b binary $(KERN_BINFILES)
80         $(V)$(OBJDUMP) -S $@ > $@.asm
81         $(V)$(NM) -n $@ > $@.sym
82
83 # How to build the Bochs disk image
84 $(OBJDIR)/kern/bochs.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
85         @echo + mk $@
86         $(V)dd if=/dev/zero of=$(OBJDIR)/kern/bochs.img~ count=10000 2>/dev/null
87         $(V)dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/bochs.img~ conv=notrunc 2>/dev/null
88         $(V)dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/bochs.img~ seek=1 conv=notrunc 2>/dev/null
89         $(V)mv $(OBJDIR)/kern/bochs.img~ $(OBJDIR)/kern/bochs.img
90 # brho uses these
91 #       $(V)cp $(OBJDIR)/kern/kernel mnt/hdd/texas
92 #       $(V)sync
93
94 all: $(OBJDIR)/kern/bochs.img
95
96 grub: $(OBJDIR)/jos-grub
97
98 $(OBJDIR)/jos-grub: $(OBJDIR)/kern/kernel
99         @echo + oc $@
100         $(V)$(OBJCOPY) --adjust-vma=0x10000000 $^ $@