Adjust all #include lines appropriately.
--- /dev/null
+# -*- makefile -*-
+
+include ../Makefile.vars
+
+SHELL = /bin/sh
+
+CC = gcc
+
+SRC_ROOT = ../..
+VPATH = $(SRC_ROOT)
+
+WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
+INCLUDES = -I$(SRC_ROOT)
+CFLAGS = -g -O3 -MMD -msoft-float $(INCLUDES) $(WARNINGS) $(DEFINES)
+ASFLAGS = -Wa,--gstabs $(INCLUDES) $(DEFINES)
+
+# Core kernel.
+threads_SRC = threads/init.c # Main program.
+threads_SRC += threads/thread.c # Thread management core.
+threads_SRC += threads/switch.S # Thread switch routine.
+threads_SRC += threads/interrupt.c # Interrupt core.
+threads_SRC += threads/intr-stubs.S # Interrupt stubs.
+threads_SRC += threads/synch.c # Synchronization.
+threads_SRC += threads/paging.c # Page tables.
+threads_SRC += threads/palloc.c # Page allocator.
+threads_SRC += threads/malloc.c # Subpage allocator.
+threads_SRC += threads/start.S # Startup code.
+
+# Device driver code.
+devices_SRC = devices/timer.c # Timer device.
+devices_SRC += devices/kbd.c # Keyboard device.
+devices_SRC += devices/vga.c # Video device.
+devices_SRC += devices/serial.c # Serial port device.
+devices_SRC += devices/disk.c # IDE disk device.
+
+# Library code.
+lib_SRC = lib/debug.c # Debug helpers.
+lib_SRC += lib/lib.c # Standard C library.
+lib_SRC += lib/random.c # Pseudo-random numbers.
+lib_SRC += lib/list.c # Doubly-linked lists.
+lib_SRC += lib/bitmap.c # Bitmaps.
+lib_SRC += lib/hash.c # Hash tables.
+
+# Filesystem code.
+filesys_SRC = filesys/filesys.c # Filesystem core.
+filesys_SRC += filesys/file.c # Files.
+filesys_SRC += filesys/directory.c # Directories.
+filesys_SRC += filesys/filehdr.c # File headers (inodes).
+filesys_SRC += filesys/fsutil.c # Utilities.
+
+# User process code.
+userprog_SRC = userprog/addrspace.c # Address spaces.
+userprog_SRC += userprog/exception.c # User exception handler.
+userprog_SRC += userprog/syscall.c # System call handler.
+userprog_SRC += userprog/gdt.c # GDT initialization.
+userprog_SRC += userprog/tss.c # TSS management.
+
+SOURCES = $(foreach dir,$(SUBDIRS),$($(dir)_SRC))
+OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
+DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
+
+all: os.dsk
+
+threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
+ $< > $@
+
+threads/kernel.lds.s: CPPFLAGS += -P -C
+threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
+
+kernel.o: threads/kernel.lds.s $(OBJECTS)
+ ld -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
+
+kernel.bin: kernel.o
+ objcopy -O binary -R .note -R .comment -S $< $@.tmp
+ $(SRC_ROOT)/pad 4096 < $@.tmp > $@
+ rm $@.tmp
+
+threads/loader.o: threads/loader.S threads/loader.h kernel.bin
+ gcc -c $< -o $@ -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
+
+loader.bin: threads/loader.o
+ ld -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
+
+os.dsk: loader.bin kernel.bin
+ cat $^ > $@
+
+clean:
+ rm -f $(OBJECTS) $(DEPENDS)
+ rm -f threads/intr-stubs.S threads/loader.o
+ rm -f kernel.o kernel.lds.s
+ rm -f kernel.bin loader.bin
+
+-include $(DEPENDS)
+++ /dev/null
-# -*- makefile -*-
-
-SHELL = /bin/sh
-
-CC = gcc
-
-VPATH := $(TOP_SRCDIR)/threads
-VPATH := $(VPATH):$(TOP_SRCDIR)/devices
-VPATH := $(VPATH):$(TOP_SRCDIR)/lib
-VPATH := $(VPATH):$(TOP_SRCDIR)/filesys
-VPATH := $(VPATH):$(TOP_SRCDIR)/userprog
-
-WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS = -g -O3 -MMD -msoft-float $(WARNINGS) $(INCLUDES) $(DEFINES)
-ASFLAGS = -Wa,--gstabs $(INCLUDES) $(DEFINES)
-
-# Core kernel.
-THREADS_SRC = init.c # Main program.
-THREADS_SRC += thread.c # Thread management core.
-THREADS_SRC += switch.S # Thread switch routine.
-THREADS_SRC += interrupt.c # Interrupt core.
-THREADS_SRC += intr-stubs.S # Interrupt stubs.
-THREADS_SRC += synch.c # Synchronization.
-THREADS_SRC += paging.c # Page tables.
-THREADS_SRC += palloc.c # Page allocator.
-THREADS_SRC += malloc.c # Subpage allocator.
-THREADS_SRC += start.S # Startup code.
-
-# Device driver code.
-DEVICES_SRC = timer.c # Timer device.
-DEVICES_SRC += kbd.c # Keyboard device.
-DEVICES_SRC += vga.c # Video device.
-DEVICES_SRC += serial.c # Serial port device.
-DEVICES_SRC += disk.c # IDE disk device.
-
-# Library code.
-LIB_SRC = debug.c # Debug helpers.
-LIB_SRC += lib.c # Standard C library.
-LIB_SRC += random.c # Pseudo-random numbers.
-LIB_SRC += list.c # Doubly-linked lists.
-LIB_SRC += bitmap.c # Bitmaps.
-LIB_SRC += hash.c # Hash tables.
-
-# Filesystem code.
-FILESYS_SRC = filesys.c # Filesystem core.
-FILESYS_SRC += file.c # Files.
-FILESYS_SRC += directory.c # Directories.
-FILESYS_SRC += filehdr.c # File headers (inodes).
-FILESYS_SRC += fsutil.c # Utilities.
-
-# User process code.
-USERPROG_SRC = addrspace.c # Address spaces.
-USERPROG_SRC += exception.c # User exception handler.
-USERPROG_SRC += syscall.c # System call handler.
-USERPROG_SRC += gdt.c # GDT initialization.
-USERPROG_SRC += tss.c # TSS management.
-
-# Objects.
-OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
-
-all: diskimage.bin
-
-intr-stubs.S: $(TOP_SRCDIR)/threads/intr-stubs.pl $(TOP_SRCDIR)/threads/loader.h
- $< > $@
-
-kernel.lds.s: CPPFLAGS += -P -C
-kernel.lds.s: $(TOP_SRCDIR)/threads/kernel.lds.S $(TOP_SRCDIR)/threads/loader.h
-
-kernel.o: $(OBJECTS) kernel.lds.s
- ld -T kernel.lds.s -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
-
-kernel.bin: kernel.o
- objcopy -O binary -R .note -R .comment -S $< $@.tmp
- $(TOP_SRCDIR)/pad 4096 < $@.tmp > $@
-
-loader.bin: loader.S loader.h kernel.bin
- gcc -c $< -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
- ld -N -e start -Ttext 0x7c00 --oformat binary -o $@ loader.o
-
-diskimage.bin: loader.bin kernel.bin
- cat loader.bin kernel.bin > diskimage.bin
-
-clean:
- rm -f *.o *.d *.bin
- rm -f kernel.bin.data kernel.bin.pad intr-stubs.S kernel.lds.s
-
--include *.d
--- /dev/null
+include Makefile.vars
+BUILD_SUBDIRS = $(addprefix build/, $(SUBDIRS))
+
+all: build build/Makefile $(BUILD_SUBDIRS)
+ $(MAKE) -C build
+
+$(BUILD_SUBDIRS):
+ mkdir $@
+build:
+ mkdir $@
+build/Makefile: ../Makefile.build
+ cp $< $@
+
+clean:
+ rm -rf build
#include <stdbool.h>
#include <stdint.h>
-#include "debug.h"
+#include "lib/debug.h"
/* Register definitions for the 16550A UART used in PCs. This is
a full definition of all the registers and their bits. We
#include "disk.h"
#include <stdbool.h>
-#include "debug.h"
-#include "io.h"
-#include "interrupt.h"
-#include "lib.h"
-#include "synch.h"
#include "timer.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "threads/io.h"
+#include "threads/interrupt.h"
+#include "threads/synch.h"
/* ATA command block port addresses. */
#define reg_data(CHANNEL) ((CHANNEL)->reg_base + 0) /* Data. */
#include "kbd.h"
-#include "debug.h"
-#include "interrupt.h"
-#include "io.h"
-#include "lib.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "threads/interrupt.h"
+#include "threads/io.h"
static void
irq21_keyboard (struct intr_frame *args UNUSED)
#include "serial.h"
#include "16550a.h"
-#include "debug.h"
-#include "io.h"
#include "timer.h"
+#include "lib/debug.h"
+#include "threads/io.h"
static void set_serial (int bps, int bits, enum parity_type parity, int stop);
#include "timer.h"
-#include "debug.h"
-#include "interrupt.h"
-#include "io.h"
+#include "lib/debug.h"
+#include "threads/interrupt.h"
+#include "threads/io.h"
#if TIMER_FREQ < 19
#error 8254 timer requires TIMER_FREQ >= 19
#include "vga.h"
#include <stdint.h>
#include <stddef.h>
-#include "io.h"
-#include "lib.h"
-#include "mmu.h"
+#include "lib/lib.h"
+#include "threads/io.h"
+#include "threads/mmu.h"
/* VGA text screen support. See [FREEVGA] for more information. */
-all:
-%:
- $(MAKE) -C build $@
+include Makefile.vars
+include ../Makefile.kernel
--- /dev/null
+DEFINES = -DUSERPROG -DFILESYS
+SUBDIRS = threads devices lib userprog filesys
#include "directory.h"
#include "file.h"
#include "fsutil.h"
-#include "lib.h"
-#include "malloc.h"
+#include "lib/lib.h"
+#include "threads/malloc.h"
/* Initializes D as a directory that holds ENTRY_CNT entries. */
bool
#include <stdbool.h>
#include <stddef.h>
-#include "disk.h"
+#include "devices/disk.h"
/* Maximum length of a filename.
This is the traditional UNIX maximum.
#include "file.h"
-#include "debug.h"
-#include "lib.h"
-#include "malloc.h"
#include "directory.h"
#include "filehdr.h"
#include "filesys.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "threads/malloc.h"
bool
file_open (struct file *file, disk_sector_t hdr_sector)
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
-#include "disk.h"
+#include "devices/disk.h"
#include "off_t.h"
struct file
#include "filehdr.h"
-#include "bitmap.h"
-#include "debug.h"
-#include "malloc.h"
#include "filesys.h"
-#include "lib.h"
+#include "lib/bitmap.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "threads/malloc.h"
/* Allocates sectors from bitmap B for the content of a file
whose size is LENGTH bytes, and returns a new `struct filehdr'
#include <stdbool.h>
#include <stddef.h>
-#include "disk.h"
#include "off_t.h"
+#include "devices/disk.h"
/* Number of direct sector pointers in a file header. */
#define DIRECT_CNT ((DISK_SECTOR_SIZE - sizeof (off_t) * 2) \
*/
#include "filesys.h"
-#include "bitmap.h"
-#include "debug.h"
-#include "directory.h"
-#include "disk.h"
#include "file.h"
#include "filehdr.h"
-#include "lib.h"
+#include "directory.h"
+#include "devices/disk.h"
+#include "lib/bitmap.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
/* Filesystem.
#include "fsutil.h"
#include <stdbool.h>
-#include "debug.h"
-#include "filesys.h"
#include "file.h"
-#include "lib.h"
-#include "mmu.h"
-#include "palloc.h"
+#include "filesys.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "threads/mmu.h"
+#include "threads/palloc.h"
/* Filename and file size to use for copy operations,
as "filename:size". */
#include <limits.h>
#include "debug.h"
#include "lib.h"
-#include "malloc.h"
+#include "threads/malloc.h"
#ifdef FILESYS
-#include "file.h"
+#include "filesys/file.h"
#endif
\f
/* Number of bits in an element. */
#include "debug.h"
#include <stdarg.h>
-#include "interrupt.h"
#include "lib.h"
+#include "threads/interrupt.h"
#define MAX_CLASSES 16
static bool all_enabled;
#include "hash.h"
-#include "malloc.h"
+#include "debug.h"
+#include "threads/malloc.h"
static struct list *find_bucket (struct hash *, hash_elem *);
static struct list_elem *find_elem (struct hash *, struct list *, hash_elem *);
+#include "lib.h"
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include "debug.h"
-#include "interrupt.h"
-#include "lib.h"
-#include "serial.h"
-#include "vga.h"
+#include "devices/serial.h"
+#include "devices/vga.h"
+#include "threads/interrupt.h"
static void
vprintf_core (const char *format, va_list args,
-all:
-%:
- $(MAKE) -C build $@
+include Makefile.vars
+include ../Makefile.kernel
--- /dev/null
+DEFINES =
+SUBDIRS = threads devices lib
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
-#include "debug.h"
#include "interrupt.h"
#include "io.h"
-#include "kbd.h"
-#include "lib.h"
#include "loader.h"
#include "malloc.h"
#include "mmu.h"
#include "paging.h"
#include "palloc.h"
-#include "random.h"
-#include "serial.h"
#include "thread.h"
-#include "timer.h"
-#include "vga.h"
+#include "devices/kbd.h"
+#include "devices/serial.h"
+#include "devices/timer.h"
+#include "devices/vga.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "lib/random.h"
#ifdef USERPROG
-#include "exception.h"
-#include "syscall.h"
-#include "gdt.h"
-#include "tss.h"
+#include "userprog/exception.h"
+#include "userprog/gdt.h"
+#include "userprog/syscall.h"
+#include "userprog/tss.h"
#endif
#ifdef FILESYS
-#include "filesys.h"
-#include "disk.h"
-#include "fsutil.h"
+#include "devices/disk.h"
+#include "filesys/filesys.h"
+#include "filesys/fsutil.h"
#endif
/* Amount of physical memory, in 4 kB pages. */
#include <inttypes.h>
#include <stdint.h>
#include "intr-stubs.h"
-#include "debug.h"
#include "io.h"
-#include "lib.h"
#include "mmu.h"
#include "thread.h"
-#include "timer.h"
+#include "devices/timer.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
/* Number of x86 interrupts. */
#define INTR_CNT 256
#! /usr/bin/perl
print <<'EOF';
-#include "loader.h"
+#include "threads/loader.h"
.data
.globl intr_stubs
#include "malloc.h"
#include <stdint.h>
-#include "debug.h"
-#include "lib.h"
-#include "list.h"
-#include "synch.h"
#include "mmu.h"
#include "palloc.h"
+#include "synch.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "lib/list.h"
/* A simple implementation of malloc().
#ifndef HEADER_MALLOC_H
#define HEADER_MALLOC_H
-#include "debug.h"
+#include "lib/debug.h"
#include <stddef.h>
void malloc_init (void);
#ifndef __ASSEMBLER__
#include <stdint.h>
-#include "debug.h"
+#include "lib/debug.h"
#endif
#include "loader.h"
#include <stdbool.h>
#include <stddef.h>
#include "init.h"
-#include "lib.h"
#include "mmu.h"
#include "palloc.h"
+#include "lib/lib.h"
static uint32_t *base_page_dir;
#include "palloc.h"
#include <stddef.h>
#include <stdint.h>
-#include "debug.h"
#include "init.h"
#include "loader.h"
-#include "lib.h"
-#include "list.h"
#include "mmu.h"
#include "synch.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "lib/list.h"
/* Page allocator. Hands out memory in page-size chunks.
See malloc.h for an allocator that hands out smaller
#include "synch.h"
#include "interrupt.h"
-#include "lib.h"
#include "thread.h"
+#include "lib/lib.h"
/* Initializes semaphore SEMA to VALUE and names it NAME (for
debugging purposes only). A semaphore is a nonnegative
#define HEADER_SYNCH_H 1
#include <stdbool.h>
-#include "list.h"
+#include "lib/list.h"
/* A counting semaphore. */
struct semaphore
#include "thread.h"
#include <stddef.h>
-#include "debug.h"
#include "interrupt.h"
#include "intr-stubs.h"
-#include "lib.h"
#include "mmu.h"
#include "palloc.h"
-#include "random.h"
#include "switch.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "lib/random.h"
#ifdef USERPROG
-#include "gdt.h"
+#include "userprog/gdt.h"
#endif
/* Value for struct thread's `magic' member.
#define HEADER_THREAD_H 1
#include <stdint.h>
-#include "debug.h"
-#include "list.h"
+#include "lib/debug.h"
+#include "lib/list.h"
#ifdef USERPROG
-#include "addrspace.h"
+#include "userprog/addrspace.h"
#endif
/* States in a thread's life cycle. */
-all:
-%:
- $(MAKE) -C build $@
+include Makefile.vars
+include ../Makefile.kernel
--- /dev/null
+DEFINES = -DUSERPROG -DFILESYS
+SUBDIRS = threads devices lib userprog filesys
#include "addrspace.h"
#include <inttypes.h>
-#include "debug.h"
-#include "file.h"
-#include "filesys.h"
-#include "init.h"
-#include "lib.h"
-#include "mmu.h"
-#include "paging.h"
-#include "palloc.h"
-#include "thread.h"
#include "tss.h"
+#include "filesys/file.h"
+#include "filesys/filesys.h"
+#include "lib/debug.h"
+#include "lib/lib.h"
+#include "threads/init.h"
+#include "threads/mmu.h"
+#include "threads/paging.h"
+#include "threads/palloc.h"
+#include "threads/thread.h"
/* We load ELF binaries. The following definitions are taken
from the ELF specification, [ELF1], more-or-less verbatim. */
#include "exception.h"
#include <inttypes.h>
-#include "lib.h"
#include "gdt.h"
-#include "interrupt.h"
-#include "thread.h"
+#include "lib/lib.h"
+#include "threads/interrupt.h"
+#include "threads/thread.h"
static void kill (struct intr_frame *);
static void page_fault (struct intr_frame *);
#include "gdt.h"
-#include "debug.h"
-#include "mmu.h"
-#include "palloc.h"
#include "tss.h"
+#include "lib/debug.h"
+#include "threads/mmu.h"
+#include "threads/palloc.h"
/* The Global Descriptor Table (GDT).
#ifndef HEADER_GDT_H
#define HEADER_GDT_H 1
-#include "loader.h"
+#include "threads/loader.h"
/* Segment selectors.
More selectors are defined by the loader in loader.h. */
#include "syscall.h"
-#include "lib.h"
-#include "interrupt.h"
-#include "thread.h"
+#include "lib/lib.h"
+#include "threads/interrupt.h"
+#include "threads/thread.h"
static void syscall_handler (struct intr_frame *);
#include "tss.h"
#include <stddef.h>
-#include "debug.h"
#include "gdt.h"
-#include "mmu.h"
-#include "palloc.h"
+#include "lib/debug.h"
+#include "threads/mmu.h"
+#include "threads/palloc.h"
/* The Task-State Segment (TSS).