.bash_helpers.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. # Copyright (c) 2008-2013 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Define helpers
  23. msg() {
  24. echo -e "\n$1\n================================================================================"
  25. }
  26. post_cmake() {
  27. # Check if xmlstarlet software package is available for fixing the generated Eclipse project setting
  28. if [ $HAS_XMLSTARLET ]; then
  29. # Common fixes for all builds
  30. #
  31. # Remove build type from project name
  32. # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
  33. #
  34. xmlstarlet ed -P -L \
  35. -u "/projectDescription/name/text()" -x "concat(substring-before(., '-Release'), substring-before(., '-Debug'), substring-before(., '-RelWithDebInfo'))" \
  36. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.core.errorOutputParser']" -x "concat('org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;', substring-after(., 'org.eclipse.cdt.core.MakeErrorParser'))" \
  37. $1/.project
  38. # Build-specific fixes
  39. if [ $1 == "android-Build" ]; then
  40. # For Android build, add the Android and Java nature to the project setting as it would be done by Eclipse during project import
  41. # This fix avoids the step to reimport the project everytime the Eclipse project setting is regenerated by cmake_gcc.sh invocation
  42. echo -- Add Android and Java nature to Eclipse project setting files in $( pwd )/$1
  43. #
  44. # Add natures (Android nature must be inserted as first nature)
  45. #
  46. xmlstarlet ed -P -L \
  47. -i "/projectDescription/natures/nature[1]" -t elem -n nature -v "com.android.ide.eclipse.adt.AndroidNature" \
  48. -s "/projectDescription/natures" -t elem -n nature -v "org.eclipse.jdt.core.javanature" \
  49. $1/.project
  50. #
  51. # Add build commands
  52. #
  53. for c in com.android.ide.eclipse.adt.ResourceManagerBuilder com.android.ide.eclipse.adt.PreCompilerBuilder org.eclipse.jdt.core.javabuilder com.android.ide.eclipse.adt.ApkBuilder; do
  54. xmlstarlet ed -P -L \
  55. -s "/projectDescription/buildSpec" -t elem -n buildCommandNew -v "" \
  56. -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n name -v $c \
  57. -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n arguments -v "" \
  58. -r "/projectDescription/buildSpec/buildCommandNew" -v "buildCommand" \
  59. $1/.project
  60. done
  61. elif [ $1 == "raspi-Build" ]; then
  62. # For Raspberry Pi build, add [Bin-CC] linked resource
  63. #
  64. # Replace [Subprojects]/Urho3D linked resource to [Targets]/[Bin-CC] instead
  65. #
  66. xmlstarlet ed -P -L \
  67. -u "/projectDescription/linkedResources/link/name/text()[. = '[Subprojects]/Urho3D']" -v "[Targets]/[Bin-CC]" \
  68. -u "/projectDescription/linkedResources/link/location[../name/text() = '[Targets]/[Bin-CC]']" -v "$( pwd )/Bin-CC" \
  69. $1/.project
  70. else
  71. # For native build, move the Eclipse project setting files back to Source folder to fix source code versioning
  72. echo -- Eclipse project setting files have been relocated to: $( pwd )/Source
  73. for f in .project .cproject; do mv $1/$f Source; done
  74. #
  75. # Replace [Source directory] linked resource to [Build] instead
  76. # Modify build argument to first change directory to Build folder
  77. # Replace [Subprojects]/Urho3D linked resource to [Build]/[Bin] instead
  78. #
  79. xmlstarlet ed -P -L \
  80. -u "/projectDescription/linkedResources/link/name/text()[. = '[Source directory]']" -v "[Build]" \
  81. -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]']" -v "$( pwd )/$1" \
  82. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.make.core.build.arguments']" -x "concat('-C ../$1 ', .)" \
  83. -u "/projectDescription/linkedResources/link/name/text()[. = '[Subprojects]/Urho3D']" -v "[Build]/[Bin]" \
  84. -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]/[Bin]']" -v "$( pwd )/Bin" \
  85. Source/.project
  86. #
  87. # Fix source path entry to Source folder and modify its filter condition
  88. # Fix output path entry to [Build] linked resource and modify its filter condition
  89. #
  90. xmlstarlet ed -P -L \
  91. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']/@path" -v "" \
  92. -s "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']" -t attr -n "excluding" -v "[Subprojects]/|[Targets]/" \
  93. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@path" -v "[Build]" \
  94. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@excluding" -x "substring-after(., '[Source directory]/|')" \
  95. Source/.cproject
  96. fi
  97. fi
  98. }
  99. # vi: set ts=4 sw=4 expandtab: