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) -T kern/kernel.ld -nostdlib
12 # entry.S must be first, so that it's the first code in the text segment!!!
14 # We also snatch the use of a couple handy source files
15 # from the lib directory, to avoid gratuitous code duplication.
16 KERN_SRCFILES := kern/entry.S \
34 # Only build files if they exist.
35 KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
37 # Binary program images to embed within the kernel.
38 KERN_BINFILES := user/idle \
47 KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
48 KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
49 KERN_OBJFILES := $(patsubst $(OBJDIR)/lib/%, $(OBJDIR)/kern/%, $(KERN_OBJFILES))
51 KERN_BINFILES := $(patsubst %, $(OBJDIR)/%, $(KERN_BINFILES))
53 # How to build kernel object files
54 $(OBJDIR)/kern/%.o: kern/%.c
57 $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
59 $(OBJDIR)/kern/%.o: kern/%.S
62 $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
64 $(OBJDIR)/kern/%.o: lib/%.c
67 $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
69 # How to build the kernel itself
70 $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES) kern/kernel.ld
72 $(V)$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) $(GCC_LIB) -b binary $(KERN_BINFILES)
73 $(V)$(OBJDUMP) -S $@ > $@.asm
74 $(V)$(NM) -n $@ > $@.sym
76 # How to build the Bochs disk image
77 $(OBJDIR)/kern/bochs.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
79 $(V)dd if=/dev/zero of=$(OBJDIR)/kern/bochs.img~ count=10000 2>/dev/null
80 $(V)dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/bochs.img~ conv=notrunc 2>/dev/null
81 $(V)dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/bochs.img~ seek=1 conv=notrunc 2>/dev/null
82 $(V)mv $(OBJDIR)/kern/bochs.img~ $(OBJDIR)/kern/bochs.img
84 all: $(OBJDIR)/kern/bochs.img
86 grub: $(OBJDIR)/jos-grub
88 $(OBJDIR)/jos-grub: $(OBJDIR)/kern/kernel
90 $(V)$(OBJCOPY) --adjust-vma=0x10000000 $^ $@