-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile.gcc
112 lines (77 loc) · 2.19 KB
/
Makefile.gcc
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
PROJ := 5
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
SLASH := /
V := @
GCCPREFIX:=mips-sde-elf-
# eliminate default suffix rules
.SUFFIXES: .c .S .h
# define compiler and flags
HOSTCC := gcc
HOSTCFLAGS := -g -Wall -O2
GDB := $(GCCPREFIX)gdb
THUMIPSCC := ./thumips-cc
CLANG := clang
#CC :=$(GCCPREFIX)gcc
CFLAGS := -fno-builtin -nostdlib -nostdinc
CTYPE := c S
LD := $(GCCPREFIX)ld
AS := $(GCCPREFIX)as -EL -g -mips32
LDFLAGS += -nostdlib
OBJCOPY := $(GCCPREFIX)objcopy
OBJDUMP := $(GCCPREFIX)objdump
COPY := cp
MKDIR := mkdir -p
MV := mv
RM := rm -f
AWK := awk
SED := sed
SH := sh
TR := tr
TOUCH := touch -c
TAR := tar
ZIP := gzip
OBJDIR := obj
BINDIR := bin
SRCDIR := kern
DEPDIR := dep
MODULES := init libs debug driver trap mm sync
SRC_DIR := $(addprefix $(SRCDIR)/,$(MODULES))
BUILD_DIR := $(addprefix $(OBJDIR)/,$(MODULES))
DEP_DIR := $(addprefix $(DEPDIR)/,$(MODULES))
VPATH += $(SRC_DIR)
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
OBJ := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRC))
ASMSRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.S))
OBJ += $(patsubst $(SRCDIR)/%.S, $(OBJDIR)/%.o, $(ASMSRC))
INCLUDES := $(addprefix -I,$(SRC_DIR))
INCLUDES += -I$(SRCDIR)/include
DEPENDS := $(patsubst $(SRCDIR)/%.c, $(DEPDIR)/%.d, $(SRC))
MAKEDEPEND = $(CLANG) -M $(CFLAGS) $(INCLUDES) -o $(DEPDIR)/$*.d $<
#vpath %.c $(SRC_DIR)
#vpath %.S $(SRC_DIR)
.PHONY: all checkdirs clean
all: checkdirs obj/ucore-kernel
$(shell mkdir -p $(DEP_DIR))
obj/ucore-kernel: $(OBJ) tools/kernel.ld
@echo LINK
$(LD) -nostdlib -n -G 0 -static -T tools/kernel.ld $(OBJ) -o $@
$(DEPDIR)/%.d: $(SRCDIR)/%.c
@echo DEP $<
@set -e; rm -f $@; \
$(CLANG) -MM -MT "$(OBJDIR)/$*.o $@" $(CFLAGS) $(INCLUDES) $< > $@;
$(OBJDIR)/%.o: $(SRCDIR)/%.c
/opt/CodeSourcery/Sourcery_CodeBench_Lite_for_MIPS_ELF/bin/mips-sde-elf-gcc -c -EL -G0 $(INCLUDES) $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.S
$(CLANG) $(INCLUDES) -D__ASSEMBLY__ -E $< | $(AS) -o $@
checkdirs: $(BUILD_DIR) $(DEP_DIR)
$(BUILD_DIR):
@mkdir -p $@
$(DEP_DIR):
@mkdir -p $@
clean:
-rm -rf $(BUILD_DIR)
-rm -rf $(DEPDIR)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
endif