forked from cahirwpz/mimiker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
91 lines (71 loc) · 2.29 KB
/
Makefile.common
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# vim: tabstop=8 shiftwidth=8 noexpandtab:
TOPDIR = $(realpath $(dir $(filter %Makefile.common, $(MAKEFILE_LIST))))
SOURCES = $(SOURCES_C) $(SOURCES_ASM)
OBJECTS = $(SOURCES_C:.c=.o) $(SOURCES_ASM:.S=.o)
DEPFILES = $(SOURCES_C:%.c=.%.D) $(SOURCES_ASM:%.S=.%.D)
TRIPLET_CUSTOM = mipsel-unknown-elf-
TRIPLET_IMGTECH = mips-mti-elf-
CUSTOM_TOOLCHAIN_FOUND = $(shell which $(TRIPLET_CUSTOM)gcc > /dev/null; echo $$?)
# If custom toolchain is available, use it. Otherwise fall back to ImgTech's.
ifeq ($(CUSTOM_TOOLCHAIN_FOUND),0)
P = $(TRIPLET_CUSTOM)
else
P = $(TRIPLET_IMGTECH)
endif
CC = $(P)gcc -mips32r2 -EL -g
AR = $(P)ar
AS = $(P)as -mips32r2 -EL -g
NM = $(P)nm
GDB = $(P)gdb
OBJCOPY = $(P)objcopy
OBJDUMP = $(P)objdump
HOSTCC = gcc -g
SYSROOT = $(realpath $(dir $(shell which $(P)gcc))/..)
GENASSYM = $(TOPDIR)/script/genassym.py $(NM)
ASFLAGS =
CFLAGS = -std=gnu11 -Og -Wall -Werror -fno-builtin -ffreestanding
CPPFLAGS = -Wall -Werror -DDEBUG -I$(TOPDIR)/include
LDLIBS =
LDFLAGS = -nostdlib -T malta.ld
LD_EMBED =
DIR = $(patsubst $(TOPDIR)/%,%,$(CURDIR)/)
define emit_dep_rule
CFILE = $(1)
DFILE = .$(patsubst %.S,%.D,$(patsubst %.c,%.D,$(1)))
$$(DFILE): $$(CFILE)
@echo "[DEP] $$(DIR)$$@"
$(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG $$^ -o $$@
endef
%.S: %.c
@echo "[CC] $(DIR)$< -> $(DIR)$@"
$(CC) $(CFLAGS) $(CPPFLAGS) -S -o $@ $<
%.ko: %.c
@echo "[CC] $(DIR)$< -> $(DIR)$@"
$(CC) $(CFLAGS) $(CPPFLAGS) -D_KERNELSPACE -c -o $@ $<
%.o: %.c
@echo "[CC] $(DIR)$< -> $(DIR)$@"
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
%.o: %.S
@echo "[AS] $(DIR)$< -> $(DIR)$@"
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
%.elf: %.ko
@echo "[LD] $(addprefix $(DIR),$(filter %.ko,$^)) -> $(DIR)$@"
$(CC) $(LDFLAGS) $(filter %.ko,$^) -Wl,[email protected] $(LDLIBS) $(LD_EMBED) -o $@
%.test: %.c
@echo "[HOSTCC] $(DIR)$< -> $(DIR)$@"
$(HOSTCC) $(CFLAGS) $(CPPFLAGS) -D_USERSPACE -o $@ $<
%.a:
@echo "[AR] $(addprefix $(DIR),$^) -> $(DIR)$@"
$(AR) rs $@ $^
%.h: %.o
@echo "[ASSYM] $(DIR)$<"
$(GENASSYM) $<
.PHONY: all clean
# Pass "VERBOSE=1" at command line to display command being invoked by GNU Make
ifneq ($(VERBOSE), 1)
.SILENT:
endif
$(foreach file,$(SOURCES) null,$(eval $(call emit_dep_rule,$(file))))
ifeq ($(words $(findstring $(MAKECMDGOALS), clean)), 0)
-include $(DEPFILES)
endif