purge wince configuration
[libvpx.git] / build / make / gen_msvs_proj.sh
blob5921a2b10dd68c16a4dc2800d6a87a596a7dfc9b
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 self_dirname=$(dirname "$0")
16 EOL=$'\n'
18 show_help() {
19 cat <<EOF
20 Usage: ${self_basename} --name=projname [options] file1 [file2 ...]
22 This script generates a Visual Studio project file from a list of source
23 code files.
25 Options:
26 --help Print this message
27 --exe Generate a project for building an Application
28 --lib Generate a project for creating a static library
29 --static-crt Use the static C runtime (/MT)
30 --target=isa-os-cc Target specifier (required)
31 --out=filename Write output to a file [stdout]
32 --name=project_name Name of the project (required)
33 --proj-guid=GUID GUID to use for the project
34 --module-def=filename File containing export definitions (for DLLs)
35 --ver=version Version (7,8) of visual studio to generate for
36 -Ipath/to/include Additional include directories
37 -DFLAG[=value] Preprocessor macros to define
38 -Lpath/to/lib Additional library search paths
39 -llibname Library to link against
40 EOF
41 exit 1
44 die() {
45 echo "${self_basename}: $@" >&2
46 exit 1
49 die_unknown(){
50 echo "Unknown option \"$1\"." >&2
51 echo "See ${self_basename} --help for available options." >&2
52 exit 1
55 generate_uuid() {
56 local hex="0123456789ABCDEF"
57 local i
58 local uuid=""
59 local j
60 #93995380-89BD-4b04-88EB-625FBE52EBFB
61 for ((i=0; i<32; i++)); do
62 (( j = $RANDOM % 16 ))
63 uuid="${uuid}${hex:$j:1}"
64 done
65 echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
68 indent1=" "
69 indent=""
70 indent_push() {
71 indent="${indent}${indent1}"
73 indent_pop() {
74 indent="${indent%${indent1}}"
77 tag_attributes() {
78 for opt in "$@"; do
79 optval="${opt#*=}"
80 [ -n "${optval}" ] ||
81 die "Missing attribute value in '$opt' while generating $tag tag"
82 echo "${indent}${opt%%=*}=\"${optval}\""
83 done
86 open_tag() {
87 local tag=$1
88 shift
89 if [ $# -ne 0 ]; then
90 echo "${indent}<${tag}"
91 indent_push
92 tag_attributes "$@"
93 echo "${indent}>"
94 else
95 echo "${indent}<${tag}>"
96 indent_push
100 close_tag() {
101 local tag=$1
102 indent_pop
103 echo "${indent}</${tag}>"
106 tag() {
107 local tag=$1
108 shift
109 if [ $# -ne 0 ]; then
110 echo "${indent}<${tag}"
111 indent_push
112 tag_attributes "$@"
113 indent_pop
114 echo "${indent}/>"
115 else
116 echo "${indent}<${tag}/>"
120 generate_filter() {
121 local var=$1
122 local name=$2
123 local pats=$3
124 local file_list_sz
125 local i
126 local f
127 local saveIFS="$IFS"
128 local pack
129 echo "generating filter '$name' from ${#file_list[@]} files" >&2
130 IFS=*
132 open_tag Filter \
133 Name=$name \
134 Filter=$pats \
135 UniqueIdentifier=`generate_uuid`
137 file_list_sz=${#file_list[@]}
138 for i in ${!file_list[@]}; do
139 f=${file_list[i]}
140 for pat in ${pats//;/$IFS}; do
141 if [ "${f##*.}" == "$pat" ]; then
142 unset file_list[i]
144 open_tag File RelativePath="./$f"
145 if [ "$pat" == "asm" ] && $asm_use_custom_step; then
146 for plat in "${platforms[@]}"; do
147 for cfg in Debug Release; do
148 open_tag FileConfiguration \
149 Name="${cfg}|${plat}"
150 tag Tool \
151 Name="VCCustomBuildTool" \
152 Description="Assembling \$(InputFileName)" \
153 CommandLine="$(eval echo \$asm_${cfg}_cmdline)"\
154 Outputs="\$(InputName).obj"
155 close_tag FileConfiguration
156 done
157 done
160 if [ "${f##*.}" == "cpp" ]; then
161 for plat in "${platforms[@]}"; do
162 for cfg in Debug Release; do
163 open_tag FileConfiguration \
164 Name="${cfg}|${plat}"
165 tag Tool \
166 Name="VCCLCompilerTool" \
167 CompileAs="2"
168 close_tag FileConfiguration
169 done
170 done
172 close_tag File
174 break
176 done
177 done
179 close_tag Filter
180 IFS="$saveIFS"
183 # Process command line
184 unset target
185 for opt in "$@"; do
186 optval="${opt#*=}"
187 case "$opt" in
188 --help|-h) show_help
190 --target=*) target="${optval}"
192 --out=*) outfile="$optval"
194 --name=*) name="${optval}"
196 --proj-guid=*) guid="${optval}"
198 --module-def=*)
199 link_opts="${link_opts} ModuleDefinitionFile=${optval}"
201 --exe) proj_kind="exe"
203 --lib) proj_kind="lib"
205 --static-crt) use_static_runtime=true
207 --ver=*) vs_ver="$optval"
208 case $optval in
209 [789])
211 *) die Unrecognized Visual Studio Version in $opt
213 esac
215 -I*) opt="${opt%/}"
216 incs="${incs}${incs:+;}&quot;${opt##-I}&quot;"
217 yasmincs="${yasmincs} ${opt}"
219 -D*) defines="${defines}${defines:+;}${opt##-D}"
221 -L*) # fudge . to $(OutDir)
222 if [ "${opt##-L}" == "." ]; then
223 libdirs="${libdirs}${libdirs:+;}&quot;\$(OutDir)&quot;"
224 else
225 # Also try directories for this platform/configuration
226 libdirs="${libdirs}${libdirs:+;}&quot;${opt##-L}&quot;"
227 libdirs="${libdirs}${libdirs:+;}&quot;${opt##-L}/\$(PlatformName)/\$(ConfigurationName)&quot;"
228 libdirs="${libdirs}${libdirs:+;}&quot;${opt##-L}/\$(PlatformName)&quot;"
231 -l*) libs="${libs}${libs:+ }${opt##-l}.lib"
233 -*) die_unknown $opt
235 *) file_list[${#file_list[@]}]="$opt"
236 case "$opt" in
237 *.asm) uses_asm=true;;
238 esac
239 esac
240 done
241 outfile=${outfile:-/dev/stdout}
242 guid=${guid:-`generate_uuid`}
243 asm_use_custom_step=false
244 uses_asm=${uses_asm:-false}
245 case "${vs_ver:-8}" in
246 7) vs_ver_id="7.10"
247 asm_use_custom_step=$uses_asm
249 8) vs_ver_id="8.00"
251 9) vs_ver_id="9.00"
253 esac
255 [ -n "$name" ] || die "Project name (--name) must be specified!"
256 [ -n "$target" ] || die "Target (--target) must be specified!"
258 if ${use_static_runtime:-false}; then
259 release_runtime=0
260 debug_runtime=1
261 lib_sfx=mt
262 else
263 release_runtime=2
264 debug_runtime=3
265 lib_sfx=md
268 # Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename
269 # it to ${lib_sfx}d.lib. This precludes linking to release libs from a
270 # debug exe, so this may need to be refactored later.
271 for lib in ${libs}; do
272 if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then
273 lib=${lib%.lib}d.lib
275 debug_libs="${debug_libs}${debug_libs:+ }${lib}"
276 done
279 # List Keyword for this target
280 case "$target" in
281 x86*)
282 keyword="ManagedCProj"
284 *) die "Unsupported target $target!"
285 esac
287 # List of all platforms supported for this target
288 case "$target" in
289 x86_64*)
290 platforms[0]="x64"
292 x86*)
293 platforms[0]="Win32"
294 # these are only used by vs7
295 asm_Debug_cmdline="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} &quot;\$(InputPath)&quot;"
296 asm_Release_cmdline="yasm -Xvc -f \$(PlatformName) ${yasmincs} &quot;\$(InputPath)&quot;"
298 *) die "Unsupported target $target!"
299 esac
301 generate_vcproj() {
302 case "$proj_kind" in
303 exe) vs_ConfigurationType=1
305 *) vs_ConfigurationType=4
307 esac
309 echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
310 open_tag VisualStudioProject \
311 ProjectType="Visual C++" \
312 Version="${vs_ver_id}" \
313 Name="${name}" \
314 ProjectGUID="{${guid}}" \
315 RootNamespace="${name}" \
316 Keyword="${keyword}"
318 open_tag Platforms
319 for plat in "${platforms[@]}"; do
320 tag Platform Name="$plat"
321 done
322 close_tag Platforms
324 open_tag ToolFiles
325 case "$target" in
326 x86*) $uses_asm && tag ToolFile RelativePath="$self_dirname/../x86-msvs/yasm.rules"
328 esac
329 close_tag ToolFiles
331 open_tag Configurations
332 for plat in "${platforms[@]}"; do
333 plat_no_ws=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'`
334 open_tag Configuration \
335 Name="Debug|$plat" \
336 OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
337 IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
338 ConfigurationType="$vs_ConfigurationType" \
339 CharacterSet="1"
341 case "$target" in
342 x86*) tag Tool \
343 Name="VCCLCompilerTool" \
344 Optimization="0" \
345 AdditionalIncludeDirectories="$incs" \
346 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
347 RuntimeLibrary="$debug_runtime" \
348 UsePrecompiledHeader="0" \
349 WarningLevel="3" \
350 DebugInformationFormat="1" \
351 Detect64BitPortabilityProblems="true" \
353 $uses_asm && tag Tool Name="YASM" IncludePaths="$incs" Debug="1"
355 esac
357 case "$proj_kind" in
358 exe)
359 case "$target" in
360 x86*) tag Tool \
361 Name="VCLinkerTool" \
362 AdditionalDependencies="$debug_libs \$(NoInherit)" \
363 AdditionalLibraryDirectories="$libdirs" \
364 GenerateDebugInformation="true" \
365 ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \
368 esac
370 lib)
371 case "$target" in
372 *) tag Tool \
373 Name="VCLibrarianTool" \
374 OutputFile="\$(OutDir)/${name}${lib_sfx}d.lib" \
376 esac
378 dll) tag Tool \
379 Name="VCLinkerTool" \
380 AdditionalDependencies="\$(NoInherit)" \
381 LinkIncremental="2" \
382 GenerateDebugInformation="true" \
383 AssemblyDebug="1" \
384 TargetMachine="1" \
385 $link_opts
386 esac
388 close_tag Configuration
390 open_tag Configuration \
391 Name="Release|$plat" \
392 OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
393 IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
394 ConfigurationType="$vs_ConfigurationType" \
395 CharacterSet="1" \
396 WholeProgramOptimization="0"
398 case "$target" in
399 x86*) tag Tool \
400 Name="VCCLCompilerTool" \
401 AdditionalIncludeDirectories="$incs" \
402 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
403 RuntimeLibrary="$release_runtime" \
404 UsePrecompiledHeader="0" \
405 WarningLevel="3" \
406 DebugInformationFormat="0" \
407 Detect64BitPortabilityProblems="true"
409 $uses_asm && tag Tool Name="YASM" IncludePaths="$incs"
411 esac
413 case "$proj_kind" in
414 exe)
415 case "$target" in
416 x86*) tag Tool \
417 Name="VCLinkerTool" \
418 AdditionalDependencies="$libs \$(NoInherit)" \
419 AdditionalLibraryDirectories="$libdirs" \
421 esac
423 lib)
424 case "$target" in
425 *) tag Tool \
426 Name="VCLibrarianTool" \
427 OutputFile="\$(OutDir)/${name}${lib_sfx}.lib" \
429 esac
431 dll) # note differences to debug version: LinkIncremental, AssemblyDebug
432 tag Tool \
433 Name="VCLinkerTool" \
434 AdditionalDependencies="\$(NoInherit)" \
435 LinkIncremental="1" \
436 GenerateDebugInformation="true" \
437 TargetMachine="1" \
438 $link_opts
439 esac
441 close_tag Configuration
442 done
443 close_tag Configurations
445 open_tag Files
446 generate_filter srcs "Source Files" "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
447 generate_filter hdrs "Header Files" "h;hpp;hxx;hm;inl;inc;xsd"
448 generate_filter resrcs "Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
449 generate_filter resrcs "Build Files" "mk"
450 close_tag Files
452 tag Globals
453 close_tag VisualStudioProject
455 # This must be done from within the {} subshell
456 echo "Ignored files list (${#file_list[@]} items) is:" >&2
457 for f in "${file_list[@]}"; do
458 echo " $f" >&2
459 done
462 generate_vcproj |
463 sed -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile}
465 exit
466 <!--
467 TODO: Add any files not captured by filters.
468 <File
469 RelativePath=".\ReadMe.txt"
471 </File>