9a2728d356a1441bd4d13701022908a61b07870e
[pintos-anon] / src / Makefile.build
1 # -*- makefile -*-
2
3 SRCDIR = ../..
4
5 all: os.dsk
6
7 include ../../Make.config
8 include ../Make.vars
9 include ../../tests/Make.tests
10
11 # Compiler and assembler options.
12 os.dsk: CPPFLAGS += -I$(SRCDIR)/lib/kernel
13
14 # Core kernel.
15 threads_SRC  = threads/init.c           # Main program.
16 threads_SRC += threads/thread.c         # Thread management core.
17 threads_SRC += threads/switch.S         # Thread switch routine.
18 threads_SRC += threads/interrupt.c      # Interrupt core.
19 threads_SRC += threads/intr-stubs.S     # Interrupt stubs.
20 threads_SRC += threads/synch.c          # Synchronization.
21 threads_SRC += threads/palloc.c         # Page allocator.
22 threads_SRC += threads/malloc.c         # Subpage allocator.
23 threads_SRC += threads/start.S          # Startup code.
24
25 # Device driver code.
26 devices_SRC  = devices/timer.c          # Timer device.
27 devices_SRC += devices/kbd.c            # Keyboard device.
28 devices_SRC += devices/vga.c            # Video device.
29 devices_SRC += devices/serial.c         # Serial port device.
30 devices_SRC += devices/disk.c           # IDE disk device.
31 devices_SRC += devices/input.c          # Serial and keyboard input.
32 devices_SRC += devices/intq.c           # Interrupt queue.
33
34 # Library code shared between kernel and user programs.
35 lib_SRC  = lib/debug.c                  # Debug helpers.
36 lib_SRC += lib/random.c                 # Pseudo-random numbers.
37 lib_SRC += lib/stdio.c                  # I/O library.
38 lib_SRC += lib/stdlib.c                 # Utility functions.
39 lib_SRC += lib/string.c                 # String functions.
40
41 # Kernel-specific library code.
42 lib/kernel_SRC  = lib/kernel/debug.c    # Debug helpers.
43 lib/kernel_SRC += lib/kernel/list.c     # Doubly-linked lists.
44 lib/kernel_SRC += lib/kernel/bitmap.c   # Bitmaps.
45 lib/kernel_SRC += lib/kernel/hash.c     # Hash tables.
46 lib/kernel_SRC += lib/kernel/console.c  # printf(), putchar().
47
48 # User process code.
49 userprog_SRC  = userprog/process.c      # Process loading.
50 userprog_SRC += userprog/pagedir.c      # Page directories.
51 userprog_SRC += userprog/exception.c    # User exception handler.
52 userprog_SRC += userprog/syscall.c      # System call handler.
53 userprog_SRC += userprog/gdt.c          # GDT initialization.
54 userprog_SRC += userprog/tss.c          # TSS management.
55
56 # No virtual memory code yet.
57 #vm_SRC = vm/file.c                     # Some file.
58
59 # Filesystem code.
60 filesys_SRC  = filesys/filesys.c        # Filesystem core.
61 filesys_SRC += filesys/free-map.c       # Free sector bitmap.
62 filesys_SRC += filesys/file.c           # Files.
63 filesys_SRC += filesys/directory.c      # Directories.
64 filesys_SRC += filesys/inode.c          # File headers.
65 filesys_SRC += filesys/fsutil.c         # Utilities.
66
67 SOURCES = $(foreach dir,$(KERNEL_SUBDIRS),$($(dir)_SRC))
68 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
69 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
70
71 threads/kernel.lds.s: CPPFLAGS += -P
72 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
73
74 kernel.o: threads/kernel.lds.s $(OBJECTS) 
75         $(LD) -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
76
77 kernel.bin: kernel.o
78         $(OBJCOPY) -O binary -R .note -R .comment -S $< $@.tmp
79         dd if=$@.tmp of=$@ bs=4096 conv=sync
80         rm $@.tmp
81
82 threads/loader.o: threads/loader.S kernel.bin
83         $(CC) -c $< -o $@ $(ASFLAGS) $(CPPFLAGS) $(DEFINES) -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
84
85 loader.bin: threads/loader.o
86         $(LD) -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
87
88 os.dsk: loader.bin kernel.bin
89         cat $^ > $@
90
91 clean::
92         rm -f $(OBJECTS) $(DEPENDS) 
93         rm -f threads/loader.o threads/kernel.lds.s threads/loader.d
94         rm -f kernel.o kernel.lds.s
95         rm -f kernel.bin loader.bin os.dsk
96
97 Makefile: $(SRCDIR)/Makefile.build
98         cp $< $@
99
100 -include $(DEPENDS)