Don't want -DKERNEL_LOAD_PAGES on every kernel.bin prereq.
[pintos-anon] / src / Makefile.build
1 # -*- makefile -*-
2
3 include ../Makefile.vars
4
5 SHELL = /bin/sh
6
7 CC = gcc
8
9 VPATH = ../..
10
11 DEFINES += -DKERNEL
12 WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
13 INCLUDES = -nostdinc -I../.. -I- -I../../lib -I../../lib/kernel
14 CFLAGS = -g -O3 -MMD -msoft-float $(INCLUDES) $(WARNINGS) $(DEFINES)
15 ASFLAGS = -Wa,--gstabs -MMD $(INCLUDES) $(DEFINES)
16
17 # Core kernel.
18 threads_SRC  = threads/init.c           # Main program.
19 threads_SRC += threads/thread.c         # Thread management core.
20 threads_SRC += threads/switch.S         # Thread switch routine.
21 threads_SRC += threads/interrupt.c      # Interrupt core.
22 threads_SRC += threads/intr-stubs.S     # Interrupt stubs.
23 threads_SRC += threads/synch.c          # Synchronization.
24 threads_SRC += threads/paging.c         # Page tables.
25 threads_SRC += threads/palloc.c         # Page allocator.
26 threads_SRC += threads/malloc.c         # Subpage allocator.
27 threads_SRC += threads/start.S          # Startup code.
28
29 # Device driver code.
30 devices_SRC  = devices/timer.c          # Timer device.
31 devices_SRC += devices/kbd.c            # Keyboard device.
32 devices_SRC += devices/vga.c            # Video device.
33 devices_SRC += devices/serial.c         # Serial port device.
34 devices_SRC += devices/disk.c           # IDE disk device.
35
36 # Library code shared between kernel and user programs.
37 lib_SRC  = lib/debug.c          # Debug helpers.
38 lib_SRC += lib/random.c         # Pseudo-random numbers.
39 lib_SRC += lib/stdio.c          # I/O library.
40 lib_SRC += lib/stdlib.c         # Utility functions.
41 lib_SRC += lib/string.c         # String functions.
42
43 # Kernel-specific library code.
44 lib_kernel_SRC += lib/kernel/list.c     # Doubly-linked lists.
45 lib_kernel_SRC += lib/kernel/bitmap.c   # Bitmaps.
46 lib_kernel_SRC += lib/kernel/hash.c     # Hash tables.
47 lib_kernel_SRC += lib/kernel/printf.c   # Kernel printf().
48
49 # Filesystem code.
50 filesys_SRC  = filesys/filesys.c        # Filesystem core.
51 filesys_SRC += filesys/file.c           # Files.
52 filesys_SRC += filesys/directory.c      # Directories.
53 filesys_SRC += filesys/filehdr.c        # File headers (inodes).
54 filesys_SRC += filesys/fsutil.c         # Utilities.
55
56 # User process code.
57 userprog_SRC  = userprog/addrspace.c    # Address spaces.
58 userprog_SRC += userprog/exception.c    # User exception handler.
59 userprog_SRC += userprog/syscall.c      # System call handler.
60 userprog_SRC += userprog/gdt.c          # GDT initialization.
61 userprog_SRC += userprog/tss.c          # TSS management.
62
63 SOURCES = $(foreach dir,$(SUBDIRS),$($(subst /,_,$(dir))_SRC))
64 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
65 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
66
67 all: os.dsk
68
69 threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
70         $< > $@
71
72 threads/kernel.lds.s: CPPFLAGS += -P -C
73 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
74
75 kernel.o: threads/kernel.lds.s $(OBJECTS) 
76         ld -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
77
78 kernel.bin: kernel.o
79         objcopy -O binary -R .note -R .comment -S $< $@.tmp
80         ../../pad 4096 < $@.tmp > $@
81         rm $@.tmp
82
83 threads/loader.o: threads/loader.S kernel.bin
84         $(CC) -c $< -o $@ $(ASFLAGS) -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
85
86 loader.bin: threads/loader.o
87         ld -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
88
89 os.dsk: loader.bin kernel.bin
90         cat $^ > $@
91
92 clean:
93         rm -f $(OBJECTS) $(DEPENDS) 
94         rm -f threads/intr-stubs.S threads/loader.o
95         rm -f kernel.o kernel.lds.s
96         rm -f kernel.bin loader.bin
97
98 -include $(DEPENDS)