gen_msvs_proj.sh 18.2 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
2
#!/bin/bash
##
3
##  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
4
##
5
##  Use of this source code is governed by a BSD-style license
6
7
##  that can be found in the LICENSE file in the root of the source
##  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.
John Koleszar's avatar
John Koleszar committed
10
11
12
13
##

self=$0
self_basename=${self##*/}
14
self_dirname=$(dirname "$0")
15
16

. "$self_dirname/msvs_common.sh"|| exit 127
John Koleszar's avatar
John Koleszar committed
17
18
19
20
21
22
23
24
25
26
27
28

show_help() {
    cat <<EOF
Usage: ${self_basename} --name=projname [options] file1 [file2 ...]

This script generates a Visual Studio project file from a list of source
code files.

Options:
    --help                      Print this message
    --exe                       Generate a project for building an Application
    --lib                       Generate a project for creating a static library
Jim Bankoski's avatar
Jim Bankoski committed
29
    --dll                       Generate a project for creating a dll
John Koleszar's avatar
John Koleszar committed
30
31
32
33
34
35
    --static-crt                Use the static C runtime (/MT)
    --target=isa-os-cc          Target specifier (required)
    --out=filename              Write output to a file [stdout]
    --name=project_name         Name of the project (required)
    --proj-guid=GUID            GUID to use for the project
    --module-def=filename       File containing export definitions (for DLLs)
Johann's avatar
Johann committed
36
    --ver=version               Version (7,8,9) of visual studio to generate for
Johann's avatar
Johann committed
37
    --src-path-bare=dir         Path to root of source tree
John Koleszar's avatar
John Koleszar committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    -Ipath/to/include           Additional include directories
    -DFLAG[=value]              Preprocessor macros to define
    -Lpath/to/lib               Additional library search paths
    -llibname                   Library to link against
EOF
    exit 1
}

generate_filter() {
    local var=$1
    local name=$2
    local pats=$3
    local file_list_sz
    local i
    local f
    local saveIFS="$IFS"
    local pack
    echo "generating filter '$name' from ${#file_list[@]} files" >&2
    IFS=*

    open_tag Filter \
        Name=$name \
        Filter=$pats \
Johann's avatar
Johann committed
61
        UniqueIdentifier=`generate_uuid` \
John Koleszar's avatar
John Koleszar committed
62
63
64
65
66
67
68
69

    file_list_sz=${#file_list[@]}
    for i in ${!file_list[@]}; do
        f=${file_list[i]}
        for pat in ${pats//;/$IFS}; do
            if [ "${f##*.}" == "$pat" ]; then
                unset file_list[i]

70
                objf=$(echo ${f%.*}.obj | sed -e 's/^[\./]\+//g' -e 's,[:/ ],_,g')
71
                open_tag File RelativePath="$f"
72

John Koleszar's avatar
John Koleszar committed
73
74
75
                if [ "$pat" == "asm" ] && $asm_use_custom_step; then
                    for plat in "${platforms[@]}"; do
                        for cfg in Debug Release; do
Johann's avatar
Johann committed
76
77
78
                            open_tag FileConfiguration \
                                Name="${cfg}|${plat}" \

John Koleszar's avatar
John Koleszar committed
79
80
81
                            tag Tool \
                                Name="VCCustomBuildTool" \
                                Description="Assembling \$(InputFileName)" \
82
83
                                CommandLine="$(eval echo \$asm_${cfg}_cmdline) -o \$(IntDir)\\$objf" \
                                Outputs="\$(IntDir)\\$objf" \
Johann's avatar
Johann committed
84

John Koleszar's avatar
John Koleszar committed
85
86
87
88
                            close_tag FileConfiguration
                        done
                    done
                fi
89
90
                if [ "$pat" == "c" ] || \
                   [ "$pat" == "cc" ] || [ "$pat" == "cpp" ]; then
91
92
93
94
                    for plat in "${platforms[@]}"; do
                        for cfg in Debug Release; do
                            open_tag FileConfiguration \
                                Name="${cfg}|${plat}" \
John Koleszar's avatar
John Koleszar committed
95

96
97
                            tag Tool \
                                Name="VCCLCompilerTool" \
98
                                ObjectFile="\$(IntDir)\\$objf" \
99
100
101
102
103

                            close_tag FileConfiguration
                        done
                    done
                fi
Johann's avatar
Johann committed
104
                close_tag File
John Koleszar's avatar
John Koleszar committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

                break
            fi
        done
    done

    close_tag Filter
    IFS="$saveIFS"
}

# Process command line
unset target
for opt in "$@"; do
    optval="${opt#*=}"
    case "$opt" in
Johann's avatar
Johann committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        --help|-h) show_help
        ;;
        --target=*) target="${optval}"
        ;;
        --out=*) outfile="$optval"
        ;;
        --name=*) name="${optval}"
        ;;
        --proj-guid=*) guid="${optval}"
        ;;
        --module-def=*) link_opts="${link_opts} ModuleDefinitionFile=${optval}"
        ;;
        --exe) proj_kind="exe"
        ;;
