gen_msvs_sln.sh 7.1 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
#!/bin/bash
Yaowu Xu's avatar
Yaowu Xu committed
2
## Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar's avatar
John Koleszar committed
3
##
Yaowu Xu's avatar
Yaowu Xu committed
4 5 6 7 8 9
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
John Koleszar's avatar
John Koleszar committed
10 11 12 13 14 15 16 17 18 19 20 21
##


self=$0
self_basename=${self##*/}
EOL=$'\n'
EOLDOS=$'\r'

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

22
This script generates a Visual Studio solution file from a list of project
John Koleszar's avatar
John Koleszar committed
23 24 25 26 27
files.

Options:
    --help                      Print this message
    --out=outfile               Redirect output to a file
28
    --ver=version               Version (7,8,9,10,11,12,14) of visual studio to generate for
John Koleszar's avatar
John Koleszar committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    --target=isa-os-cc          Target specifier
EOF
    exit 1
}

die() {
    echo "${self_basename}: $@" >&2
    [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
    exit 1
}

die_unknown(){
    echo "Unknown option \"$1\"." >&2
    echo "See ${self_basename} --help for available options." >&2
    [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
    exit 1
}

indent1=$'\t'
indent=""
indent_push() {
    indent="${indent}${indent1}"
}
indent_pop() {
    indent="${indent%${indent1}}"
}

parse_project() {
    local file=$1
58 59
    local name=`grep RootNamespace "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
    local guid=`grep ProjectGuid "$file" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
John Koleszar's avatar
John Koleszar committed
60 61

    # save the project GUID to a varaible, normalizing to the basename of the
62
    # vcxproj file without the extension
John Koleszar's avatar
John Koleszar committed
63 64
    local var
    var=${file##*/}
65
    var=${var%%.${sfx}}
John Koleszar's avatar
John Koleszar committed
66 67 68 69
    eval "${var}_file=\"$1\""
    eval "${var}_name=$name"
    eval "${var}_guid=$guid"

70 71
    cur_config_list=`grep -B1 'Label="Configuration"' $file |
        grep Condition | cut -d\' -f4`
72 73 74 75 76 77 78 79
    new_config_list=$(for i in $config_list $cur_config_list; do
        echo $i
    done | sort | uniq)
    if [ "$config_list" != "" ] && [ "$config_list" != "$new_config_list" ]; then
        mixed_platforms=1
    fi
    config_list="$new_config_list"
    eval "${var}_config_list=\"$cur_config_list\""
John Koleszar's avatar
John Koleszar committed
80 81 82 83 84 85 86 87 88 89 90 91
    proj_list="${proj_list} ${var}"
}

process_project() {
    eval "local file=\${$1_file}"
    eval "local name=\${$1_name}"
    eval "local guid=\${$1_guid}"

    # save the project GUID to a varaible, normalizing to the basename of the
    # vcproj file without the extension
    local var
    var=${file##*/}
92
    var=${var%%.${sfx}}
John Koleszar's avatar
John Koleszar committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    eval "${var}_guid=$guid"

    echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\""
    echo "EndProject"
}

process_global() {
    echo "Global"
    indent_push

    #
    # Solution Configuration Platforms
    #
    echo "${indent}GlobalSection(SolutionConfigurationPlatforms) = preSolution"
    indent_push
    IFS_bak=${IFS}
    IFS=$'\r'$'\n'
110 111 112 113 114
    if [ "$mixed_platforms" != "" ]; then
        config_list="
Release|Mixed Platforms
Debug|Mixed Platforms"
    fi
John Koleszar's avatar
John Koleszar committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128
    for config in ${config_list}; do
        echo "${indent}$config = $config"
    done
    IFS=${IFS_bak}
    indent_pop
    echo "${indent}EndGlobalSection"

    #
    # Project Configuration Platforms
    #
    echo "${indent}GlobalSection(ProjectConfigurationPlatforms) = postSolution"
    indent_push
    for proj in ${proj_list}; do
        eval "local proj_guid=\${${proj}_guid}"
129
        eval "local proj_config_list=\${${proj}_config_list}"
John Koleszar's avatar
John Koleszar committed
130
        IFS=$'\r'$'\n'
131 132 133 134 135 136 137 138 139
        for config in ${proj_config_list}; do
            if [ "$mixed_platforms" != "" ]; then
                local c=${config%%|*}
                echo "${indent}${proj_guid}.${c}|Mixed Platforms.ActiveCfg = ${config}"
                echo "${indent}${proj_guid}.${c}|Mixed Platforms.Build.0 = ${config}"
            else
                echo "${indent}${proj_guid}.${config}.ActiveCfg = ${config}"
                echo "${indent}${proj_guid}.${config}.Build.0 = ${config}"
            fi
John Koleszar's avatar
John Koleszar committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

        done
        IFS=${IFS_bak}
    done
    indent_pop
    echo "${indent}EndGlobalSection"

    #
    # Solution Properties
    #
    echo "${indent}GlobalSection(SolutionProperties) = preSolution"
    indent_push
    echo "${indent}HideSolutionNode = FALSE"
    indent_pop
    echo "${indent}EndGlobalSection"

    indent_pop
    echo "EndGlobal"
}

process_makefile() {
    IFS_bak=${IFS}
    IFS=$'\r'$'\n'
    local TAB=$'\t'
    cat <<EOF
165 166
MSBUILD_TOOL := msbuild.exe
found_devenv := \$(shell which \$(MSBUILD_TOOL) >/dev/null 2>&1 && echo yes)
John Koleszar's avatar
John Koleszar committed
167
.nodevenv.once:
168
${TAB}@echo "  * \$(MSBUILD_TOOL) not found in path."
John Koleszar's avatar
John Koleszar committed
169 170 171 172 173
${TAB}@echo "  * "
${TAB}@echo "  * You will have to build all configurations manually using the"
${TAB}@echo "  * Visual Studio IDE. To allow make to build them automatically,"
${TAB}@echo "  * add the Common7/IDE directory of your Visual Studio"
${TAB}@echo "  * installation to your path, eg:"
174
${TAB}@echo "  *   C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE"
John Koleszar's avatar
John Koleszar committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
${TAB}@echo "  * "
${TAB}@touch \$@
CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once)

EOF

    for sln_config in ${config_list}; do
        local config=${sln_config%%|*}
        local platform=${sln_config##*|}
        local nows_sln_config=`echo $sln_config | sed -e 's/[^a-zA-Z0-9]/_/g'`
        cat <<EOF
BUILD_TARGETS += \$(if \$(NO_LAUNCH_DEVENV),,$nows_sln_config)
clean::
${TAB}rm -rf "$platform"/"$config"
.PHONY: $nows_sln_config
ifneq (\$(found_devenv),)
$nows_sln_config: $outfile
192 193
${TAB}\$(MSBUILD_TOOL) $outfile -m -t:Build \\
${TAB}${TAB}-p:Configuration="$config" -p:Platform="$platform"
John Koleszar's avatar
John Koleszar committed
194 195
else
$nows_sln_config: $outfile .nodevenv.once
196
${TAB}@echo "  * Skipping build of $sln_config (\$(MSBUILD_TOOL) not in path)."
John Koleszar's avatar
John Koleszar committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
${TAB}@echo "  * "
endif

EOF
    done
    IFS=${IFS_bak}
}

# Process command line
outfile=/dev/stdout
for opt in "$@"; do
    optval="${opt#*=}"
    case "$opt" in
    --help|-h) show_help
    ;;
    --out=*) outfile="${optval}"; mkoutfile="${optval}".mk
    ;;
    --dep=*) eval "${optval%%:*}_deps=\"\${${optval%%:*}_deps} ${optval##*:}\""
    ;;
    --ver=*) vs_ver="$optval"
             case $optval in
218
             10|11|12|14)
John Koleszar's avatar
John Koleszar committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232
             ;;
             *) die Unrecognized Visual Studio Version in $opt
             ;;
             esac
    ;;
    --target=*) target="${optval}"
    ;;
    -*) die_unknown $opt
    ;;
    *) file_list[${#file_list[@]}]="$opt"
    esac
done
outfile=${outfile:-/dev/stdout}
mkoutfile=${mkoutfile:-/dev/stdout}
233
case "${vs_ver:-10}" in
234 235 236 237 238 239
    10) sln_vers="11.00"
       sln_vers_str="Visual Studio 2010"
    ;;
    11) sln_vers="12.00"
       sln_vers_str="Visual Studio 2012"
    ;;
Yaowu Xu's avatar
Yaowu Xu committed
240 241 242
    12) sln_vers="12.00"
       sln_vers_str="Visual Studio 2013"
    ;;
243 244 245
    14) sln_vers="14.00"
       sln_vers_str="Visual Studio 2015"
    ;;
246
esac
247
sfx=vcxproj
John Koleszar's avatar
John Koleszar committed
248 249 250 251 252 253 254 255 256 257 258 259 260

for f in "${file_list[@]}"; do
    parse_project $f
done
cat  >${outfile} <<EOF
Microsoft Visual Studio Solution File, Format Version $sln_vers${EOLDOS}
# $sln_vers_str${EOLDOS}
EOF
for proj in ${proj_list}; do
    process_project $proj >>${outfile}
done
process_global >>${outfile}
process_makefile >${mkoutfile}