aboutsummaryrefslogtreecommitdiff
path: root/build/dist
blob: 74769521d06c35dc543b2e3e750299171a4ba08f (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#! /usr/bin/env bash

# file      : build/dist
# author    : Boris Kolpackov <boris@codesynthesis.com>
# copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
# license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

# Create test distribution and generate makefiles.
#
# -src $(src_base)
# -out <dist root>
# -xsd <schema files>
# -cxx <c++ source files>
# -hxx <c++ header files>
# -ixx <c++ inline files>
# -gen <generated files>
# -cmd <xsde command>
# -opt <xsde options>
# -lib <extra libraries>
#
# -win generate MS nmakefile
#
# bld_root
#
trap 'exit 1' ERR

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

function gen ()
{
  echo -e "$*" >>$out/makefile
}

type=gnu

while [ $# -gt 0 ]; do
  case $1 in
    -src)
      src=$2
      shift 2
      ;;
    -out)
      out=$2
      shift 2
      ;;
    -xsd)
      xsd=$2
      shift 2
      ;;
    -cxx)
      cxx=$2
      shift 2
      ;;
    -hxx)
      hxx=$2
      shift 2
      ;;
    -ixx)
      ixx=$2
      shift 2
      ;;
    -gen)
      gen=$2
      shift 2
      ;;
    -cmd)
      cmd=$2
      shift 2
      ;;
    -opt)
      opt=$2
      shift 2
      ;;
    -win)
      type=win
      shift
      ;;
    -lib)
      lib=$2
      shift 2
      ;;
    *)
      error "unknown option: $1"
      exit 1
      ;;
  esac
done

if [ "$src" = "" ]; then
  error "-src option is not specified"
  exit 1
fi

if [ "$out" = "" ]; then
  error "-out option is not specified"
  exit 1
fi

# Calculate the root path.
#
root=`echo $src | sed -e 's%.*/tests/\(.*\)%tests/\1%' -`
out=$out/$root
root=`echo $root | sed -e 's%[^/]*%..%g' -`

# Sanitize any absolute paths in opt.
#
opt=`echo $opt | sed -e "s%$src/\([^ ]*\)%\1%g" -`

# Gather object files.
#
if [ "$gen" != "" ]; then
  gen_cxx=`echo $gen | sed -e 's%[^ ]*\.[h|i]xx *%%g' -`
  gen_hxx=`echo $gen | sed -e 's%[^ ]*\.[c|i]xx *%%g' -`
  gen_ixx=`echo $gen_cxx | sed -e 's%.cxx%.ixx%g' -`
fi

obj=`echo $cxx $gen_cxx | sed -e 's%\.cxx%.o%g' -`

if [ "$obj" = "" ]; then
  error "no source files specified"
  exit 1
fi

# Find the test driver name.
#
if [ "$cxx" != "" ]; then
  driver=`echo $cxx | sed -e "s/ /\n/g" | sed -e "s/driver\.cxx/driver/" -e t -e d -`
  driver=`echo $driver` # Get rid of newlines.
fi

if [ "$driver" = "" -a "$gen_cxx" != "" ]; then
  # See if the driver is auto-generated.
  #
  driver=`echo $gen_cxx | sed -e "s/ /\n/g" | sed -e "s/\([^ ]*\)driver\.cxx/\1driver/" -e t -e d -`
  driver=`echo $driver` # Get rid of newlines.
fi

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

# Figure out the stem and pattern for the schema and gen files. If
# we have more than one schema file, base the stem and the pattern
# on the first file.
#
for i in $xsd; do
  stem=`echo $i | sed -e 's%\.xsd%%' -`
  pat=`echo $gen | sed -e "s/ /\n/g" | sed -e "s/$stem/%/" -e t -e d -`
  pat=`echo $pat` # Get rid of newlines.
done


# Sense what kind of tests we need to run.
#
xml=`find $src -name 'test-*.xml' | sed -e 's%.*/\([^/]*\)%\1%' -`
std=`find $src -name 'test-*.std' | sed -e 's%.*/\([^/]*\)%\1%' -`

