Index: share/mk/bsd.links.mk =================================================================== --- share/mk/bsd.links.mk +++ share/mk/bsd.links.mk @@ -15,7 +15,16 @@ .ORDER: realinstall _installlinks _installlinks: .for s t in ${LINKS} + # Don't delete the source file on a case-insensitive file-system and pass -S + # to install to avoid overwriting the source +.if ${s:tl} == ${t:tl} + if test "${DESTDIR}${t}" -ef "${DESTDIR}${s}"; then \ + echo "Note: installing link from ${l} to ${t} on case-insensitive file system."; \ + fi + ${INSTALL_LINK} -S ${TAG_ARGS} ${DESTDIR}${s} ${DESTDIR}${t} +.else ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}${s} ${DESTDIR}${t} +.endif .endfor .for s t in ${SYMLINKS} ${INSTALL_SYMLINK} ${TAG_ARGS} ${s} ${DESTDIR}${t} Index: share/mk/bsd.man.mk =================================================================== --- share/mk/bsd.man.mk +++ share/mk/bsd.man.mk @@ -226,8 +226,19 @@ .endif # ${MK_MANCOMPRESS} == "no" .endif .for l t in ${_MANLINKS} +.if ${l:tl} == ${t:tl} + # Don't delete the source file on a case-insensitive file-system and pass -S + # to install to avoid overwriting the source + if test "${DESTDIR}${l}${ZEXT}" -ef "${DESTDIR}${t}${ZEXT}"; then \ + echo "Note: installing man link from ${l} to ${t} on case-insensitive file system."; \ + else \ + rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \ + fi + ${INSTALL_MANLINK} -S ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT} +.else rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \ ${INSTALL_MANLINK} ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT} +.endif .endfor manlint: Index: tools/install.sh =================================================================== --- tools/install.sh +++ tools/install.sh @@ -62,6 +62,14 @@ # the remaining arguments are assumed to be files/dirs only. if [ -n "${linkmode}" ]; then + # Don't delete the source file on a case insensitive file system since + # `ln -f` will remove the file first and then attempt to create the link + src_lower=$(echo "$1" | awk '{print tolower($0)}') + target_lower=$(echo "$2" | awk '{print tolower($0)}') + if [ "$src_lower" = "$target_lower" ] && test "$1" -ef "$2"; then + echo "$0: not creating link from $1 to $2 on case-insensitive file system." >&2 + exit 0 + fi if [ "${linkmode}" = "symbolic" ]; then ln -fsn "$@" else