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 --dll Generate a project for creating a dll
30 --static-crt Use the static C runtime (/MT)
31 --target=isa-os-cc Target specifier (required)
32 --out=filename Write output to a file [stdout]
33 --name=project_name Name of the project (required)
34 --proj-guid=GUID GUID to use for the project
35 --module-def=filename File containing export definitions (for DLLs)
36 --ver=version Version (7,8,9) of visual studio to generate for
37 --src-path-bare=dir Path to root of source tree
38 -Ipath/to/include Additional include directories
39 -DFLAG[=value] Preprocessor macros to define
40 -Lpath/to/lib Additional library search paths
41 -llibname Library to link against
47 echo "${self_basename}: $@" >&2
52 echo "Unknown option \"$1\"." >&2
53 echo "See ${self_basename} --help for available options." >&2
58 local hex="0123456789ABCDEF"
62 #93995380-89BD-4b04-88EB-625FBE52EBFB
63 for ((i=0; i<32; i++)); do
64 (( j = $RANDOM % 16 ))
65 uuid="${uuid}${hex:$j:1}"
67 echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
73 indent="${indent}${indent1}"
76 indent="${indent%${indent1}}"
83 die "Missing attribute value in '$opt' while generating $tag tag"
84 echo "${indent}${opt%%=*}=\"${optval}\""
92 echo "${indent}<${tag}"
97 echo "${indent}<${tag}>"
105 echo "${indent}</${tag}>"
111 if [ $# -ne 0 ]; then
112 echo "${indent}<${tag}"
118 echo "${indent}<${tag}/>"
131 echo "generating filter '$name' from ${#file_list[@]} files" >&2
137 UniqueIdentifier=`generate_uuid` \
139 file_list_sz=${#file_list[@]}
140 for i in ${!file_list[@]}; do
142 for pat in ${pats//;/$IFS}; do
143 if [ "${f##*.}" == "$pat" ]; then
146 objf=$(echo ${f%.*}.obj | sed -e 's/^[\./]\+//g' -e 's,/,_,g')
147 open_tag File RelativePath="./$f"
149 if [ "$pat" == "asm" ] && $asm_use_custom_step; then
150 for plat in "${platforms[@]}"; do
151 for cfg in Debug Release; do
152 open_tag FileConfiguration \
153 Name="${cfg}|${plat}" \
156 Name="VCCustomBuildTool" \
157 Description="Assembling \$(InputFileName)" \
158 CommandLine="$(eval echo \$asm_${cfg}_cmdline) -o \$(IntDir)\\$objf" \
159 Outputs="\$(IntDir)\\$objf" \
161 close_tag FileConfiguration
165 if [ "$pat" == "c" ] || [ "$pat" == "cc" ] ; then
166 for plat in "${platforms[@]}"; do
167 for cfg in Debug Release; do
168 open_tag FileConfiguration \
169 Name="${cfg}|${plat}" \
172 Name="VCCLCompilerTool" \
173 ObjectFile="\$(IntDir)\\$objf" \
175 close_tag FileConfiguration
190 # Process command line
197 --target=*) target="${optval}"
199 --out=*) outfile="$optval"
201 --name=*) name="${optval}"
203 --proj-guid=*) guid="${optval}"
205 --module-def=*) link_opts="${link_opts} ModuleDefinitionFile=${optval}"
207 --exe) proj_kind="exe"
209 --dll) proj_kind="dll"
211 --lib) proj_kind="lib"
213 --src-path-bare=*) src_path_bare="$optval"
215 --static-crt) use_static_runtime=true
222 *) die Unrecognized Visual Studio Version in $opt
228 incs="${incs}${incs:+;}"${opt##-I}""
229 yasmincs="${yasmincs} ${opt}"
231 -D*) defines="${defines}${defines:+;}${opt##-D}"
233 -L*) # fudge . to $(OutDir)
234 if [ "${opt##-L}" == "." ]; then
235 libdirs="${libdirs}${libdirs:+;}"\$(OutDir)""
237 # Also try directories for this platform/configuration
238 libdirs="${libdirs}${libdirs:+;}"${opt##-L}""
239 libdirs="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)/\$(ConfigurationName)""
240 libdirs="${libdirs}${libdirs:+;}"${opt##-L}/\$(PlatformName)""
243 -l*) libs="${libs}${libs:+ }${opt##-l}.lib"
248 file_list[${#file_list[@]}]="$opt"
256 outfile=${outfile:-/dev/stdout}
257 guid=${guid:-`generate_uuid`}
258 asm_use_custom_step=false
259 uses_asm=${uses_asm:-false}
260 case "${vs_ver:-8}" in
262 asm_use_custom_step=$uses_asm
263 warn_64bit='Detect64BitPortabilityProblems=true'
266 asm_use_custom_step=$uses_asm
267 warn_64bit='Detect64BitPortabilityProblems=true'
270 asm_use_custom_step=$uses_asm
271 warn_64bit='Detect64BitPortabilityProblems=false'
275 [ -n "$name" ] || die "Project name (--name) must be specified!"
276 [ -n "$target" ] || die "Target (--target) must be specified!"
278 if ${use_static_runtime:-false}; then
288 # Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename
289 # it to ${lib_sfx}d.lib. This precludes linking to release libs from a
290 # debug exe, so this may need to be refactored later.
291 for lib in ${libs}; do
292 if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then
295 debug_libs="${debug_libs}${debug_libs:+ }${lib}"
299 # List Keyword for this target
301 x86*) keyword="ManagedCProj"
303 *) die "Unsupported target $target!"
306 # List of all platforms supported for this target
310 asm_Debug_cmdline="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
311 asm_Release_cmdline="yasm -Xvc -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
315 asm_Debug_cmdline="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
316 asm_Release_cmdline="yasm -Xvc -f \$(PlatformName) ${yasmincs} "\$(InputPath)""
318 *) die "Unsupported target $target!"
324 exe) vs_ConfigurationType=1
326 dll) vs_ConfigurationType=2
328 *) vs_ConfigurationType=4
332 echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
333 open_tag VisualStudioProject \
334 ProjectType="Visual C++" \
335 Version="${vs_ver_id}" \
337 ProjectGUID="{${guid}}" \
338 RootNamespace="${name}" \
339 Keyword="${keyword}" \
342 for plat in "${platforms[@]}"; do
343 tag Platform Name="$plat"
347 open_tag Configurations
348 for plat in "${platforms[@]}"; do
349 plat_no_ws=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'`
350 open_tag Configuration \
352 OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
353 IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
354 ConfigurationType="$vs_ConfigurationType" \
362 Name="VCCLCompilerTool" \
364 AdditionalIncludeDirectories="$incs" \
365 PreprocessorDefinitions="WIN32;DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
366 RuntimeLibrary="$debug_runtime" \
368 DebugInformationFormat="1" \
373 Name="VCPreBuildEventTool" \
374 CommandLine="call obj_int_extract.bat $src_path_bare" \
377 Name="VCCLCompilerTool" \
379 AdditionalIncludeDirectories="$incs" \
380 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
381 RuntimeLibrary="$debug_runtime" \
382 UsePrecompiledHeader="0" \
384 DebugInformationFormat="2" \
387 $uses_asm && tag Tool Name="YASM" IncludePaths="$incs" Debug="true"
391 Name="VCCLCompilerTool" \
393 AdditionalIncludeDirectories="$incs" \
394 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
395 RuntimeLibrary="$debug_runtime" \
396 UsePrecompiledHeader="0" \
398 DebugInformationFormat="2" \
401 $uses_asm && tag Tool Name="YASM" IncludePaths="$incs" Debug="true"
414 Name="VCLinkerTool" \
415 OutputFile="${name}.exe" \
416 GenerateDebugInformation="true" \
420 Name="VCLinkerTool" \
421 AdditionalDependencies="$debug_libs \$(NoInherit)" \
422 AdditionalLibraryDirectories="$libdirs" \
423 GenerateDebugInformation="true" \
424 ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \
434 Name="VCLibrarianTool" \
435 OutputFile="\$(OutDir)/${name}${lib_sfx}d.lib" \
442 Name="VCLinkerTool" \
443 AdditionalDependencies="\$(NoInherit)" \
444 LinkIncremental="2" \
445 GenerateDebugInformation="true" \
453 close_tag Configuration
455 open_tag Configuration \
456 Name="Release|$plat" \
457 OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
458 IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
459 ConfigurationType="$vs_ConfigurationType" \
461 WholeProgramOptimization="0" \
468 Name="VCCLCompilerTool" \
470 FavorSizeorSpeed="1" \
471 AdditionalIncludeDirectories="$incs" \
472 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
473 RuntimeLibrary="$release_runtime" \
474 UsePrecompiledHeader="0" \
476 DebugInformationFormat="0" \
481 Name="VCPreBuildEventTool" \
482 CommandLine="call obj_int_extract.bat $src_path_bare" \
485 Name="VCCLCompilerTool" \
487 FavorSizeorSpeed="1" \
488 AdditionalIncludeDirectories="$incs" \
489 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
490 RuntimeLibrary="$release_runtime" \
491 UsePrecompiledHeader="0" \
493 DebugInformationFormat="0" \
496 $uses_asm && tag Tool Name="YASM" IncludePaths="$incs"
500 Name="VCCLCompilerTool" \
501 AdditionalIncludeDirectories="$incs" \
503 FavorSizeorSpeed="1" \
504 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
505 RuntimeLibrary="$release_runtime" \
506 UsePrecompiledHeader="0" \
508 DebugInformationFormat="0" \
511 $uses_asm && tag Tool Name="YASM" IncludePaths="$incs"
524 Name="VCLinkerTool" \
525 OutputFile="${name}.exe" \
526 GenerateDebugInformation="true" \
530 Name="VCLinkerTool" \
531 AdditionalDependencies="$libs \$(NoInherit)" \
532 AdditionalLibraryDirectories="$libdirs" \
543 Name="VCLibrarianTool" \
544 OutputFile="\$(OutDir)/${name}${lib_sfx}.lib" \
549 dll) # note differences to debug version: LinkIncremental, AssemblyDebug
551 Name="VCLinkerTool" \
552 AdditionalDependencies="\$(NoInherit)" \
553 LinkIncremental="1" \
554 GenerateDebugInformation="true" \
561 close_tag Configuration
563 close_tag Configurations
566 generate_filter srcs "Source Files" "c;cc;def;odl;idl;hpj;bat;asm;asmx"
567 generate_filter hdrs "Header Files" "h;hm;inl;inc;xsd"
568 generate_filter resrcs "Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
569 generate_filter resrcs "Build Files" "mk"
573 close_tag VisualStudioProject
575 # This must be done from within the {} subshell
576 echo "Ignored files list (${#file_list[@]} items) is:" >&2
577 for f in "${file_list[@]}"; do
583 sed -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile}
587 TODO: Add any files not captured by filters.
589 RelativePath=".\ReadMe.txt"