# Install files.
#
install=$bld_root/install/install

$install -d -m 755 $out

for i in $cxx $hxx $ixx; do
  $install -p -m 644 $src/$i $out/$i
done

for i in $xsd; do
  $install -p -m 644 $src/$i $out/$i

  # See if we have a map file for this schema.
  #
  m=`echo $i | sed -e 's%\.xsd%.map%' -`
  if [ -f "$src/$m" ]; then
    $install -p -m 644 $src/$m $out/$m
  fi
done

for i in $xml; do
  $install -p -m 644 $src/$i $out/$i
done

for i in $std; do
  $install -p -m 644 $src/$i $out/$i
done

# Generate the makefile.
#
rm -f $out/makefile

gen "root := $root"
gen
gen 'include $(root)/build/cxx/rules.make'
gen
gen 'EXTRA_CPPFLAGS := -I$(root)/libxsde'
gen

if [ "$lib" != "" ]; then
  s=`echo $lib | sed -e 's/\([^ ]*\)/-l\1/g' -`
  gen "override LIBS += $s"
  gen
fi

gen 'ifeq ($(XSDE_STL),n)'
gen 'EXTRA_XSDFLAGS += --no-stl'
gen 'endif'
gen
gen 'ifeq ($(XSDE_IOSTREAM),n)'
gen 'EXTRA_XSDFLAGS += --no-iostream'
gen 'endif'
gen
gen 'ifeq ($(XSDE_EXCEPTIONS),n)'
gen 'EXTRA_XSDFLAGS += --no-exceptions'
gen 'endif'
gen
gen 'ifeq ($(XSDE_LONGLONG),n)'
gen 'EXTRA_XSDFLAGS += --no-long-long'
gen 'endif'
gen
gen 'ifeq ($(XSDE_PARSER_VALIDATION),n)'
gen 'EXTRA_XSDFLAGS += --suppress-parser-val'
gen 'endif'
gen
gen 'ifeq ($(XSDE_SERIALIZER_VALIDATION),n)'
gen 'EXTRA_XSDFLAGS += --suppress-serializer-val'
gen 'endif'
gen
gen 'ifeq ($(XSDE_REUSE_STYLE),mixin)'
gen 'EXTRA_XSDFLAGS += --reuse-style-mixin'
gen 'endif'
gen
gen 'ifeq ($(XSDE_POLYMORPHIC),y)'
gen 'EXTRA_XSDFLAGS += --runtime-polymorphic'
gen 'endif'
gen
gen "$driver: $obj" '$(root)/libxsde/xsde/libxsde.a'
gen

for i in $cxx; do
  o=`echo $i | sed -e 's%\.cxx%.o%' -`
  gen "$o: $i $gen_hxx"
done

for i in $gen_cxx; do
  o=`echo $i | sed -e 's%\.cxx%.o%' -`
  gen "$o: $i"
done

gen

if [ "$xsd" != "" ]; then
gen ".PRECIOUS: $pat"
gen "$pat: %.xsd"
gen '\t$(root)/bin/xsde' $cmd '$(XSDFLAGS) $(EXTRA_XSDFLAGS)' $opt '$<'
gen
fi

gen '.PHONY: test'
gen "test: $driver"
if [ "$xml" = "" ]; then
  if [ "$std" = "" ]; then
    # Simple return value test.
    #
    gen "\t./$driver"
  else
    # Test with result comparison.
    #
    gen "\t./$driver | diff -u $std -"
  fi
else
  for i in $xml; do
    if [ "$std" = "" ]; then
      # Return value test with argument.
      #
      gen "\t./$driver $i"
    else
      # Test with argument and result comparison.
      #
      s=`echo $i | sed -e 's%\.xml%.std%' -`
      gen "\t./$driver $i | diff -u $s -"
    fi
  done
fi

gen

gen '.PHONY: clean'
gen 'clean:'
gen "\trm -f $driver $obj $gen_cxx $gen_ixx $gen_hxx"
gen