Jim Bankoski's avatar
Jim Bankoski committed
134
135
        --dll) proj_kind="dll"
        ;;
Johann's avatar
Johann committed
136
137
        --lib) proj_kind="lib"
        ;;
138
        --src-path-bare=*) src_path_bare=$(fix_path "$optval")
Johann's avatar
Johann committed
139
        ;;
Johann's avatar
Johann committed
140
141
142
143
144
145
146
147
148
149
150
151
152
        --static-crt) use_static_runtime=true
        ;;
        --ver=*)
            vs_ver="$optval"
            case "$optval" in
                [789])
                ;;
                *) die Unrecognized Visual Studio Version in $opt
                ;;
            esac
        ;;
        -I*)
            opt="${opt%/}"
153
154
155
            opt=${opt##-I}
            opt=$(fix_path "$opt")
            incs="${incs}${incs:+;}&quot;${opt}&quot;"
156
            yasmincs="${yasmincs} -I&quot;${opt}&quot;"
Johann's avatar
Johann committed
157
158
159
160
161
162
163
164
        ;;
        -D*) defines="${defines}${defines:+;}${opt##-D}"
        ;;
        -L*) # fudge . to $(OutDir)
            if [ "${opt##-L}" == "." ]; then
                libdirs="${libdirs}${libdirs:+;}&quot;\$(OutDir)&quot;"
            else
                 # Also try directories for this platform/configuration
165
166
167
168
169
                 opt=${opt##-L}
                 opt=$(fix_path "$opt")
                 libdirs="${libdirs}${libdirs:+;}&quot;${opt}&quot;"
                 libdirs="${libdirs}${libdirs:+;}&quot;${opt}/\$(PlatformName)/\$(ConfigurationName)&quot;"
                 libdirs="${libdirs}${libdirs:+;}&quot;${opt}/\$(PlatformName)&quot;"
Johann's avatar
Johann committed
170
171
172
173
174
175
176
            fi
        ;;
        -l*) libs="${libs}${libs:+ }${opt##-l}.lib"
        ;;
        -*) die_unknown $opt
        ;;
        *)
177
            file_list[${#file_list[@]}]="$(fix_path $opt)"
Johann's avatar
Johann committed
178
179
180
181
182
            case "$opt" in
                 *.asm) uses_asm=true
                 ;;
            esac
        ;;
John Koleszar's avatar
John Koleszar committed
183
184
185
186
187
188
189
190
191
    esac
done
outfile=${outfile:-/dev/stdout}
guid=${guid:-`generate_uuid`}
asm_use_custom_step=false
uses_asm=${uses_asm:-false}
case "${vs_ver:-8}" in
    7) vs_ver_id="7.10"
       asm_use_custom_step=$uses_asm
192
       warn_64bit='Detect64BitPortabilityProblems=true'
John Koleszar's avatar
John Koleszar committed
193
194
    ;;
    8) vs_ver_id="8.00"
195
       asm_use_custom_step=$uses_asm
196
       warn_64bit='Detect64BitPortabilityProblems=true'
John Koleszar's avatar
John Koleszar committed
197
    ;;
Tom Finegan's avatar
Tom Finegan committed
198
    9) vs_ver_id="9.00"
199
       asm_use_custom_step=$uses_asm
200
       warn_64bit='Detect64BitPortabilityProblems=false'
Tom Finegan's avatar
Tom Finegan committed
201
    ;;
John Koleszar's avatar
John Koleszar committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
esac

[ -n "$name" ] || die "Project name (--name) must be specified!"
[ -n "$target" ] || die "Target (--target) must be specified!"

if ${use_static_runtime:-false}; then
    release_runtime=0
    debug_runtime=1
    lib_sfx=mt
else
    release_runtime=2
    debug_runtime=3
    lib_sfx=md
