obj_int_extract for Visual Studio
[libvpx.git] / build / make / gen_msvs_sln.sh
blob240678b6455388dc09f4c9e92cf85c51b8fd1385
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.
13 self=$0
14 self_basename=${self##*/}
15 EOL=$'\n'
16 EOLDOS=$'\r'
18 show_help() {
19 cat <<EOF
20 Usage: ${self_basename} [options] file1 [file2 ...]
22 This script generates a Visual Studio 2005 solution file from a list of project
23 files.
25 Options:
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
30 EOF
31 exit 1
34 die() {
35 echo "${self_basename}: $@" >&2
36 [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
37 exit 1
40 die_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
47 indent1=$'\t'
48 indent=""
49 indent_push() {
50 indent="${indent}${indent1}"
52 indent_pop() {
53 indent="${indent%${indent1}}"
56 parse_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}'`
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"
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}"
77 process_project() {
78 eval "local file=\${$1_file}"
79 eval "local name=\${$1_name}"
80 eval "local guid=\${$1_guid}"
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"
89 echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\""
90 indent_push
92 eval "local deps=\"\${${var}_deps}\""
93 if [ -n "$deps" ]; then
94 echo "${indent}ProjectSection(ProjectDependencies) = postProject"
95 indent_push
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
103 indent_pop
104 echo "${indent}EndProjectSection"
108 indent_pop
109 echo "EndProject"
112 process_global() {
113 echo "Global"
114 indent_push
117 # Solution Configuration Platforms
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"
131 # Project Configuration Platforms
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}"
142 done
143 IFS=${IFS_bak}
144 done
145 indent_pop
146 echo "${indent}EndGlobalSection"
149 # Solution Properties
151 echo "${indent}GlobalSection(SolutionProperties) = preSolution"
152 indent_push
153 echo "${indent}HideSolutionNode = FALSE"
154 indent_pop
155 echo "${indent}EndGlobalSection"
157 indent_pop
158 echo "EndGlobal"
161 process_makefile() {
162 IFS_bak=${IFS}
163 IFS=$'\r'$'\n'
164 local TAB=$'\t'
165 cat <<EOF
166 found_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 \$@
177 CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once)
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
186 BUILD_TARGETS += \$(if \$(NO_LAUNCH_DEVENV),,$nows_sln_config)
187 clean::
188 ${TAB}rm -rf "$platform"/"$config"
189 .PHONY: $nows_sln_config
190 ifneq (\$(found_devenv),)
191 ifeq (\$(CONFIG_VS_VERSION),7)
192 $nows_sln_config: $outfile
193 ${TAB}devenv.com $outfile -build "$config"
195 else
196 $nows_sln_config: $outfile
197 ${TAB}devenv.com $outfile -build "$sln_config"
199 endif
200 else
201 $nows_sln_config: $outfile .nodevenv.once
202 ${TAB}@echo " * Skipping build of $sln_config (devenv.com not in path)."
203 ${TAB}@echo " * "
204 endif
207 done
208 IFS=${IFS_bak}
211 # Process command line
212 outfile=/dev/stdout
213 for opt in "$@"; do
214 optval="${opt#*=}"
215 case "$opt" in
216 --help|-h) show_help
218 --out=*) outfile="${optval}"; mkoutfile="${optval}".mk
220 --dep=*) eval "${optval%%:*}_deps=\"\${${optval%%:*}_deps} ${optval##*:}\""
222 --ver=*) vs_ver="$optval"
223 case $optval in
224 [789])
226 *) die Unrecognized Visual Studio Version in $opt
228 esac
230 --ver=*) vs_ver="$optval"
231 case $optval in
232 7) sln_vers="8.00"
233 sln_vers_str="Visual Studio .NET 2003"
235 [89])
237 *) die "Unrecognized Visual Studio Version '$optval' in $opt"
239 esac
241 --target=*) target="${optval}"
243 -*) die_unknown $opt
245 *) file_list[${#file_list[@]}]="$opt"
246 esac
247 done
248 outfile=${outfile:-/dev/stdout}
249 mkoutfile=${mkoutfile:-/dev/stdout}
250 case "${vs_ver:-8}" in
251 7) sln_vers="8.00"
252 sln_vers_str="Visual Studio .NET 2003"
254 8) sln_vers="9.00"
255 sln_vers_str="Visual Studio 2005"
257 9) sln_vers="10.00"
258 sln_vers_str="Visual Studio 2008"
260 esac
262 for f in "${file_list[@]}"; do
263 parse_project $f
264 done
265 cat >${outfile} <<EOF
266 Microsoft Visual Studio Solution File, Format Version $sln_vers${EOLDOS}
267 # $sln_vers_str${EOLDOS}
269 for proj in ${proj_list}; do
270 process_project $proj >>${outfile}
271 done
272 process_global >>${outfile}
273 process_makefile >${mkoutfile}