2024-09-25 19:00:19 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Run 'make V=1' to turn on verbose commands, or 'make V=0' to turn them off.
|
|
|
|
ifeq ($(V),1)
|
|
|
|
override V =
|
|
|
|
endif
|
|
|
|
ifeq ($(V),0)
|
|
|
|
override V = @
|
|
|
|
endif
|
|
|
|
|
|
|
|
-include conf/env.mk
|
|
|
|
|
|
|
|
LABSETUP ?= ./
|
|
|
|
|
|
|
|
TOP = .
|
|
|
|
|
|
|
|
# try to generate a unique GDB port
|
|
|
|
GDBPORT := $(shell expr `id -u` % 5000 + 25000)
|
|
|
|
|
|
|
|
CC := $(GCCPREFIX)gcc -pipe
|
|
|
|
AS := $(GCCPREFIX)as
|
|
|
|
AR := $(GCCPREFIX)ar
|
|
|
|
LD := $(GCCPREFIX)ld
|
|
|
|
OBJCOPY := $(GCCPREFIX)objcopy
|
|
|
|
OBJDUMP := $(GCCPREFIX)objdump
|
|
|
|
NM := $(GCCPREFIX)nm
|
|
|
|
|
2024-09-25 19:09:15 +00:00
|
|
|
QEMU = qemu-system-i386
|
2024-09-25 19:00:19 +00:00
|
|
|
|
|
|
|
# Native commands
|
|
|
|
NCC := gcc $(CC_VER) -pipe
|
|
|
|
NATIVE_CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -I$(TOP) -MD -Wall
|
|
|
|
TAR := tar
|
|
|
|
PERL := perl
|
|
|
|
|
|
|
|
# Compiler flags
|
|
|
|
# -fno-builtin is required to avoid refs to undefined functions in the kernel.
|
|
|
|
# Only optimize to -O1 to discourage inlining, which complicates backtraces.
|
|
|
|
CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
|
|
|
|
CFLAGS += -fno-omit-frame-pointer
|
|
|
|
CFLAGS += -std=gnu99
|
|
|
|
CFLAGS += -static
|
2024-09-25 19:04:20 +00:00
|
|
|
CFLAGS += -Wall -Wno-format -Wno-unused -Werror -m32
|
2024-09-25 19:00:19 +00:00
|
|
|
# -fno-tree-ch prevented gcc from sometimes reordering read_ebp() before
|
|
|
|
# mon_backtrace()'s function prologue on gcc version: (Debian 4.7.2-5) 4.7.2
|
|
|
|
CFLAGS += -fno-tree-ch
|
|
|
|
|
|
|
|
# prevent relative addressing and dynamic linking
|
|
|
|
CFLAGS += -fno-pic -fno-pie
|
|
|
|
|
|
|
|
# Add -fno-stack-protector if the option exists.
|
|
|
|
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
|
|
|
|
|
|
|
|
# Common linker flags
|
|
|
|
LDFLAGS := -m elf_i386
|
|
|
|
# this can cause some strange behavior with GNU ld for some reason
|
|
|
|
#LDFLAGS += -no-pie
|
|
|
|
|
|
|
|
# Linker flags for JOS user programs
|
|
|
|
ULDFLAGS := -T user/user.ld
|
|
|
|
|
|
|
|
GCC_LIB := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
.PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
|
|
|
|
$(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/net/%.o \
|
|
|
|
$(OBJDIR)/user/%.o
|
|
|
|
|
2024-09-25 19:04:20 +00:00
|
|
|
KERN_CFLAGS := $(CFLAGS) -DJOS_KERNEL
|
|
|
|
USER_CFLAGS := $(CFLAGS) -DJOS_USER
|
2024-09-25 19:00:19 +00:00
|
|
|
|
|
|
|
# Update .vars.X if variable X has changed since the last make run.
|
|
|
|
#
|
|
|
|
# Rules that use variable X should depend on $(OBJDIR)/.vars.X. If
|
|
|
|
# the variable's value has changed, this will update the vars file and
|
|
|
|
# force a rebuild of the rule that depends on it.
|
|
|
|
$(OBJDIR)/.vars.%: FORCE
|
|
|
|
$(V)echo "$($*)" | cmp -s $@ || echo "$($*)" > $@
|
|
|
|
.PRECIOUS: $(OBJDIR)/.vars.%
|
|
|
|
.PHONY: FORCE
|
|
|
|
|
|
|
|
|
|
|
|
# Include Makefrags for subdirectories
|
|
|
|
include boot/Makefrag
|
|
|
|
include kern/Makefrag
|
|
|
|
|
|
|
|
|
|
|
|
QEMUOPTS = -drive file=$(OBJDIR)/kern/kernel.img,index=0,media=disk,format=raw -serial mon:stdio -gdb tcp::$(GDBPORT)
|
|
|
|
QEMUOPTS += $(shell if $(QEMU) -nographic -help | grep -q '^-D '; then echo '-D qemu.log'; fi)
|
|
|
|
IMAGES = $(OBJDIR)/kern/kernel.img
|
|
|
|
QEMUOPTS += $(QEMUEXTRA)
|
|
|
|
|
|
|
|
.gdbinit: gdbinit.tmpl
|
|
|
|
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
|
|
|
|
|
|
|
|
gdb:
|
|
|
|
gdb -q -n -x .gdbinit
|
|
|
|
|
|
|
|
pre-qemu: .gdbinit
|
|
|
|
|
|
|
|
qemu: $(IMAGES) pre-qemu
|
|
|
|
$(QEMU) $(QEMUOPTS)
|
|
|
|
|
|
|
|
qemu-nox: $(IMAGES) pre-qemu
|
|
|
|
@echo "***"
|
|
|
|
@echo "*** Use Ctrl-a x to exit qemu"
|
|
|
|
@echo "***"
|
|
|
|
$(QEMU) -nographic $(QEMUOPTS)
|
|
|
|
|
|
|
|
qemu-gdb: $(IMAGES) pre-qemu
|
|
|
|
@echo "***"
|
|
|
|
@echo "*** Now run 'make gdb'." 1>&2
|
|
|
|
@echo "***"
|
|
|
|
$(QEMU) $(QEMUOPTS) -S
|
|
|
|
|
|
|
|
qemu-nox-gdb: $(IMAGES) pre-qemu
|
|
|
|
@echo "***"
|
|
|
|
@echo "*** Now run 'make gdb'." 1>&2
|
|
|
|
@echo "***"
|
|
|
|
$(QEMU) -nographic $(QEMUOPTS) -S
|
|
|
|
|
|
|
|
print-qemu:
|
|
|
|
@echo $(QEMU)
|
|
|
|
|
|
|
|
print-gdbport:
|
|
|
|
@echo $(GDBPORT)
|
|
|
|
|
|
|
|
# For deleting the build
|
|
|
|
clean:
|
|
|
|
rm -rf $(OBJDIR) .gdbinit jos.in qemu.log
|
|
|
|
|
|
|
|
realclean: clean
|
|
|
|
|
|
|
|
distclean: realclean
|
|
|
|
rm -rf conf/gcc.mk
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
always:
|
|
|
|
@:
|
|
|
|
|
|
|
|
.PHONY: all always \
|
|
|
|
clean realclean distclean
|