still serv_close bug...
[mit-jos.git] / GNUmakefile
blob395ce6cc0498f1f36646c44f0e6ae5c5c681a4f2
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
8 OBJDIR := obj
10 ifdef LAB
11 SETTINGLAB := true
12 else
13 -include conf/lab.mk
14 endif
16 -include conf/env.mk
18 ifndef SOL
19 SOL := 0
20 endif
21 ifndef LABADJUST
22 LABADJUST := 0
23 endif
25 ifndef LABSETUP
26 LABSETUP := ./
27 endif
30 TOP = .
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
41 ifndef 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; \
45 then echo ''; \
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)
54 endif
56 CC := $(GCCPREFIX)gcc -pipe
57 AS := $(GCCPREFIX)as
58 AR := $(GCCPREFIX)ar
59 LD := $(GCCPREFIX)ld
60 OBJCOPY := $(GCCPREFIX)objcopy
61 OBJDUMP := $(GCCPREFIX)objdump
62 NM := $(GCCPREFIX)nm
64 # Native commands
65 NCC := gcc $(CC_VER) -pipe
66 TAR := gtar
67 PERL := perl
69 # Compiler flags
70 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
71 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
72 CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
73 CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32
75 # Add -fno-stack-protector if the option exists.
76 CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
78 # Common linker flags
79 LDFLAGS := -m elf_i386
81 # Linker flags for JOS user programs
82 ULDFLAGS := -T user/user.ld
84 GCC_LIB := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
86 # Lists that the */Makefrag makefile fragments will add to
87 OBJDIRS :=
89 # Make sure that 'all' is the first target
90 all:
92 # Eliminate default suffix rules
93 .SUFFIXES:
95 # Delete target files if there is an error (or make is interrupted)
96 .DELETE_ON_ERROR:
98 # make it so that no intermediate .o files are ever deleted
99 .PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
100 $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o
102 KERN_CFLAGS := $(CFLAGS) -DJOS_KERNEL -gstabs
103 USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
108 # Include Makefrags for subdirectories
109 include boot/Makefrag
110 include kern/Makefrag
111 include lib/Makefrag
112 include user/Makefrag
113 include fs/Makefrag
115 IMAGES = $(OBJDIR)/kern/bochs.img $(OBJDIR)/fs/fs.img
117 bochs: $(IMAGES)
118 bochs 'display_library: nogui'
120 # For deleting the build
121 clean:
122 rm -rf $(OBJDIR)
124 realclean: clean
125 rm -rf lab$(LAB).tar.gz bochs.out bochs.log
127 distclean: realclean
128 rm -rf conf/gcc.mk
130 grade: $(LABSETUP)grade.sh
131 $(V)$(MAKE) clean >/dev/null 2>/dev/null
132 $(MAKE) all
133 sh $(LABSETUP)grade.sh
135 handin: tarball
136 @echo Please visit http://pdos.csail.mit.edu/cgi-bin/828handin
137 @echo and upload lab$(LAB)-handin.tar.gz. Thanks!
139 tarball: realclean
140 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
142 # For test runs
143 run-%:
144 $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
145 $(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
146 bochs -q 'display_library: nogui'
148 xrun-%:
149 $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
150 $(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
151 bochs -q
153 # This magic automatically generates makefile dependencies
154 # for header files included from C source files we compile,
155 # and keeps those dependencies up-to-date every time we recompile.
156 # See 'mergedep.pl' for more information.
157 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
158 @mkdir -p $(@D)
159 @$(PERL) mergedep.pl $@ $^
161 -include $(OBJDIR)/.deps
163 always:
166 .PHONY: all always \
167 handin tarball clean realclean clean-labsetup distclean grade labsetup