Home | History | Annotate | Download | only in make
      1 #!/bin/bash
      2 ##
      3 ##  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      4 ##
      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.
     10 ##
     11 
     12 
     13 self=$0
     14 self_basename=${self##*/}
     15 EOL=$'\n'
     16 EOLDOS=$'\r'
     17 
     18 show_help() {
     19     cat <<EOF
     20 Usage: ${self_basename} [options] file1 [file2 ...]
     21 
     22 This script generates a Visual Studio 2005 solution file from a list of project
     23 files.
     24 
     25 Options:
     26     --help                      Print this message
     27     --out=outfile               Redirect output to a file
     28     --ver=version               Version (7,8,9) of visual studio to generate for
     29     --target=isa-os-cc          Target specifier
     30 EOF
     31     exit 1
     32 }
     33 
     34 die() {
     35     echo "${self_basename}: $@" >&2
     36     [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
     37     exit 1
     38 }
     39 
     40 die_unknown(){
     41     echo "Unknown option \"$1\"." >&2
     42     echo "See ${self_basename} --help for available options." >&2
     43     [ -f "${outfile}" ] && rm -f ${outfile}{,.mk}
     44     exit 1
     45 }
     46 
     47 indent1=$'\t'
     48 indent=""
     49 indent_push() {
     50     indent="${indent}${indent1}"
     51 }
     52 indent_pop() {
     53     indent="${indent%${indent1}}"
     54 }
     55 
     56 parse_project() {
     57     local file=$1
     58     local name=`grep Name "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'`
     59     local guid=`grep ProjectGUID "$file" | awk 'BEGIN {FS="\""}{if (NR==1) print $2}'`
     60 
     61     # save the project GUID to a varaible, normalizing to the basename of the
     62     # vcproj file without the extension
     63     local var
     64     var=${file##*/}
     65     var=${var%%.vcproj}
     66     eval "${var}_file=\"$1\""
     67     eval "${var}_name=$name"
     68     eval "${var}_guid=$guid"
     69 
     70     # assume that all projects have the same list of possible configurations,
     71     # so overwriting old config_lists is not a problem
     72     config_list=`grep -A1 '<Configuration' $file |
     73         grep Name | cut -d\" -f2`
     74     proj_list="${proj_list} ${var}"
     75 }
     76 
     77 process_project() {
     78     eval "local file=\${$1_file}"
     79     eval "local name=\${$1_name}"
     80     eval "local guid=\${$1_guid}"
     81 
     82     # save the project GUID to a varaible, normalizing to the basename of the
     83     # vcproj file without the extension
     84     local var
     85     var=${file##*/}
     86     var=${var%%.vcproj}
     87     eval "${var}_guid=$guid"
     88 
     89     echo "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$name\", \"$file\", \"$guid\""
     90     indent_push
     91 
     92     eval "local deps=\"\${${var}_deps}\""
     93     if [ -n "$deps" ]; then
     94         echo "${indent}ProjectSection(ProjectDependencies) = postProject"
     95         indent_push
     96 
     97         for dep in $deps; do
     98             eval "local dep_guid=\${${dep}_guid}"
     99             [ -z "${dep_guid}" ] && die "Unknown GUID for $dep (dependency of $var)"
    100             echo "${indent}$dep_guid = $dep_guid"
    101         done
    102 
    103         indent_pop
    104         echo "${indent}EndProjectSection"
    105 
    106     fi
    107 
    108     indent_pop
    109     echo "EndProject"
    110 }
    111 
    112 process_global() {
    113     echo "Global"
    114     indent_push
    115 
    116     #
    117     # Solution Configuration Platforms
    118     #
    119     echo "${indent}GlobalSection(SolutionConfigurationPlatforms) = preSolution"
    120     indent_push
    121     IFS_bak=${IFS}
    122     IFS=$'\r'$'\n'
    123     for config in ${config_list}; do
    124         echo "${indent}$config = $config"
    125     done
    126     IFS=${IFS_bak}
    127     indent_pop
    128     echo "${indent}EndGlobalSection"
    129 
    130     #
    131     # Project Configuration Platforms
    132     #
    133     echo "${indent}GlobalSection(ProjectConfigurationPlatforms) = postSolution"
    134     indent_push
    135     for proj in ${proj_list}; do
    136         eval "local proj_guid=\${${proj}_guid}"
    137         IFS=$'\r'$'\n'
    138         for config in ${config_list}; do
    139             echo "${indent}${proj_guid}.${config}.ActiveCfg = ${config}"
    140             echo "${indent}${proj_guid}.${config}.Build.0 = ${config}"
    141 
    142             if [ "$target" == "armv6-wince-vs8" ] || [ "$target" == "armv5te-wince-vs8" ] || [ "$target" == "iwmmxt-wince-vs8" ] || [ "$target" == "iwmmxt2-wince-vs8" ];then
    143                 echo "${indent}${proj_guid}.${config}.Deploy.0 = ${config}"
    144             fi
    145         done
    146         IFS=${IFS_bak}
    147     done
    148     indent_pop
    149     echo "${indent}EndGlobalSection"
    150 
    151     #
    152     # Solution Properties
    153     #
    154     echo "${indent}GlobalSection(SolutionProperties) = preSolution"
    155     indent_push
    156     echo "${indent}HideSolutionNode = FALSE"
    157     indent_pop
    158     echo "${indent}EndGlobalSection"
    159 
    160     indent_pop
    161     echo "EndGlobal"
    162 }
    163 
    164 process_makefile() {
    165     IFS_bak=${IFS}
    166     IFS=$'\r'$'\n'
    167     local TAB=$'\t'
    168     cat <<EOF
    169 found_devenv := \$(shell which devenv.com >/dev/null 2>&1 && echo yes)
    170 .nodevenv.once:
    171 ${TAB}@echo "  * devenv.com not found in path."
    172 ${TAB}@echo "  * "
    173 ${TAB}@echo "  * You will have to build all configurations manually using the"
    174 ${TAB}@echo "  * Visual Studio IDE. To allow make to build them automatically,"
    175 ${TAB}@echo "  * add the Common7/IDE directory of your Visual Studio"
    176 ${TAB}@echo "  * installation to your path, eg:"
    177 ${TAB}@echo "  *   C:\Program Files\Microsoft Visual Studio 8\Common7\IDE"
    178 ${TAB}@echo "  * "
    179 ${TAB}@touch \$@
    180 CLEAN-OBJS += \$(if \$(found_devenv),,.nodevenv.once)
    181 
    182 EOF
    183 
    184     for sln_config in ${config_list}; do
    185         local config=${sln_config%%|*}
    186         local platform=${sln_config##*|}
    187         local nows_sln_config=`echo $sln_config | sed -e 's/[^a-zA-Z0-9]/_/g'`
    188         cat <<EOF
    189 BUILD_TARGETS += \$(if \$(NO_LAUNCH_DEVENV),,$nows_sln_config)
    190 clean::
    191 ${TAB}rm -rf "$platform"/"$config"
    192 .PHONY: $nows_sln_config
    193 ifneq (\$(found_devenv),)
    194   ifeq (\$(CONFIG_VS_VERSION),7)
    195 $nows_sln_config: $outfile
    196 ${TAB}devenv.com $outfile -build "$config"
    197 
    198   else
    199 $nows_sln_config: $outfile
    200 ${TAB}devenv.com $outfile -build "$sln_config"
    201 
    202   endif
    203 else
    204 $nows_sln_config: $outfile .nodevenv.once
    205 ${TAB}@echo "  * Skipping build of $sln_config (devenv.com not in path)."
    206 ${TAB}@echo "  * "
    207 endif
    208 
    209 EOF
    210     done
    211     IFS=${IFS_bak}
    212 }
    213 
    214 # Process command line
    215 outfile=/dev/stdout
    216 for opt in "$@"; do
    217     optval="${opt#*=}"
    218     case "$opt" in
    219     --help|-h) show_help
    220     ;;
    221     --out=*) outfile="${optval}"; mkoutfile="${optval}".mk
    222     ;;
    223     --dep=*) eval "${optval%%:*}_deps=\"\${${optval%%:*}_deps} ${optval##*:}\""
    224     ;;
    225     --ver=*) vs_ver="$optval"
    226              case $optval in
    227              [789])
    228              ;;
    229              *) die Unrecognized Visual Studio Version in $opt
    230              ;;
    231              esac
    232     ;;
    233     --ver=*) vs_ver="$optval"
    234              case $optval in
    235              7) sln_vers="8.00"
    236                 sln_vers_str="Visual Studio .NET 2003"
    237              ;;
    238              [89])
    239              ;;
    240              *) die "Unrecognized Visual Studio Version '$optval' in $opt"
    241              ;;
    242              esac
    243     ;;
    244     --target=*) target="${optval}"
    245     ;;
    246     -*) die_unknown $opt
    247     ;;
    248     *) file_list[${#file_list[@]}]="$opt"
    249     esac
    250 done
    251 outfile=${outfile:-/dev/stdout}
    252 mkoutfile=${mkoutfile:-/dev/stdout}
    253 case "${vs_ver:-8}" in
    254     7) sln_vers="8.00"
    255        sln_vers_str="Visual Studio .NET 2003"
    256     ;;
    257     8) sln_vers="9.00"
    258        sln_vers_str="Visual Studio 2005"
    259     ;;
    260     9) sln_vers="10.00"
    261        sln_vers_str="Visual Studio 2008"
    262     ;;
    263 esac
    264 
    265 for f in "${file_list[@]}"; do
    266     parse_project $f
    267 done
    268 cat  >${outfile} <<EOF
    269 Microsoft Visual Studio Solution File, Format Version $sln_vers${EOLDOS}
    270 # $sln_vers_str${EOLDOS}
    271 EOF
    272 for proj in ${proj_list}; do
    273     process_project $proj >>${outfile}
    274 done
    275 process_global >>${outfile}
    276 process_makefile >${mkoutfile}
    277