3 ## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
14 self_basename
=${self##*/}
15 self_dirname
=$
(dirname "$0")
20 Usage: ${self_basename} --name=projname [options] file1 [file2 ...]
22 This script generates a Visual Studio project file from a list of source
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,9) of visual studio to generate for
36 --src-path-bare=dir Path to root of source tree
37 -Ipath/to/include Additional include directories
38 -DFLAG[=value] Preprocessor macros to define
39 -Lpath/to/lib Additional library search paths
40 -llibname Library to link against
46 echo "${self_basename}: $@" >&2
51 echo "Unknown option \"$1\"." >&2
52 echo "See ${self_basename} --help for available options." >&2
57 local hex
="0123456789ABCDEF"
61 #93995380-89BD-4b04-88EB-625FBE52EBFB
62 for ((i
=0; i
<32; i
++)); do
63 (( j
= $RANDOM % 16 ))
64 uuid
="${uuid}${hex:$j:1}"
66 echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
72 indent
="${indent}${indent1}"
75 indent
="${indent%${indent1}}"
82 die
"Missing attribute value in '$opt' while generating $tag tag"
83 echo "${indent}${opt%%=*}=\"${optval}\""
91 echo "${indent}<${tag}"
96 echo "${indent}<${tag}>"
104 echo "${indent}</${tag}>"
110 if [ $# -ne 0 ]; then
111 echo "${indent}<${tag}"
117 echo "${indent}<${tag}/>"
130 echo "generating filter '$name' from ${#file_list[@]} files" >&2
136 UniqueIdentifier
=`generate_uuid` \
138 file_list_sz
=${#file_list[@]}
139 for i
in ${!file_list[@]}; do
141 for pat
in ${pats//;/$IFS}; do
142 if [ "${f##*.}" == "$pat" ]; then
145 open_tag File RelativePath
="./$f"
146 if [ "$pat" == "asm" ] && $asm_use_custom_step; then
147 for plat
in "${platforms[@]}"; do
148 for cfg
in Debug Release
; do
149 open_tag FileConfiguration \
150 Name
="${cfg}|${plat}" \
153 Name
="VCCustomBuildTool" \
154 Description
="Assembling \$(InputFileName)" \
155 CommandLine
="$(eval echo \$asm_${cfg}_cmdline)" \
156 Outputs
="\$(InputName).obj" \
158 close_tag FileConfiguration
174 # Process command line
181 --target=*) target
="${optval}"
183 --out=*) outfile
="$optval"
185 --name=*) name
="${optval}"
187 --proj-guid=*) guid
="${optval}"
189 --module-def=*) link_opts
="${link_opts} ModuleDefinitionFile=${optval}"
191 --exe) proj_kind
="exe"
193 --lib) proj_kind
="lib"
195 --src-path-bare=*) src_path_bare
="$optval"
197 --static-crt) use_static_runtime
=true
204 *) die Unrecognized Visual Studio Version
in $opt
210 incs
="${incs}${incs:+;}"${opt##-I}""
211 yasmincs
="${yasmincs} ${opt}"
213 -D*) defines
="${defines}${defines:+;}${opt##-D}"
215 -L*) # fudge . to $(OutDir)
216 if [ "${opt##-L}" == "." ]; then
217 libdirs
="${libdirs}${libdirs:+;}"\$(OutDir)""
219 # Also try directories for this platform/configuration
220 libdirs
="${libdirs}${libdirs:+;}"${opt##-L}""
221 libdirs
="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)/\$(ConfigurationName)""
222 libdirs
="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)""
225 -l*) libs
="${libs}${libs:+ }${opt##-l}.lib"
230 file_list
[${#file_list[@]}]="$opt"
238 outfile
=${outfile:-/dev/stdout}
239 guid
=${guid:-`generate_uuid`}
240 asm_use_custom_step
=false
241 uses_asm
=${uses_asm:-false}
242 case "${vs_ver:-8}" in
244 asm_use_custom_step
=$uses_asm
252 [ -n "$name" ] || die
"Project name (--name) must be specified!"
253 [ -n "$target" ] || die
"Target (--target) must be specified!"
255 if ${use_static_runtime:-false}; then
265 # Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename
266 # it to ${lib_sfx}d.lib. This precludes linking to release libs from a
267 # debug exe, so this may need to be refactored later.
268 for lib
in ${libs}; do
269 if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then
272 debug_libs
="${debug_libs}${debug_libs:+ }${lib}"
276 # List Keyword for this target
278 x86
*) keyword
="ManagedCProj"
280 *) die
"Unsupported target $target!"
283 # List of all platforms supported for this target
290 # these are only used by vs7
291 asm_Debug_cmdline
="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
292 asm_Release_cmdline
="yasm -Xvc -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
294 *) die
"Unsupported target $target!"
300 exe
) vs_ConfigurationType
=1
302 *) vs_ConfigurationType
=4
306 echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
307 open_tag VisualStudioProject \
308 ProjectType
="Visual C++" \
309 Version
="${vs_ver_id}" \
311 ProjectGUID
="{${guid}}" \
312 RootNamespace
="${name}" \
313 Keyword
="${keyword}" \
316 for plat
in "${platforms[@]}"; do
317 tag Platform Name
="$plat"
323 x86
*) $uses_asm && tag ToolFile RelativePath
="$self_dirname/../x86-msvs/yasm.rules"
328 open_tag Configurations
329 for plat
in "${platforms[@]}"; do
330 plat_no_ws
=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'`
331 open_tag Configuration \
333 OutputDirectory
="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
334 IntermediateDirectory
="$plat_no_ws/\$(ConfigurationName)/${name}" \
335 ConfigurationType
="$vs_ConfigurationType" \
343 Name
="VCCLCompilerTool" \
345 AdditionalIncludeDirectories
="$incs" \
346 PreprocessorDefinitions
="WIN32;DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
347 RuntimeLibrary
="$debug_runtime" \
349 Detect64BitPortabilityProblems
="true" \
350 DebugInformationFormat
="1" \
354 Name
="VCPreBuildEventTool" \
355 CommandLine
="call obj_int_extract.bat $src_path_bare" \
358 Name
="VCCLCompilerTool" \
360 AdditionalIncludeDirectories
="$incs" \
361 PreprocessorDefinitions
="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
362 RuntimeLibrary
="$debug_runtime" \
363 UsePrecompiledHeader
="0" \
365 DebugInformationFormat
="1" \
366 Detect64BitPortabilityProblems
="true" \
368 $uses_asm && tag Tool Name
="YASM" IncludePaths
="$incs" Debug
="true"
372 Name
="VCCLCompilerTool" \
374 AdditionalIncludeDirectories
="$incs" \
375 PreprocessorDefinitions
="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
376 RuntimeLibrary
="$debug_runtime" \
377 UsePrecompiledHeader
="0" \
379 DebugInformationFormat
="1" \
380 Detect64BitPortabilityProblems
="true" \
382 $uses_asm && tag Tool Name
="YASM" IncludePaths
="$incs" Debug
="true"
395 Name
="VCLinkerTool" \
396 OutputFile
="${name}.exe" \
397 GenerateDebugInformation
="true" \
401 Name
="VCLinkerTool" \
402 AdditionalDependencies
="$debug_libs \$(NoInherit)" \
403 AdditionalLibraryDirectories
="$libdirs" \
404 GenerateDebugInformation
="true" \
405 ProgramDatabaseFile
="\$(OutDir)/${name}.pdb" \
415 Name
="VCLibrarianTool" \
416 OutputFile
="\$(OutDir)/${name}${lib_sfx}d.lib" \
423 Name
="VCLinkerTool" \
424 AdditionalDependencies
="\$(NoInherit)" \
425 LinkIncremental
="2" \
426 GenerateDebugInformation
="true" \
434 close_tag Configuration
436 open_tag Configuration \
437 Name
="Release|$plat" \
438 OutputDirectory
="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
439 IntermediateDirectory
="$plat_no_ws/\$(ConfigurationName)/${name}" \
440 ConfigurationType
="$vs_ConfigurationType" \
442 WholeProgramOptimization
="0" \
449 Name
="VCCLCompilerTool" \
451 FavorSizeorSpeed
="1" \
452 AdditionalIncludeDirectories
="$incs" \
453 PreprocessorDefinitions
="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
454 RuntimeLibrary
="$release_runtime" \
455 UsePrecompiledHeader
="0" \
457 Detect64BitPortabilityProblems
="true" \
458 DebugInformationFormat
="0" \
462 Name
="VCPreBuildEventTool" \
463 CommandLine
="call obj_int_extract.bat $src_path_bare" \
466 Name
="VCCLCompilerTool" \
468 FavorSizeorSpeed
="1" \
469 AdditionalIncludeDirectories
="$incs" \
470 PreprocessorDefinitions
="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
471 RuntimeLibrary
="$release_runtime" \
472 UsePrecompiledHeader
="0" \
474 DebugInformationFormat
="0" \
475 Detect64BitPortabilityProblems
="true" \
477 $uses_asm && tag Tool Name
="YASM" IncludePaths
="$incs"
481 Name
="VCCLCompilerTool" \
482 AdditionalIncludeDirectories
="$incs" \
484 FavorSizeorSpeed
="1" \
485 PreprocessorDefinitions
="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
486 RuntimeLibrary
="$release_runtime" \
487 UsePrecompiledHeader
="0" \
489 DebugInformationFormat
="0" \
490 Detect64BitPortabilityProblems
="true" \
492 $uses_asm && tag Tool Name
="YASM" IncludePaths
="$incs"
505 Name
="VCLinkerTool" \
506 OutputFile
="${name}.exe" \
507 GenerateDebugInformation
="true" \
511 Name
="VCLinkerTool" \
512 AdditionalDependencies
="$libs \$(NoInherit)" \
513 AdditionalLibraryDirectories
="$libdirs" \
524 Name
="VCLibrarianTool" \
525 OutputFile
="\$(OutDir)/${name}${lib_sfx}.lib" \
530 dll
) # note differences to debug version: LinkIncremental, AssemblyDebug
532 Name
="VCLinkerTool" \
533 AdditionalDependencies
="\$(NoInherit)" \
534 LinkIncremental
="1" \
535 GenerateDebugInformation
="true" \
542 close_tag Configuration
544 close_tag Configurations
547 generate_filter srcs
"Source Files" "c;def;odl;idl;hpj;bat;asm;asmx"
548 generate_filter hdrs
"Header Files" "h;hm;inl;inc;xsd"
549 generate_filter resrcs
"Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
550 generate_filter resrcs
"Build Files" "mk"
554 close_tag VisualStudioProject
556 # This must be done from within the {} subshell
557 echo "Ignored files list (${#file_list[@]} items) is:" >&2
558 for f
in "${file_list[@]}"; do
564 sed -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile}
568 TODO
: Add any files not captured by filters.
570 RelativePath
=".\ReadMe.txt"