-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (38 loc) · 1.69 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
XDIR:=/u/cs452/public/xdev
ARCH=cortex-a72
TRIPLE=aarch64-none-elf
XBINDIR:=$(XDIR)/bin
CC:=$(XBINDIR)/$(TRIPLE)-gcc
OBJCOPY:=$(XBINDIR)/$(TRIPLE)-objcopy
OBJDUMP:=$(XBINDIR)/$(TRIPLE)-objdump
KERNDIR = kern
USERDIR = user
LIBDIR = lib
INCLUDEDIR = include
# COMPILE OPTIONS
WARNINGS=-Wall -Wextra -Wpedantic -Wno-unused-const-variable
CFLAGS:=-g -pipe -static $(WARNINGS) -ffreestanding -nostartfiles\
-mcpu=$(ARCH) -static-pie -mstrict-align -fno-builtin -mgeneral-regs-only\
-I./$(INCLUDEDIR) -I./ -O3
# -Wl,option tells g++ to pass 'option' to the linker with commas replaced by spaces
# doing this rather than calling the linker ourselves simplifies the compilation procedure
LDFLAGS:=-Wl,-nmagic -Wl,-Tlinker.ld -Wl,--no-warn-rwx-segments
# Source files and include dirs
SOURCES := $(wildcard $(KERNDIR)/*.[cS]) $(wildcard $(USERDIR)/*.[cS]) $(wildcard $(LIBDIR)/*.[cS]) $(wildcard $(USERDIR)/**/*.[cS])
# Create .o and .d files for every .cc and .S (hand-written assembly) file
OBJECTS := $(patsubst %.c, %.o, $(patsubst %.S, %.o, $(SOURCES)))
DEPENDS := $(patsubst %.c, %.d, $(patsubst %.S, %.d, $(SOURCES)))
# The first rule is the default, ie. "make", "make all" and "make choochoo-os.img" mean the same
all: choochoo-os.img
clean:
rm -f $(OBJECTS) $(DEPENDS) choochoo-os.elf choochoo-os.img
choochoo-os.img: choochoo-os.elf
$(OBJCOPY) $< -O binary $@
choochoo-os.elf: $(OBJECTS) linker.ld
$(CC) $(CFLAGS) $(filter-out %.ld, $^) -o $@ $(LDFLAGS)
@$(OBJDUMP) -d choochoo-os.elf | grep -Fq q0 && printf "\n***** WARNING: SIMD INSTRUCTIONS DETECTED! *****\n\n" || true
%.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
%.o: %.S Makefile
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
-include $(DEPENDS)