# # This makefile system follows the structuring conventions # recommended by Peter Miller in his excellent paper: # # Recursive Make Considered Harmful # http://aegis.sourceforge.net/auug97.pdf # OBJDIR := obj ifdef GCCPREFIX SETTINGGCCPREFIX := true else -include .gccsetup endif ifdef LAB SETTINGLAB := true else -include .labsetup endif LABADJUST := 0 -include .classconfig TOP = . # Cross-compiler jos toolchain # Users of 32-bit x86 ELF platforms can leave GCCPREFIX empty, # so that they can use the native compilers for their systems. # People on other systems (e.g., x86-64 or Mac OS X) will need # to install an i386-jos-elf tool chain and set GCCPREFIX # by doing # # make 'GCCPREFIX=i386-jos-elf-' gccsetup # CC := $(GCCPREFIX)gcc -pipe GCC_LIB := $(shell $(CC) -print-libgcc-file-name) AS := $(GCCPREFIX)as AR := $(GCCPREFIX)ar LD := $(GCCPREFIX)ld OBJCOPY := $(GCCPREFIX)objcopy OBJDUMP := $(GCCPREFIX)objdump NM := $(GCCPREFIX)nm # Native commands NCC := gcc $(CC_VER) -pipe TAR := gtar PERL := perl # SPLICER := ./splicer.py # Compiler flags # Note that -O2 is required for the boot loader to fit within 512 bytes; # -fno-builtin is required to avoid refs to undefined functions in the kernel. CFLAGS := $(CFLAGS) $(DEFS) -O2 -fno-builtin -I$(TOP) -MD -Wall -Wno-format -ggdb # Linker flags for user programs ULDFLAGS := -Ttext 0x800020 # Lists that the */Makefrag makefile fragments will add to OBJDIRS := # Make sure that 'all' is the first target all: # Eliminate default suffix rules .SUFFIXES: # Delete target files if there is an error (or make is interrupted) .DELETE_ON_ERROR: # make it so that no intermediate .o files are ever deleted .SECONDARY: # Rules for building regular object files $(OBJDIR)/%.o: %.c @echo cc $< @mkdir -p $(@D) @$(CC) -nostdinc $(CFLAGS) -c -o $@ $< $(OBJDIR)/%.o: %.S @mkdir -p $(@D) @echo as $< @$(CC) -nostdinc $(CFLAGS) -c -o $@ $< # Setup a prefix for the GCC tools if we're cross-compiling. gccsetup: echo >.gccsetup "GCCPREFIX=$(GCCPREFIX)" # Include Makefrags for subdirectories include boot/Makefrag include kern/Makefrag include lib/Makefrag include user/Makefrag bochs: $(OBJDIR)/kern/bochs.img $(OBJDIR)/fs/fs.img bochs-nogui # For deleting the build clean: rm -rf $(OBJDIR) grade: @gmake clean >/dev/null 2>/dev/null gmake all sh grade.sh HANDIN_CMD = tar cf - . | gzip | uuencode lab$(LAB).tar.gz | mail 6.828-handin@pdos.lcs.mit.edu handin: clean $(HANDIN_CMD) # For test runs run-%: @rm -f $(OBJDIR)/kern/init.o $(OBJDIR)/kern/bochs.img @gmake "DEFS=-DTEST=binary_user_$*_start -DTESTSIZE=binary_user_$*_size" $(OBJDIR)/kern/bochs.img $(OBJDIR)/fs/fs.img bochs-nogui xrun-%: @rm -f $(OBJDIR)/kern/init.o $(OBJDIR)/kern/bochs.img @gmake "DEFS=-DTEST=binary_user_$*_start -DTESTSIZE=binary_user_$*_size" $(OBJDIR)/kern/bochs.img $(OBJDIR)/fs/fs.img bochs # This magic automatically generates makefile dependencies # for header files included from C source files we compile, # and keeps those dependencies up-to-date every time we recompile. # See 'mergedep.pl' for more information. $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d)) @mkdir -p $(@D) @$(PERL) mergedep.pl $@ $^ -include $(OBJDIR)/.deps .phony: lab%.tar.gz