-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (73 loc) · 2.89 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
# Copyright 2024, UNSW
# SPDX-License-Identifier: BSD-2-Clause
ifndef MICROKIT_SDK
$(error MICROKIT_SDK is not set)
endif
ifndef BUILD_DIR
$(error BUILD_DIR is not set)
endif
ifndef MICROKIT_BOARD
$(error MICROKIT_BOARD is not set)
endif
ifndef MICROKIT_CONFIG
$(error MICROKIT_CONFIG is not set)
endif
ifndef CPU
$(error CPU is not set)
endif
ifndef TARGET
$(error TARGET is not set)
endif
# Absolute path to root directory of libmicrokitco
ifndef LIBMICROKITCO_PATH
$(error LIBMICROKITCO_PATH is not set)
endif
# Absolute path to the directory containing libmicrokitco_opts.h
ifndef LIBMICROKITCO_OPT_PATH
$(error LIBMICROKITCO_OPT_PATH is not set)
else
CO_CC_INCLUDE_OPT_FLAG = -I$(LIBMICROKITCO_OPT_PATH)
endif
ifndef LIBCO_PATH
LIBCO_PATH := $(LIBMICROKITCO_PATH)/libco
endif
ifdef LLVM
CO_CC := clang
CO_LD := ld.lld
CO_CFLAGS = -target $(TARGET) -Wno-unused-command-line-argument
else
ifndef TOOLCHAIN
$(error your TOOLCHAIN triple must be specified for non-LLVM toolchain setup. E.g. TOOLCHAIN = aarch64-none-elf)
else
CO_CC := $(TOOLCHAIN)-gcc
CO_LD := $(TOOLCHAIN)-ld
CO_LDFLAGS =
endif
endif
LIBMICROKITCO_BUILD_DIR := $(BUILD_DIR)/libmicrokitco
LIBCO_OBJ := $(LIBMICROKITCO_BUILD_DIR)/libco_$(TARGET).o
LIBMICROKITCO_BARE_OBJ := $(LIBMICROKITCO_BUILD_DIR)/libmicrokitco_bare_$(TARGET).o
LIBMICROKITCO_FINAL_OBJ := $(LIBMICROKITCO_BUILD_DIR)/libmicrokitco.a
CO_CFLAGS += -c -O2 -nostdlib -ffreestanding -Wall -Wno-unused-function -Wno-unused-variable
ifeq (aarch64,$(findstring aarch64,$(TARGET)))
CO_CFLAGS += -mtune=$(shell echo $(CPU) | tr A-Z a-z) -mstrict-align
else ifeq (x86_64,$(findstring x86_64,$(TARGET)))
CO_CFLAGS += -mtune=$(shell echo $(CPU) | tr A-Z a-z) -Wno-parentheses
else ifeq (riscv64,$(findstring riscv64,$(TARGET)))
CO_CFLAGS += -mcmodel=$(shell echo $(CPU) | tr A-Z a-z) -mstrict-align -march=rv64imafdc_zicsr_zifencei -mabi=lp64d
else
$(error Unsupported target: TARGET="$(TARGET)")
endif
CO_CC_INCLUDE_MICROKIT_FLAG := -I$(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG)/include
CO_CC_INCLUDE_LIBCO_FLAG := -I$(LIBCO_PATH)
all: libmicrokitco_directory $(LIBMICROKITCO_FINAL_OBJ)
.PHONY: libmicrokitco_directory
libmicrokitco_directory:
$(info $(shell mkdir -p $(BUILD_DIR)/libmicrokitco))
$(LIBCO_OBJ): $(LIBCO_PATH)/libco.c $(LIBCO_PATH)/libco.h $(LIBCO_PATH)/aarch64.c $(LIBCO_PATH)/amd64.c $(LIBCO_PATH)/arm.c $(LIBCO_PATH)/riscv64.c $(LIBCO_PATH)/settings.h
$(CO_CC) $(CO_CFLAGS) -Wno-unused-value $< -o $@
$(LIBMICROKITCO_BARE_OBJ): $(LIBMICROKITCO_PATH)/libmicrokitco.c $(LIBMICROKITCO_PATH)/libmicrokitco.h $(LIBMICROKITCO_PATH)/libhostedqueue/libhostedqueue.h $(LIBMICROKITCO_OPT_PATH)/libmicrokitco_opts.h
$(CO_CC) $(CO_CFLAGS) $(CO_CC_INCLUDE_LIBCO_FLAG) $(CO_CC_INCLUDE_MICROKIT_FLAG) $(CO_CC_INCLUDE_OPT_FLAG) $< -o $@
$(LIBMICROKITCO_FINAL_OBJ): $(LIBCO_OBJ) $(LIBMICROKITCO_BARE_OBJ)
$(CO_LD) $(CO_LDFLAGS) -r $^ -o $@
rm $(LIBCO_OBJ) $(LIBMICROKITCO_BARE_OBJ)