fi

# Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename
# it to ${lib_sfx}d.lib. This precludes linking to release libs from a
# debug exe, so this may need to be refactored later.
for lib in ${libs}; do
    if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then
        lib=${lib%.lib}d.lib
    fi
    debug_libs="${debug_libs}${debug_libs:+ }${lib}"
done


# List Keyword for this target
case "$target" in
Johann's avatar
Johann committed
230
    x86*) keyword="ManagedCProj"
John Koleszar's avatar
John Koleszar committed
231
232
233
234
235
236
237
238
    ;;
    *) die "Unsupported target $target!"
esac

# List of all platforms supported for this target
case "$target" in
    x86_64*)
        platforms[0]="x64"
239
240
        asm_Debug_cmdline="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} &quot;\$(InputPath)&quot;"
        asm_Release_cmdline="yasm -Xvc -f \$(PlatformName) ${yasmincs} &quot;\$(InputPath)&quot;"
John Koleszar's avatar
John Koleszar committed
241
242
243
    ;;
    x86*)
        platforms[0]="Win32"
244
245
        asm_Debug_cmdline="yasm -Xvc -g cv8 -f \$(PlatformName) ${yasmincs} &quot;\$(InputPath)&quot;"
        asm_Release_cmdline="yasm -Xvc -f \$(PlatformName) ${yasmincs} &quot;\$(InputPath)&quot;"
John Koleszar's avatar
John Koleszar committed
246
247
    ;;
    *) die "Unsupported target $target!"
Johann's avatar
Johann committed
248
    ;;
John Koleszar's avatar
John Koleszar committed
249
250
251
252
esac

generate_vcproj() {
    case "$proj_kind" in
Johann's avatar
Johann committed
253
254
        exe) vs_ConfigurationType=1
        ;;
Jim Bankoski's avatar
Jim Bankoski committed
255
256
        dll) vs_ConfigurationType=2
        ;;
Johann's avatar
Johann committed
257
258
        *)   vs_ConfigurationType=4
        ;;
John Koleszar's avatar
John Koleszar committed
259
260
261
    esac

    echo "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
Johann's avatar
Johann committed
262
263
264
265
266
267
268
269
270
    open_tag VisualStudioProject \
        ProjectType="Visual C++" \
        Version="${vs_ver_id}" \
        Name="${name}" \
        ProjectGUID="{${guid}}" \
        RootNamespace="${name}" \
        Keyword="${keyword}" \

    open_tag Platforms
John Koleszar's avatar
John Koleszar committed
271
    for plat in "${platforms[@]}"; do
Johann's avatar
Johann committed
272
        tag Platform Name="$plat"
John Koleszar's avatar
John Koleszar committed
273
274
275
    done
    close_tag Platforms

Johann's avatar
Johann committed
276
    open_tag Configurations
John Koleszar's avatar
John Koleszar committed
277
278
    for plat in "${platforms[@]}"; do
        plat_no_ws=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'`
Johann's avatar
Johann committed
279
280
281
282
283
284
        open_tag Configuration \
            Name="Debug|$plat" \
            OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
            IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
            ConfigurationType="$vs_ConfigurationType" \
            CharacterSet="1" \
John Koleszar's avatar
John Koleszar committed
285
286

        case "$target" in
Johann's avatar
Johann committed
287
288
            x86*)
                case "$name" in
Johann's avatar
Johann committed
289
290
291
292
293
294
295
296
297
                    obj_int_extract)
                        tag Tool \
                            Name="VCCLCompilerTool" \
                            Optimization="0" \
                            AdditionalIncludeDirectories="$incs" \
                            PreprocessorDefinitions="WIN32;DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
                            RuntimeLibrary="$debug_runtime" \
                            WarningLevel="3" \
                            DebugInformationFormat="1" \
298
                            $warn_64bit \
Johann's avatar
Johann committed
299
300
301
302
                    ;;
                    vpx)
                        tag Tool \
                            Name="VCPreBuildEventTool" \
303
                            CommandLine="call obj_int_extract.bat &quot;$src_path_bare&quot; $plat_no_ws\\\$(ConfigurationName)" \
Johann's avatar
Johann committed
304
305
306
307
308
309
310
311
312

                        tag Tool \
                            Name="VCCLCompilerTool" \
                            Optimization="0" \
                            AdditionalIncludeDirectories="$incs" \
                            PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
                            RuntimeLibrary="$debug_runtime" \
                            UsePrecompiledHeader="0" \
                            WarningLevel="3" \
