<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/92337>92337</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc] incorrect dependencies in overlay mode
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DunskiPhilippe
      </td>
    </tr>
</table>

<pre>
    Hello,
# The problem
**OCCURES** When building llvmorg-18.1.5 tag from sources on linux.

According to [the doc](https://libc.llvm.org/overlay_mode.html), CMake command as simple as
```
cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="libc"  \
 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
 -DCMAKE_BUILD_TYPE=<Debug|Release>                    \  # Select build type
   -DCMAKE_INSTALL_PREFIX=<Your prefix of choice>   
```
should lead to the ability to create an overlay mode for the libc.
We should then be able to build libc with the `ninja libc` command, then to install an overlay  version with the n`inja install-llvmlibc` one.

however, there is no PHONY named 'install-llvmlibc' generated. And so, ninja asks us if we meant `install-llvmlib`, which is not the same thing.

Additionally, if we simply attempt to install libc with the `ninja install-libc` command, ninja wants to install `libc-startup` as dependency to libc.
However, `libc-startup` is supposed to be build only if `LLVM_LIBC_FULL_BUILD` is set to `true`, which is neither the case in overlay mode, nor the default value case
# The solution
>From what I understood during a quick search, the problem would come from the `llvm-project/libc/lib/CMakeLists.txt`  file because a unconditional dependancy is set on a variable named `startup_target` for different custom targets (namely `install-libc` and `install-libc-stripped` )and, all that because the `startup_target` is systematically set to `libc-startup` if libc isn't build for barmetal.
IMO, this dependency should not be set, at least on linux, when building libc in overlay mode.
Heer is a patch this unerequired dependency:
```
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index af7ef2de93dd..dc54648ef2bb 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -60,7 +60,12 @@ if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
   # and install it as part of the libc installation.
   set(startup_target "libc-startup")
 endif()
-
+# We should not depend on libc-startup in overlay mode
+if(NOT ${LLVM_LIBC_FULL_BUILD})
+  # Works at least on linux, but requires more investigations
+  # for other platforms
+ set(startup_target "")
+endif()
 if(LLVM_LIBC_FULL_BUILD)
 set(header_install_target install-libc-headers)
 endif()
```
"Fun fact" being that it makes makes libllvmlibc.a automatically installed with the `ninja install-lib` command .

Thanks for reading
PS: Excuse me for my poor English, I usually speak in French
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMV1tz4rgS_jXipQvKyGDIAw9cdziHXCphzsw8UbLdxtrIkleSk_DvT0mWCSTZ2U1RENtS376vv5aZMfwoEWdkvCDjVY81tlR6tmqkeeYPJRe8rrGXqvw0-4ZCKEKXJFqRaE5oDPsSodYqFVh1N93nfrn8_rh-ai_gR4kS0oaLnMsjCPFSKX3sD6eD4WAMlh2h0KoCoxqdoQElQXDZvA2CQf89zzKl_XargIwXtkTIVUbGK0KnpbW1IfGc0A2hG8HTbOCcDJQ-ErpRL6gFOx0qleOgtJUg9IbQJSxv2TNCpqqKyRyYAcOrWiAwExwnUfj4y6xyywcD50G8VND_A-64_JNBf7Xb_e_2sL6bL3brw8Pj_X_Wy_0TiVeEUhcLoRSAjEPRoL9a3s7_uz4sD8v724ftbv1I4lUmmDy-P_r589NDQheELr6ws_i-3a0O-18Pa-cyXq4wbY5ksnxEgcwgidfwxR8ZLwEcgE8oMLMtOmBPNQbzcHawvXvaz3e7w8PjerP92Tr5pRoNtcaCv4EqICsVz4KrL4tnStWIHASy3AHo0GMpF9ye3GWmkVkEJiFgBQ4rKJT2Kz2grZ0fCMGU9ZxyZgQ6G20Cbim8clv6jSSJpIfIw5BEHdgOfb_fKuDSWCbEpXN4QW24ku-GJEkibyis7jsGdEaVxCuqluoVX1AHJxqBG5AKHr7d3_0CySrMgdD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