summaryrefslogtreecommitdiff
path: root/build-0.3/meta/vctest
blob: 05023648260ff7000b9183c8d172fd56664cbb64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#! /usr/bin/env bash

# file      : build/meta/vctest
# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
# license   : GNU GPL v2; see accompanying LICENSE file

# Process VC++ test templates.
#
# Options:
#
# -b <base-dir>
# -r <root-dir>
# -o <output-file>
# -t <template-file>
#
# Arguments:
#
# <solution-files>
#
trap 'exit 1' ERR

function error ()
{
  echo "$*" 1>&2
}

base=
root=
output=
sln=
input=

while [ $# -gt 0 ]; do
  case $1 in
    -b)
      base=$2
      shift 2
      ;;
    -r)
      root=$2
      shift 2
      ;;
    -o)
      output=$2
      shift 2
      ;;
    -t)
      input=$2
      shift 2
      ;;
    *)
      sln="$sln $1"
      shift
      ;;
  esac
done


if [ "$input" = "" ]; then
  error "no template file"
  exit 1
fi

if [ "$base" = "" ]; then
  error "no base directory"
  exit 1
fi

if [ "$root" = "" ]; then
  error "no root directory"
  exit 1
fi

if [ "$output" = "" ]; then
  error "no output file"
  exit 1
fi

if [ "$sln" = "" ]; then
  error "no solution file"
  exit 1
fi


m4=m4
u2d=todos

# Assume this script is never found via PATH.
#
meta=`dirname $0`

build="$meta/.."
install=$build/install/install

# Figure out topdir
#
if [ "$base" = "$root" ]; then
  topdir=.
else
  topdir=`echo $base | sed -e "s%^$root/%%" - | \
sed -e 's%[^/][^/]*/%../%g;s%[^./][^./]*$%..%' -`
fi

#

# Determine possible configurations.
#
for f in $sln; do
  sln_conf=`cat $f | fromdos | sed -n -e \
'/^[ 	]*GlobalSection(SolutionConfigurationPlatforms).*$/{\
: loop;\
n;\
/^[ 	]*EndGlobalSection$/q;\
s/^[ 	]*\([^=]*\) = \([^=]*\)$/\1/p;\
b loop};\
d' -`
  break
done

confs=
plats=
for c in $sln_conf; do
  conf=`echo $c | sed -e 's/^\(.*\)|.*$/\1/'`
  plat=`echo $c | sed -e 's/^.*|\(.*\)$/\1/'`

  confs="$confs $conf"
  plats="$plats $plat"
done

confs=`echo $confs | sed -e 's/ /\n/g' - | sort -u`
plats=`echo $plats | sed -e 's/ /\n/g' - | sort -u`

export topdir
export configurations=$confs
export platforms=$plats

# Make sure the output directory exist.
#
$install -d -m 755 `dirname $output`

$m4 -P -D__meta_base__=$meta $meta/vctest.m4 $input >$output
$u2d $output
chmod 644 $output