link.bat 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. @echo off
  2. rem tools/link.bat
  3. rem
  4. rem Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
  5. rem Author: Gregory Nutt <gnutt@nuttx.org>
  6. rem
  7. rem Redistribution and use in source and binary forms, with or without
  8. rem modification, are permitted provided that the following conditions
  9. rem are met:
  10. rem
  11. rem 1. Redistributions of source code must retain the above copyright
  12. rem notice, this list of conditions and the following disclaimer.
  13. rem 2. Redistributions in binary form must reproduce the above copyright
  14. rem notice, this list of conditions and the following disclaimer in
  15. rem the documentation and/or other materials provided with the
  16. rem distribution.
  17. rem 3. Neither the name NuttX nor the names of its contributors may be
  18. rem used to endorse or promote products derived from this software
  19. rem without specific prior written permission.
  20. rem
  21. rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. rem POSSIBILITY OF SUCH DAMAGE.
  33. rem
  34. set usemklink=
  35. if "%1"=="-m" (
  36. set usemklink="y"
  37. shift
  38. )
  39. set src=%1
  40. set link=%2
  41. rem Verify that arguments were provided
  42. if "%src%"=="" goto :MissingSrc
  43. if "%link%"=="" goto :MissingLink
  44. goto CheckSrc
  45. :MissingSrc
  46. echo Missing ^<src^> and ^<link^> arguments
  47. goto :ShowUsage
  48. :MissingLink
  49. echo Missing ^<link^> arguments
  50. goto :ShowUsage
  51. rem Verify that a directory exists at the source path
  52. :CheckSrc
  53. if exist %src% goto :CheckLink
  54. echo No directory at %src%
  55. goto :ShowUsage
  56. :CheckLink
  57. rem If something already exists at the destination path, remove it
  58. if not exist %link% goto :MkLink
  59. rmdir /q /s %link%
  60. if errorlevel 1 (
  61. echo Failed to remove existing object at %link%
  62. goto :ShowUsage
  63. )
  64. rem Copy the directory
  65. :MkLink
  66. if "%usemklink%"=="y" (
  67. /user:administrator mklink /d %src% %link%
  68. goto :End
  69. )
  70. rem %src% may include forward slashes. That upsets xcopy, but not GNUWin32 cp
  71. rem xcopy %src% %link% /c /q /s /e /y /i
  72. cp -dR %src% %link%
  73. echo FAKELNK > %link%\.fakelnk
  74. goto :End
  75. :ShowUsage
  76. echo USAGE: %0 ^<src^> ^<link^>
  77. echo Where:
  78. echo ^<src^> is the source directory to be linked
  79. echo ^<link^> is the link to be created
  80. :End