Pass return code from main() to exit().
[pintos-anon] / src / Makefile.build
1 # -*- makefile -*-
2
3 include ../Makefile.vars
4
5 SHELL = /bin/sh
6
7 # Binary utilities.
8 # If the host appears to be x86, use the normal tools.
9 # Otherwise assume cross-tools are installed as i386-elf-*.
10 X86 = i.86\|pentium.*\|[pk][56]\|nexgen\|viac3\|6x86\|athlon.*
11 ifneq (0, $(shell expr `uname -m` : '$(X86)'))
12 CC = gcc
13 LD = ld
14 OBJCOPY = objcopy
15 else
16 CC = i386-elf-gcc
17 LD = i386-elf-ld
18 OBJCOPY = i386-elf-objcopy
19 endif
20
21 # Other utilities.
22 DD = dd
23 RM = rm
24 CAT = cat
25
26 VPATH = ../..
27
28 # Compiler and assembler options.
29 DEFINES += -DKERNEL
30 WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
31 CPPFLAGS = -nostdinc -I../.. -I- -I../../lib -I../../lib/kernel \
32            -include constants.h
33 CFLAGS = -g -O3 -MMD -msoft-float 
34 ASFLAGS = -Wa,--gstabs -MMD
35
36 # Core kernel.
37 threads_SRC  = threads/init.c           # Main program.
38 threads_SRC += threads/thread.c         # Thread management core.
39 threads_SRC += threads/switch.S         # Thread switch routine.
40 threads_SRC += threads/interrupt.c      # Interrupt core.
41 threads_SRC += threads/intr-stubs.S     # Interrupt stubs.
42 threads_SRC += threads/synch.c          # Synchronization.
43 threads_SRC += threads/palloc.c         # Page allocator.
44 threads_SRC += threads/malloc.c         # Subpage allocator.
45 threads_SRC += threads/start.S          # Startup code.
46 threads_SRC += threads/test.c           # Test code.
47
48 # Device driver code.
49 devices_SRC  = devices/timer.c          # Timer device.
50 devices_SRC += devices/kbd.c            # Keyboard device.
51 devices_SRC += devices/vga.c            # Video device.
52 devices_SRC += devices/serial.c         # Serial port device.
53 devices_SRC += devices/disk.c           # IDE disk device.
54 devices_SRC += devices/intq.c           # Interrupt queue.
55
56 # Library code shared between kernel and user programs.
57 lib_SRC  = lib/debug.c          # Debug helpers.
58 lib_SRC += lib/random.c         # Pseudo-random numbers.
59 lib_SRC += lib/stdio.c          # I/O library.
60 lib_SRC += lib/stdlib.c         # Utility functions.
61 lib_SRC += lib/string.c         # String functions.
62
63 # Kernel-specific library code.
64 lib_kernel_SRC += lib/kernel/list.c     # Doubly-linked lists.
65 lib_kernel_SRC += lib/kernel/bitmap.c   # Bitmaps.
66 lib_kernel_SRC += lib/kernel/hash.c     # Hash tables.
67 lib_kernel_SRC += lib/kernel/console.c  # printf(), putchar().
68
69 # Filesystem code.
70 filesys_SRC  = filesys/filesys.c        # Filesystem core.
71 filesys_SRC += filesys/file.c           # Files.
72 filesys_SRC += filesys/directory.c      # Directories.
73 filesys_SRC += filesys/inode.c          # File headers.
74 filesys_SRC += filesys/fsutil.c         # Utilities.
75
76 # User process code.
77 userprog_SRC  = userprog/addrspace.c    # Address spaces.
78 userprog_SRC += userprog/pagedir.c      # Page directories.
79 userprog_SRC += userprog/exception.c    # User exception handler.
80 userprog_SRC += userprog/syscall.c      # System call handler.
81 userprog_SRC += userprog/gdt.c          # GDT initialization.
82 userprog_SRC += userprog/tss.c          # TSS management.
83
84 SOURCES = $(foreach dir,$(SUBDIRS),$($(subst /,_,$(dir))_SRC))
85 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
86 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
87
88 all: os.dsk
89
90 threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
91         $< > $@
92
93 threads/kernel.lds.s: CPPFLAGS += -P -C
94 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
95
96 kernel.o: threads/kernel.lds.s $(OBJECTS) 
97         $(LD) -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
98
99 kernel.bin: kernel.o
100         $(OBJCOPY) -O binary -R .note -R .comment -S $< $@.tmp
101         $(DD) if=$@.tmp of=$@ bs=4096 conv=sync
102         $(RM) $@.tmp
103
104 threads/loader.o: threads/loader.S kernel.bin
105         $(CC) -c $< -o $@ $(ASFLAGS) $(CPPFLAGS) $(DEFINES) -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
106
107 loader.bin: threads/loader.o
108         $(LD) -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
109
110 os.dsk: loader.bin kernel.bin
111         $(CAT) $^ > $@
112
113 clean:
114         $(RM) -f $(OBJECTS) $(DEPENDS) 
115         $(RM) -f threads/intr-stubs.S threads/loader.o
116         $(RM) -f kernel.o kernel.lds.s
117         $(RM) -f kernel.bin loader.bin
118
119 Makefile: ../../Makefile.build
120         cp $< $@
121
122 %.o: %.c
123         $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(WARNINGS) $(DEFINES)
124
125 %.o: %.S
126         $(CC) -c $< -o $@ $(ASFLAGS) $(CPPFLAGS) $(DEFINES)
127
128 -include $(DEPENDS)