added base src
[xv6-db.git] / Makefile
blob114fa5881c515443cd745a35db70964e2340a1cc
1 OBJS = \
2 bio.o\
3 console.o\
4 exec.o\
5 file.o\
6 fs.o\
7 ide.o\
8 ioapic.o\
9 kalloc.o\
10 kbd.o\
11 lapic.o\
12 main.o\
13 mp.o\
14 picirq.o\
15 pipe.o\
16 proc.o\
17 spinlock.o\
18 string.o\
19 swtch.o\
20 syscall.o\
21 sysfile.o\
22 sysproc.o\
23 timer.o\
24 trapasm.o\
25 trap.o\
26 uart.o\
27 vectors.o\
28 vm.o\
30 # Cross-compiling (e.g., on Mac OS X)
31 #TOOLPREFIX = i386-jos-elf-
33 # Using native tools (e.g., on X86 Linux)
34 #TOOLPREFIX =
36 # Try to infer the correct TOOLPREFIX if not set
37 ifndef TOOLPREFIX
38 TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
39 then echo 'i386-jos-elf-'; \
40 elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
41 then echo ''; \
42 else echo "***" 1>&2; \
43 echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
44 echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
45 echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
46 echo "*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \
47 echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
48 echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
49 echo "***" 1>&2; exit 1; fi)
50 endif
52 # If the makefile can't find QEMU, specify its path here
53 #QEMU =
55 # Try to infer the correct QEMU
56 ifndef QEMU
57 QEMU = $(shell if which qemu > /dev/null; \
58 then echo qemu; exit; \
59 else \
60 qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \
61 if test -x $$qemu; then echo $$qemu; exit; fi; fi; \
62 echo "***" 1>&2; \
63 echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \
64 echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \
65 echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \
66 echo "***" 1>&2; exit 1)
67 endif
69 CC = $(TOOLPREFIX)gcc
70 AS = $(TOOLPREFIX)gas
71 LD = $(TOOLPREFIX)ld
72 OBJCOPY = $(TOOLPREFIX)objcopy
73 OBJDUMP = $(TOOLPREFIX)objdump
74 CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror
75 CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
76 ASFLAGS = -m32 -gdwarf-2
77 # FreeBSD ld wants ``elf_i386_fbsd''
78 LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null)
80 xv6.img: bootblock kernel fs.img
81 dd if=/dev/zero of=xv6.img count=10000
82 dd if=bootblock of=xv6.img conv=notrunc
83 dd if=kernel of=xv6.img seek=1 conv=notrunc
85 xv6memfs.img: bootblock kernelmemfs
86 dd if=/dev/zero of=xv6memfs.img count=10000
87 dd if=bootblock of=xv6memfs.img conv=notrunc
88 dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
90 bootblock: bootasm.S bootmain.c
91 $(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c
92 $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S
93 $(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o
94 $(OBJDUMP) -S bootblock.o > bootblock.asm
95 $(OBJCOPY) -S -O binary -j .text bootblock.o bootblock
96 ./sign.pl bootblock
98 bootother: bootother.S
99 $(CC) $(CFLAGS) -nostdinc -I. -c bootother.S
100 $(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootother.out bootother.o
101 $(OBJCOPY) -S -O binary bootother.out bootother
102 $(OBJDUMP) -S bootother.o > bootother.asm
104 initcode: initcode.S
105 $(CC) $(CFLAGS) -nostdinc -I. -c initcode.S
106 $(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o
107 $(OBJCOPY) -S -O binary initcode.out initcode
108 $(OBJDUMP) -S initcode.o > initcode.asm
110 kernel: $(OBJS) multiboot.o data.o bootother initcode
111 $(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernel multiboot.o data.o $(OBJS) -b binary initcode bootother
112 $(OBJDUMP) -S kernel > kernel.asm
113 $(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
115 # kernelmemfs is a copy of kernel that maintains the
116 # disk image in memory instead of writing to a disk.
117 # This is not so useful for testing persistent storage or
118 # exploring disk buffering implementations, but it is
119 # great for testing the kernel on real hardware without
120 # needing a scratch disk.
121 MEMFSOBJS = $(filter-out ide.o,$(OBJS)) memide.o
122 kernelmemfs: $(MEMFSOBJS) multiboot.o data.o bootother initcode fs.img
123 $(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernelmemfs multiboot.o data.o $(MEMFSOBJS) -b binary initcode bootother fs.img
124 $(OBJDUMP) -S kernelmemfs > kernelmemfs.asm
125 $(OBJDUMP) -t kernelmemfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym
127 tags: $(OBJS) bootother.S _init
128 etags *.S *.c
130 vectors.S: vectors.pl
131 perl vectors.pl > vectors.S
133 ULIB = ulib.o usys.o printf.o umalloc.o
135 _%: %.o $(ULIB)
136 $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
137 $(OBJDUMP) -S $@ > $*.asm
138 $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
140 _forktest: forktest.o $(ULIB)
141 # forktest has less library code linked in - needs to be small
142 # in order to be able to max out the proc table.
143 $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o
144 $(OBJDUMP) -S _forktest > forktest.asm
146 mkfs: mkfs.c fs.h
147 gcc -m32 -Werror -Wall -o mkfs mkfs.c
149 UPROGS=\
150 _cat\
151 _echo\
152 _forktest\
153 _grep\
154 _init\
155 _kill\
156 _ln\
157 _ls\
158 _mkdir\
159 _rm\
160 _sh\
161 _stressfs\
162 _usertests\
163 _wc\
164 _zombie\
166 fs.img: mkfs README $(UPROGS)
167 ./mkfs fs.img README $(UPROGS)
169 -include *.d
171 clean:
172 rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
173 *.o *.d *.asm *.sym vectors.S parport.out \
174 bootblock kernel xv6.img fs.img mkfs \
175 $(UPROGS)
177 # make a printout
178 FILES = $(shell grep -v '^\#' runoff.list)
179 PRINT = runoff.list runoff.spec $(FILES)
181 xv6.pdf: $(PRINT)
182 ./runoff
183 ls -l xv6.pdf
185 print: xv6.pdf
187 # run in emulators
189 bochs : fs.img xv6.img
190 if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi
191 bochs -q
193 # try to generate a unique GDB port
194 GDBPORT = $(shell expr `id -u` % 5000 + 25000)
195 # QEMU's gdb stub command line changed in 0.11
196 QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
197 then echo "-gdb tcp::$(GDBPORT)"; \
198 else echo "-s -p $(GDBPORT)"; fi)
199 ifndef CPUS
200 CPUS := 2
201 endif
202 QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS)
204 qemu: fs.img xv6.img
205 $(QEMU) -serial mon:stdio $(QEMUOPTS)
207 qemu-memfs: xv6memfs.img
208 $(QEMU) xv6memfs.img -smp $(CPUS)
210 qemu-nox: fs.img xv6.img
211 $(QEMU) -nographic $(QEMUOPTS)
213 .gdbinit: .gdbinit.tmpl
214 sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
216 qemu-gdb: fs.img xv6.img .gdbinit
217 @echo "*** Now run 'gdb'." 1>&2
218 $(QEMU) -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB)
220 qemu-nox-gdb: fs.img xv6.img .gdbinit
221 @echo "*** Now run 'gdb'." 1>&2
222 $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)