From d480bbdcac279f12f0037789401d4355f265eaea Mon Sep 17 00:00:00 2001
From: Willi Mutschler <willi@mutschler.eu>
Date: Tue, 26 Sep 2023 11:56:03 +0200
Subject: [PATCH] manual: workaround if MATLAB does not see Xcode license
 agreement

because MATLAB checks the directory of Xcode and not of the Command Line Tools
---
 doc/manual/source/installation-and-configuration.rst | 9 ++++++++-
 macOS/conclusion_template.html                       | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/doc/manual/source/installation-and-configuration.rst b/doc/manual/source/installation-and-configuration.rst
index f798b472f3..056577d843 100644
--- a/doc/manual/source/installation-and-configuration.rst
+++ b/doc/manual/source/installation-and-configuration.rst
@@ -180,8 +180,15 @@ Dynare now ships a compilation environment that can be used with the
 :opt:`use_dll` option. To install this environment correctly, the Dynare
 installer ensures that the Xcode Command Line Tools (an Apple product) have
 been installed on a system folder. To install the Xcode Command Line Tools
-yourself, simply type ``xcode-select --install`` into the Terminal
+yourself, simply type ``xcode-select --install`` into the terminal
 (``/Applications/Utilities/Terminal.app``) prompt.
+Additionally, to make MATLAB aware that you agree to the terms of Xcode, run the following two commands in the Terminal prompt::
+
+  CLT_VERSION=$(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep versions | awk '{print $2}' | cut -d'.' -f1-2)
+  defaults write com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense "${CLT_VERSION}"
+  defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense
+
+Otherwise you will see a warning that Xcode is installed, but its license has not been accepted.
 
 We recommend making use of optimized compilation flags when using :opt:`use_dll` and for this you need to install gcc via Homebrew_::
   brew install gcc
diff --git a/macOS/conclusion_template.html b/macOS/conclusion_template.html
index 8858a68137..25aa2721a5 100644
--- a/macOS/conclusion_template.html
+++ b/macOS/conclusion_template.html
@@ -31,6 +31,7 @@
       <code>
       xcode-select --install
       </code>
+      <p>If you get a warning in MATLAB, that Xcode is installed, but its license has not been accepted, please refer to the <a href="https://www.dynare.org/manual/installation-and-configuration.html#prerequisites-on-macos" target="_blank" rel="noopener noreferrer">manual</a> for a workaround.</p>
 
       <p class="bold-text">Compilation Environment for use_dll option</p>
       <p>Dynare ships a compilation environment that can be used with the use_dll option. To install this environment correctly, the Xcode Command Line Tools are sufficient.</p>
-- 
GitLab