* same with xv6
[mascara-docs.git] / i386 / standford / 2004 / src / lab3 / kern / Makefrag
blobd11a7eb00d120e3132c5086fdaca743aeee68838
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.
8 OBJDIRS += kern
10 KERN_LDFLAGS := $(LDFLAGS) -Ttext F0100020 -nostdlib
13 INIT=init
14 ENV=env
15 PMAP=pmap
17 ## Only build files if they exist.
19 ## entry.S must be first, so that it's the 
20 ## first code in the text segment!!!
22 ## Note that we also snatch the use of a couple handy source files
23 ## from the lib directory, to avoid gratuitous code duplication.
25 KERN_SRCFILES :=        kern/entry.S \
26                         kern/$(INIT).c \
27                         kern/console.c \
28                         kern/monitor.c \
29                         kern/$(PMAP).c \
30                         kern/$(ENV).c \
31                         kern/kclock.c \
32                         kern/picirq.c \
33                         kern/trap.c \
34                         kern/trapentry.S \
35                         kern/sched.c \
36                         kern/syscall.c \
37                         lib/printf.c \
38                         lib/printfmt.c \
39                         lib/readline.c \
40                         lib/string.c
41 KERN_SRCFILES := $(foreach file, $(KERN_SRCFILES), \
42                         $(shell test -f $(file) && echo $(file)))
43 KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, \
44                         $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_SRCFILES)))
46 KERN_BINFILES := 
49 KERN_BINFILES := $(addprefix $(OBJDIR)/, $(KERN_BINFILES))
51 # How to build the kernel itself
52 $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES)
53         @echo ld $@
54         @$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) $(GCC_LIB) -b binary $(KERN_BINFILES)
55         @$(OBJDUMP) -S $@ > $@.asm
56         @$(NM) -n $@ > $@.sym
58 # How to build the Bochs disk image
59 $(OBJDIR)/kern/bochs.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
60         @echo mk $(OBJDIR)/kern/bochs.img
61         @dd if=/dev/zero of=$(OBJDIR)/kern/bochs.img~ count=10000 2>/dev/null
62         @dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/bochs.img~ conv=notrunc 2>/dev/null
63         @dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/bochs.img~ seek=1 conv=notrunc 2>/dev/null
64         @mv $(OBJDIR)/kern/bochs.img~ $(OBJDIR)/kern/bochs.img
66 all: $(OBJDIR)/kern/bochs.img
68 grub: $(OBJDIR)/jos-grub
70 $(OBJDIR)/jos-grub: $(OBJDIR)/kern/kernel
71         @echo oc $@
72         @objcopy --adjust-vma=0x10000000 $^ $@