biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / stdenv / cygwin / wrap-exes-to-find-dlls.sh
blobd0da8c1b65c25cc73c2bce119775d71fd97375b1
1 postFixupHooks+=(_cygwinWrapExesToFindDlls)
3 _cygwinWrapExesToFindDlls() {
4 find $out -type l | while read LINK; do
5 TARGET="$(readlink "${LINK}")"
7 # fix all non .exe links that link explicitly to a .exe
8 if [[ ${TARGET} == *.exe ]] && [[ ${LINK} != *.exe ]]; then
9 mv "${LINK}" "${LINK}.exe"
10 LINK="${LINK}.exe"
13 # generate complementary filenames
14 if [[ ${LINK} == *.exe ]]; then
15 _LINK="${LINK%.exe}"
16 _TARGET="${TARGET%.exe}"
17 else
18 _LINK="${LINK}.exe"
19 _TARGET="${TARGET}.exe"
22 # check if sould create complementary link
23 DOLINK=1
24 if [[ ${_TARGET} == *.exe ]]; then
25 # the canonical target has to be a .exe
26 CTARGET="$(readlink -f "${LINK}")"
27 if [[ ${CTARGET} != *.exe ]]; then
28 CTARGET="${CTARGET}.exe"
31 if [ ! -e "${CTARGET}" ]; then
32 unset DOLINK
36 if [ -e "${_LINK}" ]; then
37 # complementary link seems to exist
38 # but could be cygwin smoke and mirrors
39 INO=$(stat -c%i "${LINK}")
40 _INO=$(stat -c%i "${_LINK}")
41 if [ "${INO}" -ne "${_INO}" ]; then
42 unset DOLINK
46 # create complementary link
47 if [ -n "${DOLINK}" ]; then
48 ln -s "${_TARGET}" "${_LINK}.tmp"
49 mv "${_LINK}.tmp" "${_LINK}"
51 done
53 find $out -type f -name "*.exe" | while read EXE; do
54 WRAPPER="${EXE%.exe}"
55 if [ -e "${WRAPPER}" ]; then
56 # check if really exists or cygwin smoke and mirrors
57 INO=$(stat -c%i "${EXE}")
58 _INO=$(stat -c%i "${WRAPPER}")
59 if [ "${INO}" -ne "${_INO}" ]; then
60 continue
64 mv "${EXE}" "${EXE}.tmp"
66 cat >"${WRAPPER}" <<EOF
67 #!/bin/sh
68 export PATH=$_PATH${_PATH:+:}\${PATH}
69 exec "\$0.exe" "\$@"
70 EOF
71 chmod +x "${WRAPPER}"
72 mv "${EXE}.tmp" "${EXE}"
73 done