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) 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
45 echo "${self_basename}: $@" >&2
50 echo "Unknown option \"$1\"." >&2
51 echo "See ${self_basename} --help for available options." >&2
56 local hex
="0123456789ABCDEF"
60 #93995380-89BD-4b04-88EB-625FBE52EBFB
61 for ((i
=0; i
<32; i
++)); do
62 (( j
= $RANDOM % 16 ))
63 uuid
="${uuid}${hex:$j:1}"
65 echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
71 indent
="${indent}${indent1}"
74 indent
="${indent%${indent1}}"
81 die
"Missing attribute value in '$opt' while generating $tag tag"
82 echo "${indent}${opt%%=*}=\"${optval}\""
90 echo "${indent}<${tag}"
95 echo "${indent}<${tag}>"
103 echo "${indent}</${tag}>"
109 if [ $# -ne 0 ]; then
110 echo "${indent}<${tag}"
116 echo "${indent}<${tag}/>"
129 echo "generating filter '$name' from ${#file_list[@]} files" >&2
135 UniqueIdentifier
=`generate_uuid`
137 file_list_sz
=${#file_list[@]}
138 for i
in ${!file_list[@]}; do
140 for pat
in ${pats//;/$IFS}; do
141 if [ "${f##*.}" == "$pat" ]; then
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}"
151 Name
="VCCustomBuildTool" \
152 Description
="Assembling \$(InputFileName)" \
153 CommandLine
="$(eval echo \$asm_${cfg}_cmdline)"\
154 Outputs
="\$(InputName).obj"
155 close_tag FileConfiguration
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}"
166 Name
="VCCLCompilerTool" \
168 close_tag FileConfiguration
183 # Process command line
190 --target=*) target
="${optval}"
192 --out=*) outfile
="$optval"
194 --name=*) name
="${optval}"
196 --proj-guid=*) guid
="${optval}"
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"
211 *) die Unrecognized Visual Studio Version
in $opt
216 incs
="${incs}${incs:+;}"${opt##-I}""
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:+;}"\$(OutDir)""
225 # Also try directories for this platform/configuration
226 libdirs
="${libdirs}${libdirs:+;}"${opt##-L}""
227 libdirs
="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)/\$(ConfigurationName)""
228 libdirs
="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)""
231 -l*) libs
="${libs}${libs:+ }${opt##-l}.lib"
235 *) file_list
[${#file_list[@]}]="$opt"
237 *.asm
) uses_asm
=true
;;
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
247 asm_use_custom_step
=$uses_asm
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
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
275 debug_libs
="${debug_libs}${debug_libs:+ }${lib}"
279 # List Keyword for this target
282 keyword
="ManagedCProj"
284 *) die
"Unsupported target $target!"
287 # List of all platforms supported for this target
294 # these are only used by vs7
295 asm_Debug_cmdline
="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
296 asm_Release_cmdline
="yasm -Xvc -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
298 *) die
"Unsupported target $target!"
303 exe
) vs_ConfigurationType
=1
305 *) vs_ConfigurationType
=4
309 echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
310 open_tag VisualStudioProject \
311 ProjectType
="Visual C++" \
312 Version
="${vs_ver_id}" \
314 ProjectGUID
="{${guid}}" \
315 RootNamespace
="${name}" \
319 for plat
in "${platforms[@]}"; do
320 tag Platform Name
="$plat"
326 x86
*) $uses_asm && tag ToolFile RelativePath
="$self_dirname/../x86-msvs/yasm.rules"
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 \
336 OutputDirectory
="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
337 IntermediateDirectory
="$plat_no_ws/\$(ConfigurationName)/${name}" \
338 ConfigurationType
="$vs_ConfigurationType" \
343 Name
="VCCLCompilerTool" \
345 AdditionalIncludeDirectories
="$incs" \
346 PreprocessorDefinitions
="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
347 RuntimeLibrary
="$debug_runtime" \
348 UsePrecompiledHeader
="0" \
350 DebugInformationFormat
="1" \
351 Detect64BitPortabilityProblems
="true" \
353 $uses_asm && tag Tool Name
="YASM" IncludePaths
="$incs" Debug
="1"
361 Name
="VCLinkerTool" \
362 AdditionalDependencies
="$debug_libs \$(NoInherit)" \
363 AdditionalLibraryDirectories
="$libdirs" \
364 GenerateDebugInformation
="true" \
365 ProgramDatabaseFile
="\$(OutDir)/${name}.pdb" \
373 Name
="VCLibrarianTool" \
374 OutputFile
="\$(OutDir)/${name}${lib_sfx}d.lib" \
379 Name
="VCLinkerTool" \
380 AdditionalDependencies
="\$(NoInherit)" \
381 LinkIncremental
="2" \
382 GenerateDebugInformation
="true" \
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" \
396 WholeProgramOptimization
="0"
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" \
406 DebugInformationFormat
="0" \
407 Detect64BitPortabilityProblems
="true"
409 $uses_asm && tag Tool Name
="YASM" IncludePaths
="$incs"
417 Name
="VCLinkerTool" \
418 AdditionalDependencies
="$libs \$(NoInherit)" \
419 AdditionalLibraryDirectories
="$libdirs" \
426 Name
="VCLibrarianTool" \
427 OutputFile
="\$(OutDir)/${name}${lib_sfx}.lib" \
431 dll
) # note differences to debug version: LinkIncremental, AssemblyDebug
433 Name
="VCLinkerTool" \
434 AdditionalDependencies
="\$(NoInherit)" \
435 LinkIncremental
="1" \
436 GenerateDebugInformation
="true" \
441 close_tag Configuration
443 close_tag Configurations
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"
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
463 sed -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile}
467 TODO
: Add any files not captured by filters.
469 RelativePath
=".\ReadMe.txt"