From 6c249a820605f4e2f998d5849b5be1005bf480e3 Mon Sep 17 00:00:00 2001
From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Date: Sat, 17 Jan 2015 17:58:25 -0800
Subject: [PATCH 1004/1012] MacPorts Only: Relocate clang resources using llvm
 version

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 0111fcf6f32dfeb41ae0b1e9be0258b899d97200)
---
 lib/Headers/Makefile         |  3 ++-
 runtime/compiler-rt/Makefile | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git llvm_release_34/tools/clang/lib/Headers/Makefile macports_release_34/tools/clang/lib/Headers/Makefile
index 42219c4..69ca986 100644
--- llvm_release_34/tools/clang/lib/Headers/Makefile
+++ macports_release_34/tools/clang/lib/Headers/Makefile
@@ -16,6 +16,7 @@ include $(CLANG_LEVEL)/Makefile
 
 CLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \
 	$(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc))
+LLVM_VERSION := $(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)
 
 HeaderDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)/include
 
@@ -40,7 +41,7 @@ $(HeaderDir)/module.map: $(PROJ_SRC_DIR)/module.map $(HeaderDir)/.dir
 # Hook into the standard Makefile rules.
 all-local:: $(OBJHEADERS) $(HeaderDir)/module.map
 
-PROJ_headers := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION)/include
+PROJ_headers := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(LLVM_VERSION)/include
 
 INSTHEADERS := $(addprefix $(PROJ_headers)/, $(HEADERS))
 INSTHEADERS += $(PROJ_headers)/arm_neon.h
diff --git llvm_release_34/tools/clang/runtime/compiler-rt/Makefile macports_release_34/tools/clang/runtime/compiler-rt/Makefile
index 273e482..3ecee5c 100644
--- llvm_release_34/tools/clang/runtime/compiler-rt/Makefile
+++ macports_release_34/tools/clang/runtime/compiler-rt/Makefile
@@ -18,9 +18,10 @@ include $(CLANG_LEVEL)/Makefile
 
 CLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \
 	$(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc))
+LLVM_VERSION := $(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)
 
 ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)
-PROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION)
+PROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(LLVM_VERSION)
 
 ResourceLibDir := $(ResourceDir)/lib
 ResourceIncludeDir := $(ResourceDir)/include
@@ -256,9 +257,21 @@ $(PROJ_resources_include)/sanitizer: $(ResourceIncludeDir)/sanitizer $(PROJ_reso
 RuntimeHeaderInstall: $(PROJ_resources_include)/sanitizer
 .PHONY: RuntimeHeaderInstall
 
+# Make sure $(PROJ_resources) exists before creating the symlink.
+$(PROJ_resources:$(LLVM_VERSION)=$(CLANG_VERSION)):
+	$(Echo) Creating compiler runtime compatibility symlink
+	$(Verb) $(MKDIR) $(dir $@)
+	$(Verb) ln -s $(LLVM_VERSION) $@
+
+MacPortsClangResSymlinkInstall: $(PROJ_resources:$(LLVM_VERSION)=$(CLANG_VERSION))
+.PHONY: MacPortsClangResSymlinkInstall
+
 # Hook into the standard Makefile rules.
 all-local:: $(RuntimeDirs:%=RuntimeLibrary.%) RuntimeHeader
 install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) RuntimeHeaderInstall
+ifneq ($(LLVM_VERSION),$(CLANG_VERSION))
+install-local:: MacPortsClangResSymlinkInstall
+endif
 clean-local:: CleanRuntimeLibraries
 
 endif
-- 
2.10.1

