1# Copyright (c) 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 7BOUNDS_CHECK_DIR := $(abspath ../../../../../third_party/bounds_checking_function) 8INCLUDES = -I$(PWD) -I$(BOUNDS_CHECK_DIR)/include 9 10CODEGEN_SOURCE_DIR := $(PWD)/codegen 11CODEGEN_SOURCE := $(wildcard $(CODEGEN_SOURCE_DIR)/*.cpp) 12CODEGEN_OBJ_DIR := $(BUILD_DIR)/codegen 13CODEGEN_OBJS := $(addprefix $(CODEGEN_OBJ_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(CODEGEN_SOURCE)))) 14 15PARSER_SOURCE_DIR := $(PWD)/parser 16PARSER_SOURCE := $(wildcard $(PARSER_SOURCE_DIR)/*.cpp) 17PARSER_OBJS_DIR := $(BUILD_DIR)/parser 18PARSER_OBJS := $(addprefix $(PARSER_OBJS_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(PARSER_SOURCE)))) 19 20PREPROCESSOR_SOURCE_DIR := $(PWD)/preprocessor 21PREPROCESSOR_SOURCE := $(wildcard $(PREPROCESSOR_SOURCE_DIR)/*.cpp) 22PREPROCESSOR_OBJS_DIR := $(BUILD_DIR)/preprocessor 23PREPROCESSOR_OBJS := $(addprefix $(PREPROCESSOR_OBJS_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(PREPROCESSOR_SOURCE)))) 24 25LEXER_SOURCE_DIR := $(PWD)/lexer 26LEXER_SOURCE := $(wildcard $(LEXER_SOURCE_DIR)/*.cpp) 27LEXER_OBJS_DIR := $(BUILD_DIR)/lexer 28LEXER_OBJS := $(addprefix $(LEXER_OBJS_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(LEXER_SOURCE)))) 29 30AST_SOURCE_DIR := $(PWD)/ast 31AST_SOURCE := $(wildcard $(AST_SOURCE_DIR)/*.cpp) 32AST_OBJS_DIR := $(BUILD_DIR)/ast 33AST_OBJS := $(addprefix $(AST_OBJS_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(AST_SOURCE)))) 34 35HASH_SOURCE_DIR := $(PWD)/hash 36HASH_SOURCE := $(wildcard $(HASH_SOURCE_DIR)/*.cpp) 37HASH_OBJS_DIR := $(BUILD_DIR)/hash 38HASH_OBJS := $(addprefix $(HASH_OBJS_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(HASH_SOURCE)))) 39 40UTIL_SOURCE_DIR := $(PWD)/util 41UTIL_SOURCE := $(wildcard $(UTIL_SOURCE_DIR)/*.cpp) 42UTIL_OBJS_DIR := $(BUILD_DIR)/util 43UTIL_OBJS := $(addprefix $(UTIL_OBJS_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(UTIL_SOURCE)))) 44 45BOUNDS_CHECK_SOURCE_DIR := $(abspath ../../../../../third_party/bounds_checking_function/src) 46BOUNDS_CHECK_SOURCE := $(wildcard $(BOUNDS_CHECK_SOURCE_DIR)/*.c) 47BOUNDS_CHECK_OBJS_DIR := $(BUILD_DIR)/bounds_checking_function 48BOUNDS_CHECK_OBJS := $(addprefix $(BOUNDS_CHECK_OBJS_DIR)/, $(patsubst %.c, %.o, $(notdir $(BOUNDS_CHECK_SOURCE)))) 49 50MAIN_SOURCE := $(wildcard *.cpp) 51MAIN_OBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.cpp, %.o, $(MAIN_SOURCE))) 52 53all:$(TARGET) 54 55$(TARGET) : $(BOUNDS_CHECK_OBJS) $(UTIL_OBJS) $(HASH_OBJS) $(AST_OBJS) $(LEXER_OBJS) $(PREPROCESSOR_OBJS) $(PARSER_OBJS) $(CODEGEN_OBJS) $(MAIN_OBJS) 56 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) $^ -o $@ 57 $(Q) echo $(TARGET):build successful. 58 59$(BUILD_DIR)/%.o : %.cpp 60 $(Q) mkdir -p $(BUILD_DIR) 61 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 62 63$(CODEGEN_OBJ_DIR)/%.o : $(CODEGEN_SOURCE_DIR)/%.cpp 64 $(Q) mkdir -p $(CODEGEN_OBJ_DIR) 65 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 66 67$(PARSER_OBJS_DIR)/%.o : $(PARSER_SOURCE_DIR)/%.cpp 68 $(Q) mkdir -p $(PARSER_OBJS_DIR) 69 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 70 71$(PREPROCESSOR_OBJS_DIR)/%.o : $(PREPROCESSOR_SOURCE_DIR)/%.cpp 72 $(Q) mkdir -p $(PREPROCESSOR_OBJS_DIR) 73 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 74 75$(LEXER_OBJS_DIR)/%.o : $(LEXER_SOURCE_DIR)/%.cpp 76 $(Q) mkdir -p $(LEXER_OBJS_DIR) 77 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 78 79$(AST_OBJS_DIR)/%.o : $(AST_SOURCE_DIR)/%.cpp 80 $(Q) mkdir -p $(AST_OBJS_DIR) 81 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 82 83$(HASH_OBJS_DIR)/%.o : $(HASH_SOURCE_DIR)/%.cpp 84 $(Q) mkdir -p $(HASH_OBJS_DIR) 85 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 86 87$(UTIL_OBJS_DIR)/%.o : $(UTIL_SOURCE_DIR)/%.cpp 88 $(Q) mkdir -p $(UTIL_OBJS_DIR) 89 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 90 91$(BOUNDS_CHECK_OBJS_DIR)/%.o : $(BOUNDS_CHECK_SOURCE_DIR)/%.c 92 $(Q) mkdir -p $(BOUNDS_CHECK_OBJS_DIR) 93 $(Q) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $^ -o $@ 94 95clean: 96 $(Q) rm -rf $(TARGET) $(BUILD_DIR) 97 98.PHONY:all clean