313
                            DebugInformationFormat="2" \
314
                            $warn_64bit \
Johann's avatar
Johann committed
315

316
                        $uses_asm && tag Tool Name="YASM"  IncludePaths="$incs" Debug="true"
Johann's avatar
Johann committed
317
                    ;;
Johann's avatar
Johann committed
318
319
320
321
322
323
324
325
326
                    *)
                        tag Tool \
                            Name="VCCLCompilerTool" \
                            Optimization="0" \
                            AdditionalIncludeDirectories="$incs" \
                            PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
                            RuntimeLibrary="$debug_runtime" \
                            UsePrecompiledHeader="0" \
                            WarningLevel="3" \
327
                            DebugInformationFormat="2" \
328
                            $warn_64bit \
Johann's avatar
Johann committed
329

330
                        $uses_asm && tag Tool Name="YASM"  IncludePaths="$incs" Debug="true"
Johann's avatar
Johann committed
331
332
                    ;;
                esac
John Koleszar's avatar
John Koleszar committed
333
334
335
336
337
338
            ;;
        esac

        case "$proj_kind" in
            exe)
                case "$target" in
Johann's avatar
Johann committed
339
340
                    x86*)
                        case "$name" in
Johann's avatar
Johann committed
341
342
343
344
345
                            obj_int_extract)
                                tag Tool \
                                    Name="VCLinkerTool" \
                                    GenerateDebugInformation="true" \
                            ;;
Johann's avatar
Johann committed
346
347
348
349
350
351
352
353
354
                            *)
                                tag Tool \
                                    Name="VCLinkerTool" \
                                    AdditionalDependencies="$debug_libs \$(NoInherit)" \
                                    AdditionalLibraryDirectories="$libdirs" \
                                    GenerateDebugInformation="true" \
                                    ProgramDatabaseFile="\$(OutDir)/${name}.pdb" \
                            ;;
                        esac
John Koleszar's avatar
John Koleszar committed
355
356
357
358
359
                    ;;
                 esac
            ;;
            lib)
                case "$target" in
Johann's avatar
Johann committed
360
361
362
363
364
365
                    x86*)
                        tag Tool \
                            Name="VCLibrarianTool" \
                            OutputFile="\$(OutDir)/${name}${lib_sfx}d.lib" \

                    ;;
John Koleszar's avatar
John Koleszar committed
366
367
                esac
            ;;
Johann's avatar
Johann committed
368
369
370
371
372
373
374
375
376
377
378
            dll)
                tag Tool \
                    Name="VCLinkerTool" \
                    AdditionalDependencies="\$(NoInherit)" \
                    LinkIncremental="2" \
                    GenerateDebugInformation="true" \
                    AssemblyDebug="1" \
                    TargetMachine="1" \
                    $link_opts \

            ;;
John Koleszar's avatar
John Koleszar committed
379
380
381
382
        esac

        close_tag Configuration

Johann's avatar
Johann committed
383
384
385
386
387
388
389
        open_tag Configuration \
            Name="Release|$plat" \
            OutputDirectory="\$(SolutionDir)$plat_no_ws/\$(ConfigurationName)" \
            IntermediateDirectory="$plat_no_ws/\$(ConfigurationName)/${name}" \
            ConfigurationType="$vs_ConfigurationType" \
            CharacterSet="1" \
            WholeProgramOptimization="0" \
John Koleszar's avatar
John Koleszar committed
390

Johann's avatar
Johann committed
391
392
393
        case "$target" in
            x86*)
                case "$name" in
Johann's avatar
Johann committed
394
395
396
                    obj_int_extract)
                        tag Tool \
                            Name="VCCLCompilerTool" \
397
398
                            Optimization="2" \
                            FavorSizeorSpeed="1" \
Johann's avatar
Johann committed
399
400
401
402
403
404
                            AdditionalIncludeDirectories="$incs" \
                            PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" \
                            RuntimeLibrary="$release_runtime" \
                            UsePrecompiledHeader="0" \
                            WarningLevel="3" \
                            DebugInformationFormat="0" \
405
                            $warn_64bit \
Johann's avatar
Johann committed
406
407
408
409
                    ;;
                    vpx)
                        tag Tool \
                            Name="VCPreBuildEventTool" \
410
                            CommandLine="call obj_int_extract.bat $src_path_bare $plat_no_ws\\\$(ConfigurationName)" \
