gen_msvs_sln.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #!/bin/bash
  2. ##
  3. ## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  4. ##
  5. ## Use of this source code is governed by a BSD-style license
  6. ## that can be found in the LICENSE file in the root of the source
  7. ## tree. An additional intellectual property rights grant can be found
  8. ## in the file PATENTS. All contributing project authors may
  9. ## be found in the AUTHORS file in the root of the source tree.
  10. ##
  11. self=$0
  12. self_basename=${self##*/}
  13. EOL=$'\n'
  14. EOLDOS=$'\r'
  15. show_help() {
  16. cat <<EOF
  17. Usage: ${self_basename} [options] file1 [file2 ...]
  18. This script generates a Visual Studio solution file from a list of project
  19. files.
  20. Options:
  21. --help Print this message
  22. --out=outfile Redirect output to a file
  23. --ver=version Version (7,8,9,10,11,12,14,15) of visual studio to generate for
  24. --target=isa-os-cc Target specifier
  25. EOF
  26. exit 1
  27. }
  28. die() {
  29. echo "${self_basename}: $@" >&2
  30. [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
  31. exit 1
  32. }
  33. die_unknown(){
  34. echo "Unknown option \"$1\"." >&2
  35. echo "See ${self_basename} --help for available options." >&2
  36. [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
  37. exit 1
  38. }
  39. indent1=$'\t'
  40. indent=""
  41. indent_push() {
  42. indent="${indent}${indent1}"
  43. }
  44. indent_pop() {
  45. indent="${indent%${indent1}}"
  46. }
  47. parse_project() {
  48. local file=$1
  49. local name=`grep RootNamespace "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
  50. local guid=`grep ProjectGuid "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
  51. # save the project GUID to a varaible, normalizing to the basename of the
  52. # vcxproj file without the extension
  53. local var
  54. var=${file##*/}
  55. var=${var%%.${sfx}}
  56. eval "${var}_file=\"$1\""
  57. eval "${var}_name=$name"
  58. eval "${var}_guid=$guid"
  59. cur_config_list=`grep -B1 'Label="Configuration"' $file |
  60. grep Condition | cut -d\' -f4`
  61. new_config_list=$(for i in $config_list $cur_config_list; do
  62. echo $i
  63. done | sort | uniq)
  64. if [ "$config_list" != "" ] && [ "$config_list" != "$new_config_list" ]; then
  65. mixed_platforms=1
  66. fi
  67. config_list="$new_config_list"
  68. eval "${var}_config_list=\"$cur_config_list\""
  69. proj_list="${proj_list} ${var}"
  70. }
  71. process_project() {
  72. eval "local file=\${$1_file}"
  73. eval "local name=\${$1_name}"
  74. eval "local guid=\${$1_guid}"
  75. # save the project GUID to a varaible, normalizing to the basename of the
  76. # vcproj file without the extension
  77. local var
  78. var=${file##*/}
  79. var=${var%%.${sfx}}
  80. eval "${var}_guid=$guid"
  81. echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\""
  82. echo "EndProject"
  83. }
  84. process_global() {
  85. echo "Global"
  86. indent_push
  87. #
  88. # Solution Configuration Platforms
  89. #
  90. echo "${indent}GlobalSection(SolutionConfigurationPlatforms) = preSolution"
  91. indent_push
  92. IFS_bak=${IFS}
  93. IFS=$'\r'$'\n'
  94. if [ "$mixed_platforms" != "" ]; then
  95. config_list="
  96. Release|Mixed Platforms
  97. Debug|Mixed Platforms"
  98. fi
  99. for config in ${config_list}; do
  100. echo "${indent}$config = $config"
  101. done
  102. IFS=${IFS_bak}
  103. indent_pop
  104. echo "${indent}EndGlobalSection"
  105. #
  106. # Project Configuration Platforms
  107. #
  108. echo "${indent}GlobalSection(ProjectConfigurationPlatforms) = postSolution"
  109. indent_push
  110. for proj in ${proj_list}; do
  111. eval "local proj_guid=\${${proj}_guid}"
  112. eval "local proj_config_list=\${${proj}_config_list}"
  113. IFS=$'\r'$'\n'
  114. for config in ${proj_config_list}; do
  115. if [ "$mixed_platforms" != "" ]; then
  116. local c=${config%%|*}
  117. echo "${indent}${proj_guid}.${c}|Mixed Platforms.ActiveCfg = ${config}"
  118. echo "${indent}${proj_guid}.${c}|Mixed Platforms.Build.0 = ${config}"
  119. else
  120. echo "${indent}${proj_guid}.${config}.ActiveCfg = ${config}"
  121. echo "${indent}${proj_guid}.${config}.Build.0 = ${config}"
  122. fi
  123. done
  124. IFS=${IFS_bak}
  125. done
  126. indent_pop
  127. echo "${indent}EndGlobalSection"
  128. #
  129. # Solution Properties
  130. #
  131. echo "${indent}GlobalSection(SolutionProperties) = preSolution"
  132. indent_push
  133. echo "${indent}HideSolutionNode = FALSE"
  134. indent_pop
  135. echo "${indent}EndGlobalSection"
  136. indent_pop
  137. echo "EndGlobal"
  138. }
  139. process_makefile() {
  140. IFS_bak=${IFS}
  141. IFS=$'\r'$'\n'
  142. local TAB=$'\t'
  143. cat <<EOF
  144. MSBUILD_TOOL := msbuild.exe
  145. found_devenv := \$(shell which \$(MSBUILD_TOOL) >/dev/null 2>&1 && echo yes)
  146. .nodevenv.once:
  147. ${TAB}@echo " * \$(MSBUILD_TOOL) not found in path."
  148. ${TAB}@echo " * "
  149. ${TAB}@echo " * You will have to build all configurations manually using the"
  150. ${TAB}@echo " * Visual Studio IDE. To allow make to build them automatically,"
  151. ${TAB}@echo " * add the Common7/IDE directory of your Visual Studio"
  152. ${TAB}@echo " * installation to your path, eg:"
  153. ${TAB}@echo " * C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE"
  154. ${TAB}@echo " * "
  155. ${TAB}@touch \$@
  156. CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once)
  157. EOF
  158. for sln_config in ${config_list}; do
  159. local config=${sln_config%%|*}
  160. local platform=${sln_config##*|}
  161. local nows_sln_config=`echo $sln_config | sed -e 's/[^a-zA-Z0-9]/_/g'`
  162. cat <<EOF
  163. BUILD_TARGETS += \$(if \$(NO_LAUNCH_DEVENV),,$nows_sln_config)
  164. clean::
  165. ${TAB}rm -rf "$platform"/"$config"
  166. .PHONY: $nows_sln_config
  167. ifneq (\$(found_devenv),)
  168. $nows_sln_config: $outfile
  169. ${TAB}\$(MSBUILD_TOOL) $outfile -m -t:Build \\
  170. ${TAB}${TAB}-p:Configuration="$config" -p:Platform="$platform"
  171. else
  172. $nows_sln_config: $outfile .nodevenv.once
  173. ${TAB}@echo " * Skipping build of $sln_config (\$(MSBUILD_TOOL) not in path)."
  174. ${TAB}@echo " * "
  175. endif
  176. EOF
  177. done
  178. IFS=${IFS_bak}
  179. }
  180. # Process command line
  181. outfile=/dev/stdout
  182. for opt in "$@"; do
  183. optval="${opt#*=}"
  184. case "$opt" in
  185. --help|-h) show_help
  186. ;;
  187. --out=*) outfile="${optval}"; mkoutfile="${optval}".mk
  188. ;;
  189. --dep=*) eval "${optval%%:*}_deps=\"\${${optval%%:*}_deps} ${optval##*:}\""
  190. ;;
  191. --ver=*) vs_ver="$optval"
  192. case $optval in
  193. 10|11|12|14|15)
  194. ;;
  195. *) die Unrecognized Visual Studio Version in $opt
  196. ;;
  197. esac
  198. ;;
  199. --target=*) target="${optval}"
  200. ;;
  201. -*) die_unknown $opt
  202. ;;
  203. *) file_list[${#file_list[@]}]="$opt"
  204. esac
  205. done
  206. outfile=${outfile:-/dev/stdout}
  207. mkoutfile=${mkoutfile:-/dev/stdout}
  208. case "${vs_ver:-10}" in
  209. 10) sln_vers="11.00"
  210. sln_vers_str="Visual Studio 2010"
  211. ;;
  212. 11) sln_vers="12.00"
  213. sln_vers_str="Visual Studio 2012"
  214. ;;
  215. 12) sln_vers="12.00"
  216. sln_vers_str="Visual Studio 2013"
  217. ;;
  218. 14) sln_vers="12.00"
  219. sln_vers_str="Visual Studio 2015"
  220. ;;
  221. 15) sln_vers="12.00"
  222. sln_vers_str="Visual Studio 2017"
  223. ;;
  224. esac
  225. sfx=vcxproj
  226. for f in "${file_list[@]}"; do
  227. parse_project $f
  228. done
  229. cat >${outfile} <<EOF
  230. Microsoft Visual Studio Solution File, Format Version $sln_vers${EOLDOS}
  231. # $sln_vers_str${EOLDOS}
  232. EOF
  233. for proj in ${proj_list}; do
  234. process_project $proj >>${outfile}
  235. done
  236. process_global >>${outfile}
  237. process_makefile >${mkoutfile}