Detect x86 systems, use the native tools.
[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 INCLUDES = -nostdinc -I../.. -I- -I../../lib -I../../lib/kernel
32 CFLAGS = -g -O3 -MMD -msoft-float $(INCLUDES) $(WARNINGS) $(DEFINES)
33 ASFLAGS = -Wa,--gstabs -MMD $(INCLUDES) $(DEFINES)
34
35 # Core kernel.
36 threads_SRC  = threads/init.c           # Main program.
37 threads_SRC += threads/thread.c         # Thread management core.
38 threads_SRC += threads/switch.S         # Thread switch routine.
39 threads_SRC += threads/interrupt.c      # Interrupt core.
40 threads_SRC += threads/intr-stubs.S     # Interrupt stubs.
41 threads_SRC += threads/synch.c          # Synchronization.
42 threads_SRC += threads/paging.c         # Page tables.
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/exception.c    # User exception handler.
79 userprog_SRC += userprog/syscall.c      # System call handler.
80 userprog_SRC += userprog/gdt.c          # GDT initialization.
81 userprog_SRC += userprog/tss.c          # TSS management.
82
83 SOURCES = $(foreach dir,$(SUBDIRS),$($(subst /,_,$(dir))_SRC))
84 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
85 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
86
87 all: os.dsk
88
89 threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
90         $< > $@
91
92 threads/kernel.lds.s: CPPFLAGS += -P -C
93 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
94
95 kernel.o: threads/kernel.lds.s $(OBJECTS) 
96         $(LD) -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
97
98 kernel.bin: kernel.o
99         $(OBJCOPY) -O binary -R .note -R .comment -S $< $@.tmp
100         $(DD) if=$@.tmp of=$@ bs=4096 conv=sync
101         $(RM) $@.tmp
102
103 threads/loader.o: threads/loader.S kernel.bin
104         $(CC) -c $< -o $@ $(ASFLAGS) -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
105
106 loader.bin: threads/loader.o
107         $(LD) -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
108
109 os.dsk: loader.bin kernel.bin
110         $(CAT) $^ > $@
111
112 clean:
113         $(RM) -f $(OBJECTS) $(DEPENDS) 
114         $(RM) -f threads/intr-stubs.S threads/loader.o
115         $(RM) -f kernel.o kernel.lds.s
116         $(RM) -f kernel.bin loader.bin
117
118 -include $(DEPENDS)