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 12 13self=$0 14self_basename=${self##*/} 15EOL=$'\n' 16EOLDOS=$'\r' 17 18show_help() { 19 cat <<EOF 20Usage: ${self_basename} [options] file1 [file2 ...] 21 22This script generates a Visual Studio 2005 solution file from a list of project 23files. 24 25Options: 26 --help Print this message 27 --out=outfile Redirect output to a file 28 --ver=version Version (7,8,9) of visual studio to generate for 29 --target=isa-os-cc Target specifier 30EOF 31 exit 1 32} 33 34die() { 35 echo "${self_basename}: $@" >&2 36 [ -f "${outfile}" ] && rm -f ${outfile}{,.mk} 37 exit 1 38} 39 40die_unknown(){ 41 echo "Unknown option \"$1\"." >&2 42 echo "See ${self_basename} --help for available options." >&2 43 [ -f "${outfile}" ] && rm -f ${outfile}{,.mk} 44 exit 1 45} 46 47indent1=$'\t' 48indent="" 49indent_push() { 50 indent="${indent}${indent1}" 51} 52indent_pop() { 53 indent="${indent%${indent1}}" 54} 55 56parse_project() { 57 local file=$1 58 local name=`grep Name "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'` 59 local guid=`grep ProjectGUID "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'` 60 61 # save the project GUID to a varaible, normalizing to the basename of the 62 # vcproj file without the extension 63 local var 64 var=${file##*/} 65 var=${var%%.vcproj} 66 eval "${var}_file=\"$1\"" 67 eval "${var}_name=$name" 68 eval "${var}_guid=$guid" 69 70 # assume that all projects have the same list of possible configurations, 71 # so overwriting old config_lists is not a problem 72 config_list=`grep -A1 '<Configuration' $file | 73 grep Name | cut -d\" -f2` 74 proj_list="${proj_list} ${var}" 75} 76 77process_project() { 78 eval "local file=\${$1_file}" 79 eval "local name=\${$1_name}" 80 eval "local guid=\${$1_guid}" 81 82 # save the project GUID to a varaible, normalizing to the basename of the 83 # vcproj file without the extension 84 local var 85 var=${file##*/} 86 var=${var%%.vcproj} 87 eval "${var}_guid=$guid" 88 89 echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\"" 90 indent_push 91 92 eval "local deps=\"\${${var}_deps}\"" 93 if [ -n "$deps" ]; then 94 echo "${indent}ProjectSection(ProjectDependencies) = postProject" 95 indent_push 96 97 for dep in $deps; do 98 eval "local dep_guid=\${${dep}_guid}" 99 [ -z "${dep_guid}" ] && die "Unknown GUID for $dep (dependency of $var)" 100 echo "${indent}$dep_guid = $dep_guid" 101 done 102 103 indent_pop 104 echo "${indent}EndProjectSection" 105 106 fi 107 108 indent_pop 109 echo "EndProject" 110} 111 112process_global() { 113 echo "Global" 114 indent_push 115 116 # 117 # Solution Configuration Platforms 118 # 119 echo "${indent}GlobalSection(SolutionConfigurationPlatforms) = preSolution" 120 indent_push 121 IFS_bak=${IFS} 122 IFS=$'\r'$'\n' 123 for config in ${config_list}; do 124 echo "${indent}$config = $config" 125 done 126 IFS=${IFS_bak} 127 indent_pop 128 echo "${indent}EndGlobalSection" 129 130 # 131 # Project Configuration Platforms 132 # 133 echo "${indent}GlobalSection(ProjectConfigurationPlatforms) = postSolution" 134 indent_push 135 for proj in ${proj_list}; do 136 eval "local proj_guid=\${${proj}_guid}" 137 IFS=$'\r'$'\n' 138 for config in ${config_list}; do 139 echo "${indent}${proj_guid}.${config}.ActiveCfg = ${config}" 140 echo "${indent}${proj_guid}.${config}.Build.0 = ${config}" 141 142 done 143 IFS=${IFS_bak} 144 done 145 indent_pop 146 echo "${indent}EndGlobalSection" 147 148 # 149 # Solution Properties 150 # 151 echo "${indent}GlobalSection(SolutionProperties) = preSolution" 152 indent_push 153 echo "${indent}HideSolutionNode = FALSE" 154 indent_pop 155 echo "${indent}EndGlobalSection" 156 157 indent_pop 158 echo "EndGlobal" 159} 160 161process_makefile() { 162 IFS_bak=${IFS} 163 IFS=$'\r'$'\n' 164 local TAB=$'\t' 165 cat <<EOF 166found_devenv := \$(shell which devenv.com >/dev/null 2>&1 && echo yes) 167.nodevenv.once: 168${TAB}@echo " * devenv.com not found in path." 169${TAB}@echo " * " 170${TAB}@echo " * You will have to build all configurations manually using the" 171${TAB}@echo " * Visual Studio IDE. To allow make to build them automatically," 172${TAB}@echo " * add the Common7/IDE directory of your Visual Studio" 173${TAB}@echo " * installation to your path, eg:" 174${TAB}@echo " * C:\Program Files\Microsoft Visual Studio 8\Common7\IDE" 175${TAB}@echo " * " 176${TAB}@touch \$@ 177CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once) 178 179EOF 180 181 for sln_config in ${config_list}; do 182 local config=${sln_config%%|*} 183 local platform=${sln_config##*|} 184 local nows_sln_config=`echo $sln_config | sed -e 's/[^a-zA-Z0-9]/_/g'` 185 cat <<EOF 186BUILD_TARGETS += \$(if \$(NO_LAUNCH_DEVENV),,$nows_sln_config) 187clean:: 188${TAB}rm -rf "$platform"/"$config" 189.PHONY: $nows_sln_config 190ifneq (\$(found_devenv),) 191 ifeq (\$(CONFIG_VS_VERSION),7) 192$nows_sln_config: $outfile 193${TAB}devenv.com $outfile -build "$config" 194 195 else 196$nows_sln_config: $outfile 197${TAB}devenv.com $outfile -build "$sln_config" 198 199 endif 200else 201$nows_sln_config: $outfile .nodevenv.once 202${TAB}@echo " * Skipping build of $sln_config (devenv.com not in path)." 203${TAB}@echo " * " 204endif 205 206EOF 207 done 208 IFS=${IFS_bak} 209} 210 211# Process command line 212outfile=/dev/stdout 213for opt in "$@"; do 214 optval="${opt#*=}" 215 case "$opt" in 216 --help|-h) show_help 217 ;; 218 --out=*) outfile="${optval}"; mkoutfile="${optval}".mk 219 ;; 220 --dep=*) eval "${optval%%:*}_deps=\"\${${optval%%:*}_deps} ${optval##*:}\"" 221 ;; 222 --ver=*) vs_ver="$optval" 223 case $optval in 224 [789]) 225 ;; 226 *) die Unrecognized Visual Studio Version in $opt 227 ;; 228 esac 229 ;; 230 --ver=*) vs_ver="$optval" 231 case $optval in 232 7) sln_vers="8.00" 233 sln_vers_str="Visual Studio .NET 2003" 234 ;; 235 [89]) 236 ;; 237 *) die "Unrecognized Visual Studio Version '$optval' in $opt" 238 ;; 239 esac 240 ;; 241 --target=*) target="${optval}" 242 ;; 243 -*) die_unknown $opt 244 ;; 245 *) file_list[${#file_list[@]}]="$opt" 246 esac 247done 248outfile=${outfile:-/dev/stdout} 249mkoutfile=${mkoutfile:-/dev/stdout} 250case "${vs_ver:-8}" in 251 7) sln_vers="8.00" 252 sln_vers_str="Visual Studio .NET 2003" 253 ;; 254 8) sln_vers="9.00" 255 sln_vers_str="Visual Studio 2005" 256 ;; 257 9) sln_vers="10.00" 258 sln_vers_str="Visual Studio 2008" 259 ;; 260esac 261 262for f in "${file_list[@]}"; do 263 parse_project $f 264done 265cat >${outfile} <<EOF 266Microsoft Visual Studio Solution File, Format Version $sln_vers${EOLDOS} 267# $sln_vers_str${EOLDOS} 268EOF 269for proj in ${proj_list}; do 270 process_project $proj >>${outfile} 271done 272process_global >>${outfile} 273process_makefile >${mkoutfile} 274