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.
10 KERN_LDFLAGS := $(LDFLAGS) -Ttext F0100020 -nostdlib
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 \
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)))
49 KERN_BINFILES := $(addprefix $(OBJDIR)/, $(KERN_BINFILES))
51 # How to build the kernel itself
52 $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES)
54 @$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) $(GCC_LIB) -b binary $(KERN_BINFILES)
55 @$(OBJDUMP) -S $@ > $@.asm
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
72 @objcopy --adjust-vma=0x10000000 $^ $@