2 # This makefile system follows the structuring conventions
3 # recommended by Peter Miller in his excellent paper:
5 # Recursive Make Considered Harmful
6 # http://aegis.sourceforge.net/auug97.pdf
32 # Cross-compiler jos toolchain
34 # This Makefile will automatically use the cross-compiler toolchain
35 # installed as 'i386-jos-elf-*', if one exists. If the host tools ('gcc',
36 # 'objdump', and so forth) compile for a 32-bit x86 ELF target, that will
37 # be detected as well. If you have the right compiler toolchain installed
38 # using a different name, set GCCPREFIX explicitly in conf/env.mk
40 # try to infer the correct GCCPREFIX
42 GCCPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
43 then echo 'i386-jos-elf-'; \
44 elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
46 else echo "***" 1>&2; \
47 echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
48 echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
49 echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
50 echo "*** prefix other than 'i386-jos-elf-', set your GCCPREFIX" 1>&2; \
51 echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
52 echo "*** To turn off this error, run 'gmake GCCPREFIX= ...'." 1>&2; \
53 echo "***" 1>&2; exit 1; fi)
56 CC := $(GCCPREFIX)gcc -pipe
57 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
61 OBJCOPY := $(GCCPREFIX)objcopy
62 OBJDUMP := $(GCCPREFIX)objdump
67 NCC := gcc $(CC_VER) -pipe
72 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
73 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
74 CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -D$(ARCH) -O -fno-builtin -fno-stack-protector -I$(TOP) -MD -Wall -Wno-format -Wno-unused -gstabs
76 # 64 Bit machines need these settings to compile and link
77 UNAME=$(shell uname -m)
78 ifeq ($(UNAME),x86_64)
81 GCC_LIB = $(shell $(CC) -print-libgcc-file-name | sed 's/libgcc.a/32\/libgcc.a/')
84 # Linker flags for ROS user programs
85 ULDFLAGS := -T user/user.ld
87 # Lists that the */Makefrag makefile fragments will add to
90 # Make sure that 'all' is the first target
93 # Eliminate default suffix rules
96 # Delete target files if there is an error (or make is interrupted)
99 # make it so that no intermediate .o files are ever deleted
100 .PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
101 $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o
103 KERN_CFLAGS := $(CFLAGS) -DROS_KERNEL -gstabs
104 USER_CFLAGS := $(CFLAGS) -DROS_USER -gstabs
109 # Include Makefrags for subdirectories
110 include boot/Makefrag
112 include ivylib/Makefrag
113 include kern/Makefrag
114 include user/Makefrag
118 IMAGES = $(OBJDIR)/kern/bochs.img
120 # For deleting the build
125 rm -rf lab$(LAB).tar.gz bochs.out bochs.log
130 grade: $(LABSETUP)grade.sh
131 $(V)$(MAKE) clean >/dev/null 2>/dev/null
133 sh $(LABSETUP)grade.sh
136 turnin --submit porterde cs372h-lab$(LAB) lab$(LAB)-handin.tar.gz
139 tar cf - `find . -type f | grep -v '^\.*$$' | grep -v '/CVS/' | grep -v '/\.svn/' | grep -v 'lab[0-9].*\.tar\.gz'` | gzip > lab$(LAB)-handin.tar.gz
143 $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
144 $(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
145 bochs -q 'display_library: nogui'
148 $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
149 $(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
152 # This magic automatically generates makefile dependencies
153 # for header files included from C source files we compile,
154 # and keeps those dependencies up-to-date every time we recompile.
155 # See 'mergedep.pl' for more information.
156 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
158 @$(PERL) mergedep.pl $@ $^
160 -include $(OBJDIR)/.deps
166 handin tarball clean realclean clean-labsetup distclean grade labsetup