Skip to content

Commit 8e2612d

Browse files
committed
Refactor GNUmakefile
1 parent 04c2a9e commit 8e2612d

File tree

2 files changed

+36
-124
lines changed

2 files changed

+36
-124
lines changed

GNUmakefile

+30-118
Original file line numberDiff line numberDiff line change
@@ -5,86 +5,29 @@
55
# Recursive Make Considered Harmful
66
# http://aegis.sourceforge.net/auug97.pdf
77
#
8-
OBJDIR := obj
9-
10-
ifdef LAB
11-
SETTINGLAB := true
12-
else
13-
-include conf/lab.mk
14-
endif
15-
16-
-include conf/env.mk
17-
18-
ifndef SOL
19-
SOL := 0
20-
endif
21-
ifndef LABADJUST
22-
LABADJUST := 0
23-
endif
24-
25-
ifndef LABSETUP
26-
LABSETUP := ./
27-
endif
288

9+
V := @
10+
TOP := .
11+
OBJDIR := obj
12+
TOOLPREFIX := i386-elf-
13+
QEMU := qemu-system-i386
14+
PERL := perl
15+
IMAGE := $(OBJDIR)/fos.img
2916

30-
TOP = .
17+
CC := $(TOOLPREFIX)gcc -m32 -pipe
18+
GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
19+
AS := $(TOOLPREFIX)as --32
20+
AR := $(TOOLPREFIX)ar
21+
LD := $(TOOLPREFIX)ld -m elf_i386
22+
OBJCOPY := $(TOOLPREFIX)objcopy
23+
OBJDUMP := $(TOOLPREFIX)objdump
24+
NM := $(TOOLPREFIX)nm
3125

