about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorAndrea Mattavelli <andreamattavelli@users.noreply.github.com>2017-07-24 16:44:08 +0200
committerGitHub <noreply@github.com>2017-07-24 16:44:08 +0200
commit13b17ee65b7db6af26aa614b7f0318fe2a60fe36 (patch)
tree9d807f21aeb26660b666b7801e57ae4ea0ac1936
parent769bd87658d3445af6770cadb1fe50edea833d15 (diff)
parenta9a310e40cd8f6505464dd595dd28f2987cdbf5c (diff)
downloadklee-13b17ee65b7db6af26aa614b7f0318fe2a60fe36.tar.gz
Merge pull request #721 from delcypher/cmake_runtime_dependency_fixes
A few runtime build system fixes
-rw-r--r--runtime/Makefile.cmake.bitcode.rules36
1 files changed, 31 insertions, 5 deletions
diff --git a/runtime/Makefile.cmake.bitcode.rules b/runtime/Makefile.cmake.bitcode.rules
index 2737eb80..6ad23aed 100644
--- a/runtime/Makefile.cmake.bitcode.rules
+++ b/runtime/Makefile.cmake.bitcode.rules
@@ -81,7 +81,13 @@ endif
 # Compute the directory to put build files
 LOCAL_BUILD_DIR := $(abspath $(ROOT_OBJ)/$(DIR_SUFFIX))
 
-C_SRCS := $(shell echo $(SRC_DIR)/*.c)
+C_SRCS := $(sort $(shell echo $(SRC_DIR)/*.c))
+
+# Sanity check: Make sure at least one source file was found
+ifneq ($(strip $(filter %*.c,$(C_SRCS))),)
+$(error Failed to find C source files in $(SRC_DIR))
+endif
+
 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))
@@ -92,6 +98,12 @@ BC_FILES := $(addprefix $(LOCAL_BUILD_DIR)/,$(BC_FILES_NO_DIR))
 # of all sources
 LLVMCC_FLAGS_FILE := $(LOCAL_BUILD_DIR)/LLVMCC_FLAGS
 
+# Path to file that stores list of bc files that constitute
+# bitcode archive or bitcode module. If the list of bitcode
+# files changes this should trigger a rebuild of the bitcode
+# archive or module
+BC_FILE_LIST_FILE := $(LOCAL_BUILD_DIR)/BC_FILE_LIST
+
 # All bitcode files have these additional dependencies
 $(BC_FILES) : $(ADDITIONAL_BUILD_DEPS) $(LLVMCC_FLAGS_FILE)
 
@@ -114,6 +126,14 @@ $(LLVMCC_FLAGS_FILE): force
 	$(Verb) $(MKDIR) -p "$(dir $(LLVMCC_FLAGS_FILE))"
 	$(Verb)echo "$(LLVMCC_FLAGS_FOR_FILE)" | $(CMP) -s - $@ || echo "$(LLVMCC_FLAGS_FOR_FILE)" > $@
 
+# $(BC_FILE_LIST_FILE) depends on `force` which will force rule to
+# rerun every build. However the rule will only update the file when
+# the list of bc files changes which means we should only trigger a rebuild
+# or the bitcode archive/module when the list of bc files changes
+$(BC_FILE_LIST_FILE): force
+	$(Verb) $(MKDIR) -p "$(dir $(BC_FILE_LIST_FILE))"
+	$(Verb)echo "$(BC_FILES_NO_DIR)" | $(CMP) -s - $@ || echo "$(BC_FILES_NO_DIR)" > $@
+
 clean::
 	@echo "Removing bitcode files"
 	$(Verb) $(RM) -f $(BC_FILES)
@@ -132,10 +152,12 @@ MODULE_FILE := $(MODULE_DEST)/$(MODULE_NAME).bc
 build_at_level:: $(MODULE_FILE)
 
 # Rule for building LLVM bitcode module
-$(MODULE_FILE): $(BC_FILES)
+# NOTE: Dependency on $(BC_FILE_LIST_FILE) is to force
+# rebuild when list of BC_FILES changes.
+$(MODULE_FILE): $(BC_FILES) $(BC_FILE_LIST_FILE)
 	$(Verb) $(MKDIR) -p $(MODULE_DEST)
 	@echo "Creating LLVM module $@"
-	$(Verb)$(LLVM_LINK) -o $@ $^
+	$(Verb)$(LLVM_LINK) -o $@ $(BC_FILES)
 
 clean::
 	@echo "Removing LLVM module $(MODULE_FILE)"
@@ -148,11 +170,13 @@ ARCHIVE_FILE := $(ARCHIVE_DEST)/lib$(ARCHIVE_NAME).bca
 build_at_level:: $(ARCHIVE_FILE)
 
 # Rule for building LLVM bitcode archive
-$(ARCHIVE_FILE): $(BC_FILES)
+# NOTE: Dependency on $(BC_FILE_LIST_FILE) is to force
+# rebuild when list of BC_FILES changes.
+$(ARCHIVE_FILE): $(BC_FILES) $(BC_FILE_LIST_FILE)
 	$(Verb) $(MKDIR) -p $(ARCHIVE_DEST)
 	@echo "Creating LLVM archive $@"
 	$(Verb) $(RM) -f $@
-	$(Verb)$(LLVM_AR) rcs $@ $^
+	$(Verb)$(LLVM_AR) rcs $@ $(BC_FILES)
 
 clean::
 	@echo "Removing LLVM bitcode archive $(ARCHIVE_FILE)"
@@ -170,6 +194,8 @@ debug_vars:
 	@echo "ARCHIVE_FILE := $(ARCHIVE_FILE)"
 	@echo "ASSERTIONS_ENABLED := $(ASSERTIONS_ENABLED)"
 	@echo "BC_FILES := $(BC_FILES)"
+	@echo "BC_FILES_NO_DIR := $(BC_FILES_NO_DIR)"
+	@echo "BC_FILE_LIST_FILE := $(BC_FILE_LIST_FILE)"
 	@echo "BUILD_ROOT := $(BUILD_ROOT)"
 	@echo "C_SRCS := $(C_SRCS)"
 	@echo "CURRENT_DIR := $(CURRENT_DIR)"