• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
2#
3# HDF is dual licensed: you can use it either under the terms of
4# the GPL, or the BSD license, at your option.
5# See the LICENSE file in the root of this repository for complete details.
6
7TARGET := hc-gen
8YACC_LEX_PREFIX :=HcsCompiler
9C_FLAGS := -std=gnu99 -Wall -Werror -Wno-attributes -Wall
10CC := gcc
11YACC := bison
12LEX := flex
13Q = @
14
15BOUNDS_CHECK_LIB := $(abspath ../../../../third_party/bounds_checking_function/)
16INCLUDE_DIR := ./include $(BOUNDS_CHECK_LIB)/include
17OUT_DIR := build
18
19TEST_CASE := $(abspath ../../../adapter/lite/khdf/test/tools/hc-gen/test/unittest)
20
21ORIGIN_SOURCES := $(wildcard src/*)
22ORIGIN_SOURCES += $(wildcard $(BOUNDS_CHECK_LIB)/src/*)
23
24C_SOURCES := $(filter %.c,$(ORIGIN_SOURCES))
25YACC_SOURCES := $(filter %.y,$(ORIGIN_SOURCES))
26LEX_SOURCES := $(filter %.l,$(ORIGIN_SOURCES))
27YACC_GEN_SOURCES := $(patsubst %.y,$(OUT_DIR)/%_tab.c,$(YACC_SOURCES))
28LEX_GEN_SOURCES := $(patsubst %.l,$(OUT_DIR)/%_lex.c,$(LEX_SOURCES))
29
30C_OBJECTS := $(patsubst %.c,$(OUT_DIR)/%.o,$(C_SOURCES))
31GEN_OBJECTS +=  $(patsubst %.c,%.o,$(YACC_GEN_SOURCES) $(LEX_GEN_SOURCES))
32OBJECTS :=  $(GEN_OBJECTS) $(C_OBJECTS)
33
34C_FLAGS += $(addprefix -I,$(INCLUDE_DIR))
35INCLUDE_DIR += $(OUT_DIR)
36
37UNAME := $(shell uname -a)
38ifneq ($(findstring Linux,$(UNAME)),)
39    C_FLAGS += -D OS_LINUX
40else
41    C_FLAGS += -D OS_WIN
42    C_FLAGS += -D MINGW32
43endif
44
45ifeq ($(BUILD_TYPE),debug)
46	C_FLAGS += -g
47else ifeq ($(BUILD_TYPE),asan)
48	C_FLAGS += -g -fsanitize=address
49else
50	# release
51	C_FLAGS += -O2 -s -ffunction-sections -fdata-sections -Wl,--gc-sections
52endif
53
54all: $(TARGET)
55
56$(YACC_GEN_SOURCES) : $(OUT_DIR)/%_tab.c : %.y
57	$(Q)mkdir -p $(dir $(@))
58	$(Q)$(YACC) -o $@ -v -d -pHcsCompiler $<
59
60$(LEX_GEN_SOURCES) : $(OUT_DIR)/%_lex.c : %.l | $(YACC_GEN_SOURCES)
61	$(Q)mkdir -p $(dir $(@))
62	$(Q)$(LEX) -o $@ -PHcsCompiler $<
63
64$(C_OBJECTS) : $(OUT_DIR)/%.o : %.c
65	$(Q)mkdir -p $(dir $(@))
66	$(Q)$(CC) -c -o $@ $(C_FLAGS) $^
67
68$(GEN_OBJECTS) : %.o : %.c
69	$(Q)$(CC) -c -o $@ $(C_FLAGS) $^
70
71$(TARGET) : $(OBJECTS) | $(GEN_OBJECTS)
72	$(Q)$(CC) -o $@ $(C_FLAGS) $^
73
74test: all
75	python3 $(TEST_CASE)/hcgen_test.py $(TARGET)
76
77test_update: all
78	python3 $(TEST_CASE)/update_case.py $(TARGET)
79
80clean:
81	$(Q)rm -rf $(OUT_DIR)
82	$(Q)rm -f $(TARGET)
83
84.PHONY: clean all test test_update
85