1CC      = $(CROSS_COMPILE)gcc
2LD      = $(CROSS_COMPILE)ld
3AR      = $(CROSS_COMPILE)ar
4NM      = $(CROSS_COMPILE)nm
5OBJCOPY = $(CROSS_COMPILE)objcopy
6OBJDUMP = $(CROSS_COMPILE)objdump
7READELF = $(CROSS_COMPILE)readelf
8O      ?= $(CURDIR)/out
9OUT_DIR = $(O)
10
11.PHONY: all
12all: libyaml benchmark
13
14.PHONY: clean
15################################################################################
16# libYAML
17################################################################################
18LIBYAML_FLAGS ?= CROSS_COMPILE=$(CROSS_COMPILE)
19LIBYAML_SRC_DIR = $(CURDIR)/libyaml
20LIBYAML_OUT_DIR = $(OUT_DIR)/libyaml/out
21
22.PHONY: libyaml
23libyaml:
24	$(AT)test -d $(LIBYAML_OUT_DIR) || mkdir -p $(LIBYAML_OUT_DIR)
25	cd $(LIBYAML_SRC_DIR) && ./bootstrap && \
26	./configure --host=$(MULTIARCH) \
27	--prefix=$(LIBYAML_OUT_DIR) CC=$(CC) && \
28	$(MAKE) && $(MAKE) install
29
30.PHONY: libyaml-clean
31libyaml-clean:
32	cd $(LIBYAML_SRC_DIR) && \
33	$(MAKE) clean
34
35################################################################################
36# benchmark_app
37################################################################################
38SRCS := main.c benchmark_aux.c
39OBJS := $(patsubst %.c,$(OUT_DIR)/%.o, $(SRCS))
40
41CFLAGS += -Wall -Wextra -Werror -I$(TEEC_EXPORT)/include \
42		  -I$(TEEC_INTERNAL_INCLUDES)/include -I$(LIBYAML_OUT_DIR)/include
43#Add/link other required libraries here
44LDADD += -lm -lteec -lyaml -lpthread \
45		 -L$(TEEC_EXPORT)/lib -L$(LIBYAML_OUT_DIR)/lib
46$(OBJS) : libyaml
47
48benchmark: $(OUT_DIR)/benchmark
49
50$(OUT_DIR)/%.o: %.c
51	$(AT)test -d $(OUT_DIR) || mkdir -p $(OUT_DIR)
52	$(CC) $(CFLAGS) -c $< -o $@
53
54$(OUT_DIR)/benchmark: $(OBJS)
55	$(CC) $(LDADD) -o $@ $^
56
57clean: libyaml-clean
58	rm -rf $(OUT_DIR)