Johann's avatar
Johann committed
411
412
413

                        tag Tool \
                            Name="VCCLCompilerTool" \
414
415
                            Optimization="2" \
                            FavorSizeorSpeed="1" \
Johann's avatar
Johann committed
416
417
418
419
420
421
                            AdditionalIncludeDirectories="$incs" \
                            PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
                            RuntimeLibrary="$release_runtime" \
                            UsePrecompiledHeader="0" \
                            WarningLevel="3" \
                            DebugInformationFormat="0" \
422
                            $warn_64bit \
Johann's avatar
Johann committed
423
424
425

                        $uses_asm && tag Tool Name="YASM"  IncludePaths="$incs"
                    ;;
Johann's avatar
Johann committed
426
427
428
429
                    *)
                        tag Tool \
                            Name="VCCLCompilerTool" \
                            AdditionalIncludeDirectories="$incs" \
430
431
                            Optimization="2" \
                            FavorSizeorSpeed="1" \
Johann's avatar
Johann committed
432
433
434
435
436
                            PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;$defines" \
                            RuntimeLibrary="$release_runtime" \
                            UsePrecompiledHeader="0" \
                            WarningLevel="3" \
                            DebugInformationFormat="0" \
437
                            $warn_64bit \
Johann's avatar
Johann committed
438
439
440

                        $uses_asm && tag Tool Name="YASM"  IncludePaths="$incs"
                    ;;
John Koleszar's avatar
John Koleszar committed
441
                esac
Johann's avatar
Johann committed
442
443
            ;;
        esac
John Koleszar's avatar
John Koleszar committed
444
445
446
447

        case "$proj_kind" in
            exe)
                case "$target" in
Johann's avatar
Johann committed
448
449
                    x86*)
                        case "$name" in
Johann's avatar
Johann committed
450
451
452
453
454
                            obj_int_extract)
                                tag Tool \
                                    Name="VCLinkerTool" \
                                    GenerateDebugInformation="true" \
                            ;;
Johann's avatar
Johann committed
455
456
457
458
459
460
461
462
                            *)
                                tag Tool \
                                    Name="VCLinkerTool" \
                                    AdditionalDependencies="$libs \$(NoInherit)" \
                                    AdditionalLibraryDirectories="$libdirs" \

                            ;;
                        esac
John Koleszar's avatar
John Koleszar committed
463
464
465
                    ;;
                 esac
            ;;
Johann's avatar
Johann committed
466
            lib)
John Koleszar's avatar
John Koleszar committed
467
                case "$target" in
Johann's avatar
Johann committed
468
469
470
471
472
473
                    x86*)
                        tag Tool \
                            Name="VCLibrarianTool" \
                            OutputFile="\$(OutDir)/${name}${lib_sfx}.lib" \

                    ;;
John Koleszar's avatar
John Koleszar committed
474
                esac
Johann's avatar
Johann committed
475
476
477
478
479
480
481
482
483
484
485
            ;;
            dll) # note differences to debug version: LinkIncremental, AssemblyDebug
                tag Tool \
                    Name="VCLinkerTool" \
                    AdditionalDependencies="\$(NoInherit)" \
                    LinkIncremental="1" \
                    GenerateDebugInformation="true" \
                    TargetMachine="1" \
                    $link_opts \

            ;;
John Koleszar's avatar
John Koleszar committed
486
487
488
489
490
491
        esac

        close_tag Configuration
    done
    close_tag Configurations

Johann's avatar
Johann committed
492
    open_tag Files
493
    generate_filter srcs   "Source Files"   "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx"
Johann's avatar
Johann committed
494
    generate_filter hdrs   "Header Files"   "h;hm;inl;inc;xsd"
John Koleszar's avatar
John Koleszar committed
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
    generate_filter resrcs "Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
    generate_filter resrcs "Build Files"    "mk"
    close_tag Files

    tag       Globals
    close_tag VisualStudioProject

    # This must be done from within the {} subshell
    echo "Ignored files list (${#file_list[@]} items) is:" >&2
    for f in "${file_list[@]}"; do
        echo "    $f" >&2
    done
}

generate_vcproj |
    sed  -e '/"/s;\([^ "]\)/;\1\\;g' > ${outfile}

exit
<!--
TODO: Add any files not captured by filters.
                <File
                        RelativePath=".\ReadMe.txt"
                        >
                </File>
-->