-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
123 lines (90 loc) · 2.86 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
GNU_COWAN = /u/wbcowan/gnuarm-4.0.2
ARM_XCC = $(GNU_COWAN)/arm-elf/bin/gcc
ARM_AS = $(GNU_COWAN)/arm-elf/bin/as
ARM_LD = $(GNU_COWAN)/arm-elf/bin/ld
X86_XCC = /usr/bin/gcc
X86_AS = /usr/bin/as
X86_LD = /usr/bin/gcc
XCC = $(ARM_XCC)
AS = $(ARM_AS)
LD = $(ARM_LD)
CP = /bin/cp
ASTYLE = astyle
ARM_DIR ?= /u/cs452/tftp/ARM
BUILD_DIR ?= build
CONF_DIR ?= conf
DOCS_DIR ?= docs
TEST_DIR ?= src/test
SRC_DIRS ?= src include
MD5_OUT ?= $(BUILD_DIR)/md5_hashes.txt
TARGET_ELF ?= $(TARGET).elf
TARGET_MAP ?= $(BUILD_DIR)/$(TARGET).map
TEST_EXEC ?= tests
LINKER_SCRIPT ?= $(CONF_DIR)/orex.ld
SRC_IGNORE := $(wildcard src/test/*/*.c src/test/*.c)
# $(info $(SRC_IGNORE))
SRCS := $(shell find $(SRC_DIRS) -name *.c)
SRCS := $(filter-out $(SRC_IGNORE), $(SRCS))
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
TEST_IGNORE := $(shell find src/kernel/ -type f -name '*.c' ) \
$(shell find src/user/ -type f -name '*.c' -not -path 'src/user/terminal/terminal.c' ) \
# $(info $(TEST_IGNORE))
TEST_SRCS := $(shell find $(TEST_DIR) -name *.c) $(filter-out $(TEST_IGNORE), $(SRCS))
# $(info $(TEST_SRCS))
TEST_OBJS := $(TEST_SRCS:%=$(BUILD_DIR)/%.o)
TEST_DEPS := $(TEST_OBJS:.o=.d)
# $(info $(TEST_OBJS))
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
ARM_CFLAGS = -c -fPIC -Wall -I. $(INC_FLAGS) -mcpu=arm920t -msoft-float -MMD -MP $(DFLAGS)
ARM_LDFLAGS = -init main -Map $(TARGET_MAP) -N -T $(LINKER_SCRIPT) -L$(GNU_COWAN)/lib/gcc/arm-elf/4.0.2 -L./lib
TEST_CFLAGS = -Wall -I. $(INC_FLAGS)
TEST_LDFLAGS =
CFLAGS = $(ARM_CFLAGS)
LDFLAGS = $(ARM_LDFLAGS)
all: $(BUILD_DIR)/$(TARGET_ELF)
test: XCC = $(X86_XCC)
test: AS = $(X86_AS)
test: LD = $(X86_LD)
test: CFLAGS = $(TEST_CFLAGS)
test: CFLAGS += -DX86
test: LDFLAGS = $(TEST_LDFLAGS)
test: $(BUILD_DIR)/$(TEST_EXEC)
./$(BUILD_DIR)/$(TEST_EXEC)
o2: CFLAGS += -O2
debug: CFLAGS += -DDEBUG
debug: all
ktest: CFLAGS += -DKTEST -DDEBUG
ktest: all
$(BUILD_DIR)/$(TEST_EXEC): $(TEST_OBJS)
@$(LD) $(LDFLAGS) -o $@ $(TEST_OBJS)
$(BUILD_DIR)/$(TARGET_ELF): $(OBJS)
@$(LD) $(LDFLAGS) -o $@ $(OBJS) -lgcc
$(BUILD_DIR)/%.o: %.s
@$(MKDIR_P) $(dir $@)
@$(AS) $(ASFLAGS) $< -o $@
$(BUILD_DIR)/%.c.s: %.c
@$(MKDIR_P) $(dir $@)
$(XCC) -S $(CFLAGS) $< -o $@
.PRECIOUS: $(BUILD_DIR)/%.c.s
# Hashes
hashes:
$(MKDIR_P) $(BUILD_DIR)
$(shell find -regex ".*\.[c|h]" -type f -exec md5sum '{}' \; > $(MD5_OUT))
# Docs
docs: $(addsuffix .pdf, $(basename $(wildcard $(DOCS_DIR)/*.md)))
$(DOCS_DIR)/%.pdf: $(DOCS_DIR)/%.md
$(PANDOC) $(PANDOC_FLAGS) $< -o $@
clean:
$(RM) -r $(BUILD_DIR)
copy:
$(CP) $(BUILD_DIR)/$(TARGET_ELF) $(ARM_DIR)/$(USER)
format:
$(ASTYLE) --options=.astylerc "src/*.c" "include/*.h"
.PHONY: clean hashes docs test format o2
-include $(DEPS)
# test: -include $(TEST_DEPS)
MKDIR_P ?= mkdir -p
PANDOC = pandoc
PANDOC_FLAGS=--metadata date="`date +'%b %d, %Y'`" --toc