diff options
Diffstat (limited to 'runtime/Makefile.cmake.bitcode.rules')
-rw-r--r-- | runtime/Makefile.cmake.bitcode.rules | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/runtime/Makefile.cmake.bitcode.rules b/runtime/Makefile.cmake.bitcode.rules new file mode 100644 index 00000000..85151e2f --- /dev/null +++ b/runtime/Makefile.cmake.bitcode.rules @@ -0,0 +1,163 @@ +#===--------------------------------------------------------*- Makefile -*--===# +# +# The KLEE Symbolic Virtual Machine +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# +# This files defines the rules used for the bitcode build system. They are +# inspired by LLVM's old Makefile build system. +#===------------------------------------------------------------------------===# +.PHONY: all build_at_level clean debug_vars + +CURRENT_DIR:= $(shell pwd) + +# Sanity checks +ifndef LEVEL + $(error LEVEL must be defined) +endif + +ifndef LLVMCC + $(error Makefile.cmake.bitconfig.config must be included) +endif + +# Any changes to the files listed here will trigger a rebuild of the sources +ADDITIONAL_BUILD_DEPS := $(CURRENT_DIR)/Makefile.cmake.bitcode \ + $(RUNTIME_CMAKE_BINARY_DIR)/Makefile.cmake.bitcode.config \ + $(RUNTIME_CMAKE_BINARY_DIR)/Makefile.cmake.bitcode + +# Handle VERBOSE +VERBOSE ?= 0 +ifneq ($(VERBOSE),0) + Verb := +else + Verb := @ +endif +# +# Handle build mode flags +ifeq ($(IS_RELEASE),1) +LLVMCC.Flags += -O2 +else +LLVMCC.Flags += -O0 +endif + +# Handle assertion flags +ifeq ($(ASSERTIONS_ENABLED),0) +LLVMCC.Flags += -DNDEBUG +endif + +# Handle debug symbol flags +ifneq ($(DEBUG_SYMBOLS_ENABLED),0) +LLVMCC.Flags += -g +endif + +ifdef DIRS +# all directory recursion target +all:: + $(Verb) for dir in $(DIRS); do \ + ($(MAKE) -C $$dir -f Makefile.cmake.bitcode) || exit 1; \ + done + +clean:: + $(Verb) for dir in $(DIRS); do \ + ($(MAKE) -C $$dir -f Makefile.cmake.bitcode $@) || exit 1; \ + done +else +# Build sources + +all:: build_at_level + +# Compute the directory to find sources +DIR_SUFFIX := $(subst $(RUNTIME_CMAKE_BINARY_DIR),,$(CURRENT_DIR)) +SRC_DIR := $(abspath $(ROOT_SRC)/$(DIR_SUFFIX)) +LOCAL_BUILD_DIR := $(abspath $(ROOT_OBJ)/$(DIR_SUFFIX)) + +C_SRCS := $(shell echo $(SRC_DIR)/*.c) +C_SRCS_NO_DIR := $(notdir $(C_SRCS)) +BC_FILES_NO_DIR := $(C_SRCS_NO_DIR:.c=.bc) +BC_FILES := $(addprefix $(LOCAL_BUILD_DIR)/,$(BC_FILES_NO_DIR)) + +# All bitcode files have these additional dependencies +$(BC_FILES) : $(ADDITIONAL_BUILD_DEPS) + +# Include dependency information generated by previous +# compiler invocations if they exist +-include $(BC_FILES:.bc=.dep) + +# Pattern rule to build bitcode files +$(LOCAL_BUILD_DIR)/%.bc : $(SRC_DIR)/%.c + @echo "LLVMCC ($(RUNTIME_CONFIG_STRING)) $<" + $(Verb) $(MKDIR) -p $(LOCAL_BUILD_DIR) + $(Verb) $(LLVMCC) $(LLVMCC.Flags) $(LLVMCC.Warnings) $< -c -o $@ -MP -MMD -MF $(LOCAL_BUILD_DIR)/$*.dep + +clean:: + @echo "Removing bitcode files" + $(Verb) $(RM) -f $(BC_FILES) + @echo "Removing dependency files" + $(Verb) $(RM) -f $(BC_FILES:.bc=.dep) + + +ifndef MODULE_NAME +ifndef ARCHIVE_NAME +$(error MODULE_NAME or ARCHIVE_NAME must be defined) +endif +endif + +ifdef MODULE_NAME +MODULE_FILE := $(MODULE_DEST)/$(MODULE_NAME).bc +build_at_level:: $(MODULE_FILE) + +# Rule for building LLVM bitcode module +$(MODULE_FILE): $(BC_FILES) + $(Verb) $(MKDIR) -p $(MODULE_DEST) + @echo "Creating LLVM module $@" + $(Verb)$(LLVM_LINK) -o $@ $^ + +clean:: + @echo "Removing LLVM module $(MODULE_FILE)" + $(Verb) $(RM) -f $(MODULE_FILE) +endif # MODULE_NAME + +ifdef ARCHIVE_NAME +ARCHIVE_FILE := $(ARCHIVE_DEST)/lib$(ARCHIVE_NAME).bca + +build_at_level:: $(ARCHIVE_FILE) + +# Rule for building LLVM bitcode archive +$(ARCHIVE_FILE): $(BC_FILES) + $(Verb) $(MKDIR) -p $(ARCHIVE_DEST) + @echo "Creating LLVM archive $@" + $(Verb) $(RM) -f $@ + $(Verb)$(LLVM_AR) rcs $@ $^ + +clean:: + @echo "Removing LLVM bitcode archive $(ARCHIVE_FILE)" + $(Verb) $(RM) -f $(ARCHIVE_FILE) + +endif # ARCHIVE_NAME + + +endif # end not ifdef DIRS + +debug_vars: + @echo "********************************************************************************" + @echo "Makefile variables for debugging" + @echo "********************************************************************************" + @echo "ARCHIVE_FILE := $(ARCHIVE_FILE)" + @echo "ASSERTIONS_ENABLED := $(ASSERTIONS_ENABLED)" + @echo "BC_FILES := $(BC_FILES)" + @echo "BUILD_ROOT := $(BUILD_ROOT)" + @echo "C_SRCS := $(C_SRCS)" + @echo "CURRENT_DIR := $(CURRENT_DIR)" + @echo "DEBUG_SYMBOLS_ENABLED := $(DEBUG_SYMBOLS_ENABLED)" + @echo "IS_RELEASE := $(IS_RELEASE)" + @echo "LOCAL_BUILD_DIR := $(LOCAL_BUILD_DIR)" + @echo "LLVMCC := $(LLVMCC)" + @echo "LLVMCC.Flag := $(LLVMCC.Flags)" + @echo "LLVMCC.Warnings := $(LLVMCC.Warnings)" + @echo "MODULE_FILE := $(MODULE_FILE)" + @echo "ROOT_OBJ := $(ROOT_OBJ)" + @echo "RUNTIME_CONFIG_STRING := $(RUNTIME_CONFIG_STRING)" + @echo "SRC_DIR := $(SRC_DIR)" + @echo "VERBOSE := $(VERBOSE)" |