-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathMakefile
More file actions
128 lines (99 loc) · 3.98 KB
/
Makefile
File metadata and controls
128 lines (99 loc) · 3.98 KB
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
124
125
126
127
128
ARCH := riscv
# in-tree build
SRC_DIR := .
# Build directories
BUILD_DIR := $(SRC_DIR)/build
BUILD_APP_DIR := $(BUILD_DIR)/app
BUILD_KERNEL_DIR := $(BUILD_DIR)/kernel
BUILD_LIB_DIR := $(BUILD_DIR)/lib
# Apps requiring M-mode (kernel API tests)
# All other apps run in U-mode by default (secure)
MMODE_APPS := cond coop cpubench echo hello mqueues mutex \
pipes pipes_small pipes_struct prodcons progress \
rtsched semaphore suspend test64 test_libc timer timer_kill \
privilege_switch
# Auto-detect: if building an M-mode app, enable CONFIG_PRIVILEGED
ifneq ($(filter $(MAKECMDGOALS),$(MMODE_APPS)),)
CONFIG_PRIVILEGED := 1
endif
include mk/common.mk
# architecture-specific settings
include arch/$(ARCH)/build.mk
# Include directories
INC_DIRS += -I $(SRC_DIR)/include \
-I $(SRC_DIR)/include/lib
KERNEL_OBJS := timer.o mqueue.o pipe.o semaphore.o mutex.o logger.o error.o syscall.o task.o memprot.o main.o
KERNEL_OBJS := $(addprefix $(BUILD_KERNEL_DIR)/,$(KERNEL_OBJS))
deps += $(KERNEL_OBJS:%.o=%.o.d)
LIB_OBJS := ctype.o malloc.o math.o memory.o random.o stdio.o string.o queue.o
LIB_OBJS := $(addprefix $(BUILD_LIB_DIR)/,$(LIB_OBJS))
deps += $(LIB_OBJS:%.o=%.o.d)
# Applications
APPS := coop echo hello mqueues semaphore mutex cond \
pipes pipes_small pipes_struct prodcons progress \
rtsched suspend test64 timer timer_kill \
cpubench test_libc umode privilege_switch pmp
# Output files for __link target
IMAGE_BASE := $(BUILD_DIR)/image
IMAGE_FILES := $(IMAGE_BASE).elf $(IMAGE_BASE).map $(IMAGE_BASE).lst \
$(IMAGE_BASE).sec $(IMAGE_BASE).cnt $(IMAGE_BASE).bin \
$(IMAGE_BASE).hex $(BUILD_DIR)/code.txt
# Default target
.DEFAULT_GOAL := linmo
# Phony targets
.PHONY: linmo rebuild clean distclean
# Create build directories
$(BUILD_DIR):
$(Q)mkdir -p $(BUILD_APP_DIR) $(BUILD_KERNEL_DIR) $(BUILD_LIB_DIR)
# Pattern rules for object files
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(VECHO) " CC\t$@\n"
$(Q)$(CC) $(CFLAGS) -c -MMD -MF $@.d -o $@ $<
# Main library target
linmo: $(BUILD_DIR)/liblinmo.a
$(BUILD_DIR)/liblinmo.a: $(HAL_OBJS) $(KERNEL_OBJS) $(LIB_OBJS)
$(VECHO) " AR\t$@\n"
$(Q)$(AR) $(ARFLAGS) $@ $^
# Application pattern rule
$(APPS): %: rebuild $(BUILD_APP_DIR)/%.o linmo
$(Q)$(MAKE) --no-print-directory __link
# Link target - creates all output files
__link: $(IMAGE_FILES)
$(IMAGE_BASE).elf: $(BUILD_APP_DIR)/*.o $(BUILD_DIR)/liblinmo.a $(ENTRY_OBJ)
$(VECHO) " LD\t$@\n"
$(Q)$(LD) $(LDFLAGS) -T$(LDSCRIPT) -Map $(IMAGE_BASE).map -o $@ $(BUILD_APP_DIR)/*.o $(ENTRY_OBJ) -L$(BUILD_DIR) -llinmo
$(IMAGE_BASE).lst: $(IMAGE_BASE).elf
$(VECHO) " DUMP\t$@\n"
$(Q)$(DUMP) --disassemble --reloc $< > $@
$(IMAGE_BASE).sec: $(IMAGE_BASE).elf
$(VECHO) " DUMP\t$@\n"
$(Q)$(DUMP) -h $< > $@
$(IMAGE_BASE).cnt: $(IMAGE_BASE).elf
$(VECHO) " DUMP\t$@\n"
$(Q)$(DUMP) -s $< > $@
$(IMAGE_BASE).bin: $(IMAGE_BASE).elf
$(VECHO) " COPY\t$@\n"
$(Q)$(OBJ) -O binary $< $@
$(IMAGE_BASE).hex: $(IMAGE_BASE).elf
$(VECHO) " COPY\t$@\n"
$(Q)$(OBJ) -R .eeprom -O ihex $< $@
$(BUILD_DIR)/code.txt: $(IMAGE_BASE).bin
$(VECHO) " DUMP\t$@\n"
$(Q)hexdump -v -e '4/1 "%02x" "\n"' $< > $@
@$(SIZE) $(IMAGE_BASE).elf
# Utility targets
rebuild:
$(Q)find '$(BUILD_APP_DIR)' '$(BUILD_KERNEL_DIR)' -type f -name '*.o' -delete 2>/dev/null || true
$(Q)rm -f '$(BUILD_DIR)/liblinmo.a' 2>/dev/null || true
$(Q)mkdir -p $(BUILD_APP_DIR) $(BUILD_KERNEL_DIR) $(BUILD_LIB_DIR)
clean:
$(VECHO) "Cleaning build artifacts...\n"
$(Q)find '$(BUILD_APP_DIR)' '$(BUILD_KERNEL_DIR)' -type f -name '*.o' -delete 2>/dev/null || true
$(Q)find '$(BUILD_DIR)' -type f \( -name '*.o' -o -name '*~' -o -name 'image.*' -o -name 'code.*' \) -delete 2>/dev/null || true
$(Q)find '$(SRC_DIR)' -maxdepth 1 -type f -name '*.o' -delete 2>/dev/null || true
@$(RM) $(deps)
distclean: clean
$(VECHO) "Deep cleaning...\n"
$(Q)find '$(BUILD_DIR)' -type f -name '*.a' -delete 2>/dev/null || true
$(Q)rm -rf '$(BUILD_DIR)' 2>/dev/null || true
-include $(deps)