32-
# Cross-compiler fos toolchain
33-
#
34-
# This Makefile will automatically use the cross-compiler toolchain
35-
# installed as 'i386-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
39-
40-
# try to infer the correct GCCPREFIX
41-
ifndef GCCPREFIX
42-
GCCPREFIX := $(shell if i386-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
43-
then echo 'i386-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-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-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
55-
56-
# Note for migration to new build systems, if this doesn't work with 64 compiler try
57-
# to add specific 32bit options like: -m32, --32 and -m elf_i386 to CC, AS, AR and LD
58-
#CC := $(GCCPREFIX)gcc -m32 -pipe
59-
#GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
60-
#AS := $(GCCPREFIX)as --32
61-
#AR := $(GCCPREFIX)ar
62-
#LD := $(GCCPREFIX)ld -m elf_i386
63-
#OBJCOPY := $(GCCPREFIX)objcopy
64-
#OBJDUMP := $(GCCPREFIX)objdump
65-
#NM := $(GCCPREFIX)nm
66-
67-
CC := i386-elf-gcc -m32 -pipe
68-
GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
69-
AS := i386-elf-as --32
70-
AR := i386-elf-ar
71-
LD := i386-elf-ld -m elf_i386
72-
OBJCOPY := i386-elf-objcopy
73-
OBJDUMP := i386-elf-objdump
74-
NM := i386-elf-nm
75-
76-
77-
# Note for migration to new build systems, if this doesn't work with 64 compilers, try adding -m32 to NCC flags
78-
# Native commands
79-
NCC := gcc $(CC_VER) -m32 -pipe
80-
TAR := gtar
81-
PERL := perl
8226

8327
# Compiler flags
8428
# -fno-builtin is required to avoid refs to undefined functions in the kernel.
8529
# Only optimize to -O1 to discourage inlining, which complicates backtraces.
86-
#CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O -fno-builtin -I$(TOP) -MD -Wall -Wno-format -Wno-unused -Werror -gstabs
87-
CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O0 -fno-builtin -I$(TOP) -MD -Wall -Wno-format -Wno-unused -Werror -fno-stack-protector -ggdb -g3
30+
CFLAGS := -O0 -fno-builtin -I$(TOP) -MD -Wall -Wno-format -Wno-unused -Werror -fno-stack-protector -ggdb -g3
8831

8932
# Linker flags for FOS user programs
9033
ULDFLAGS := -T user/user.ld
@@ -102,13 +45,14 @@ all:
10245
.DELETE_ON_ERROR:
10346

10447
# make it so that no intermediate .o files are ever deleted
105-
.PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
106-
$(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o
48+
.PRECIOUS: %.o \
49+
$(OBJDIR)/boot/%.o \
50+
$(OBJDIR)/kern/%.o \
51+
$(OBJDIR)/lib/%.o \
52+
$(OBJDIR)/user/%.o
10753

10854
KERN_CFLAGS := $(CFLAGS) -DFOS_KERNEL -gstabs
109-
USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
110-
111-
55+
USER_CFLAGS := $(CFLAGS) -DFOS_USER -gstabs
11256

11357

11458
# Include Makefrags for subdirectories
@@ -118,41 +62,18 @@ include lib/Makefrag
11862
include user/Makefrag
11963

12064

121-
IMAGE = $(OBJDIR)/kern/fos.img
122-
123-
# For deleting the build
124-
clean:
125-
rm -rf $(OBJDIR)
126-
127-
realclean: clean
128-
rm -rf lab$(LAB).tar.gz
129-
130-
distclean: realclean
131-
rm -rf conf/gcc.mk
65+
# Emulators
13266

133-
grade: $(LABSETUP)grade.sh
134-
$(V)$(MAKE) clean >/dev/null 2>/dev/null
135-
$(MAKE) all
136-
sh $(LABSETUP)grade.sh
137-
138-
handin: tarball
139-
@echo Please visit http://pdos.csail.mit.edu/cgi-bin/828handin
140-
@echo and upload lab$(LAB)-handin.tar.gz. Thanks!
67+
QEMUOPTS = -drive file=$(IMAGE),media=disk,format=raw -smp 2 -m 512 $(QEMUEXTRAS)
14168

142-
tarball: realclean
143-
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
69+
qemu:
70+
$(V)$(QEMU) -serial mon:stdio $(QEMUOPTS)
14471

145-
# For test runs
14672

147-
#run-%:
148-
# $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
149-
# $(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
150-
# bochs -q 'display_library: nogui'
73+
# For deleting the build
74+
clean:
75+
rm -rf $(OBJDIR)
15176

152-
#xrun-%:
153-
# $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
154-
# $(V)$(MAKE) "DEFS=-DTEST=_binary_obj_user_$*_start -DTESTSIZE=_binary_obj_user_$*_size" $(IMAGES)
155-
# bochs -q
15677

15778
# This magic automatically generates makefile dependencies
15879
# for header files included from C source files we compile,
@@ -164,14 +85,5 @@ $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
16485

16586
-include $(OBJDIR)/.deps
16687

167-
always:
168-
@:
169-
170-
QEMU := qemu-system-i386
171-
QEMUOPTS = -drive file=$(IMAGE),media=disk,format=raw -smp 2 -m 512 $(QEMUEXTRAS)
172-
173-
qemu:
174-
$(V)$(QEMU) -serial mon:stdio $(QEMUOPTS)
17588

176-
.PHONY: all always qemu \
177-
handin tarball clean realclean clean-labsetup distclean grade labsetup
89+
.PHONY: all clean qemu

kern/Makefrag

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES) kern/kernel.ld
6969
$(V)$(NM) -n $@ > [email protected]
7070

7171
# How to build the FOS disk image
72-
$(OBJDIR)/kern/fos.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
72+
$(IMAGE): $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
7373
@echo + mk $@
74-
$(V)dd if=/dev/zero of=$(OBJDIR)/kern/fos.img~ count=10000 2>/dev/null
75-
$(V)dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/fos.img~ conv=notrunc 2>/dev/null
76-
$(V)dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/fos.img~ seek=1 conv=notrunc 2>/dev/null
77-
$(V)mv $(OBJDIR)/kern/fos.img~ $(OBJDIR)/kern/fos.img
74+
$(V)dd if=/dev/zero of=$(IMAGE)~ count=10000 2>/dev/null
75+
$(V)dd if=$(OBJDIR)/boot/boot of=$(IMAGE)~ conv=notrunc 2>/dev/null
76+
$(V)dd if=$(OBJDIR)/kern/kernel of=$(IMAGE)~ seek=1 conv=notrunc 2>/dev/null
77+
$(V)mv $(IMAGE)~ $(IMAGE)
7878

79-
all: $(OBJDIR)/kern/fos.img
79+
all: $(IMAGE)
8080

8181
grub: $(OBJDIR)/fos-grub
8282

0 commit comments

Comments
 (0)