-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
57 lines (43 loc) · 1.49 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
include toolchain.mk
# helper functions
rwildcard = $(foreach d, $(wildcard $(1:=/*)), $(call rwildcard, $d, $2) $(filter $(subst *, %, $2), $d))
# directories
TOP_DIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
OBJ_DIR := $(BUILD_DIR)/obj
LIB_DIR := $(TOP_DIR)/lib
EXAMPLES_DIR := $(TOP_DIR)/examples
EXAMPLES_OBJ_DIR := $(OBJ_DIR)/examples
EXAMPLES_BIN_DIR := $(BUILD_DIR)/examples
# source & target of library
LIB_SRC := $(call rwildcard, $(LIB_DIR), *.yu)
LIB_OBJ := $(patsubst $(TOP_DIR)/%.yu, $(OBJ_DIR)/%.yu.o, $(LIB_SRC))
LIB_TARGET := $(BUILD_DIR)/libyu.a
# source & target of examples
EXAMPLES_SRC := $(call rwildcard, $(EXAMPLES_DIR), *.yu)
EXAMPLES_OBJ := $(patsubst $(TOP_DIR)/%.yu, $(OBJ_DIR)/%.yu.o, $(EXAMPLES_SRC))
EXAMPLES_TARGET := $(patsubst $(EXAMPLES_OBJ_DIR)/%.yu.o, $(EXAMPLES_BIN_DIR)/%, $(EXAMPLES_OBJ))
.SILENT:
.PHONY: all clean libyu examples
all: libyu examples
clean:
-rm -rf $(OBJ_DIR)
-rm $(LIB_TARGET)
-rm -rf $(EXAMPLES_BIN_DIR)
libyu: $(LIB_TARGET)
examples: $(EXAMPLES_BIN_DIR) $(EXAMPLES_TARGET)
$(EXAMPLES_BIN_DIR):
mkdir $@
$(LIB_TARGET): $(LIB_OBJ)
$(info making Yu standard library)
$(AR) $@ $^
$(RANLIB) $@
$(EXAMPLES_BIN_DIR)/%: $(EXAMPLES_OBJ_DIR)/%.yu.o $(LIB_TARGET)
$(info making example "$(notdir $@)"...)
$(LD) $< -L$(BUILD_DIR) -lyu -o $@
$(OBJ_DIR)/%.yu.ll: $(TOP_DIR)/%.yu $(YUC_BIN)
$(info YUC $@)
-mkdir -p $(dir $@)
$(YUC) -I $(LIB_DIR) -ot llvm $< > $@
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.ll
$(info LLC $@)
$(LLC) $^ -o $@