Redo makefiles.
[pintos-anon] / src / Makefile.build
1 # -*- makefile -*-
2
3 include ../Makefile.vars
4
5 SHELL = /bin/sh
6
7 CC = gcc
8
9 SRC_ROOT = ../..
10 VPATH = $(SRC_ROOT)
11
12 WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
13 INCLUDES = -I$(SRC_ROOT)
14 CFLAGS = -g -O3 -MMD -msoft-float $(INCLUDES) $(WARNINGS) $(DEFINES)
15 ASFLAGS = -Wa,--gstabs $(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.
37 lib_SRC  = lib/debug.c          # Debug helpers.
38 lib_SRC += lib/lib.c            # Standard C library.
39 lib_SRC += lib/random.c         # Pseudo-random numbers.
40 lib_SRC += lib/list.c           # Doubly-linked lists.
41 lib_SRC += lib/bitmap.c         # Bitmaps.
42 lib_SRC += lib/hash.c           # Hash tables.
43
44 # Filesystem code.
45 filesys_SRC  = filesys/filesys.c        # Filesystem core.
46 filesys_SRC += filesys/file.c           # Files.
47 filesys_SRC += filesys/directory.c      # Directories.
48 filesys_SRC += filesys/filehdr.c        # File headers (inodes).
49 filesys_SRC += filesys/fsutil.c         # Utilities.
50
51 # User process code.
52 userprog_SRC  = userprog/addrspace.c    # Address spaces.
53 userprog_SRC += userprog/exception.c    # User exception handler.
54 userprog_SRC += userprog/syscall.c      # System call handler.
55 userprog_SRC += userprog/gdt.c          # GDT initialization.
56 userprog_SRC += userprog/tss.c          # TSS management.
57
58 SOURCES = $(foreach dir,$(SUBDIRS),$($(dir)_SRC))
59 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
60 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
61
62 all: os.dsk
63
64 threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
65         $< > $@
66
67 threads/kernel.lds.s: CPPFLAGS += -P -C
68 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
69
70 kernel.o: threads/kernel.lds.s $(OBJECTS) 
71         ld -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
72
73 kernel.bin: kernel.o
74         objcopy -O binary -R .note -R .comment -S $< $@.tmp
75         $(SRC_ROOT)/pad 4096 < $@.tmp > $@
76         rm $@.tmp
77
78 threads/loader.o: threads/loader.S threads/loader.h kernel.bin
79         gcc -c $< -o $@ -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
80
81 loader.bin: threads/loader.o
82         ld -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
83
84 os.dsk: loader.bin kernel.bin
85         cat $^ > $@
86
87 clean:
88         rm -f $(OBJECTS) $(DEPENDS) 
89         rm -f threads/intr-stubs.S threads/loader.o
90         rm -f kernel.o kernel.lds.s
91         rm -f kernel.bin loader.bin
92
93 -include $(DEPENDS)