[corlib] corefx tests from System.Threading.* and System.Text.RegularExpressions...
[mono-project.git] / mcs / build / gensources.sh
blob0163ec146efe7760b4f8e6d497cfcfc3c8ee1e45
1 #! /bin/sh
3 outfile=$1
4 incfile=$2
5 excfile=$3
6 extfile=$4
7 extexcfile=$5
9 process_includes_1() {
10 sed -e '/^[ \t]*$/d' -e '/^[ \t]*#/d' -e '/*/d' $1 > $2
11 if cmp -s $1 $2; then
12 false
13 else
14 sed -n 's,^[ \t]*#include ,,p' $1 |
15 while read inc; do
16 cat $inc >> $2
17 echo $outfile: $inc >> $outfile.makefrag
18 echo $inc: >> $outfile.makefrag
19 done
21 # expand wildcards
22 sed -n '/*/p' $1 | grep -v '#' |
23 while read wildc; do
24 # quick syntax to exclude files:
25 # ../../../MyDir/*.cs:FileToExclude1.cs,FileToExclude2.cs
26 wc=`echo $wildc | cut -d \: -f 1` # ../../../MyDir/*.cs
27 qexc=`echo $wildc | cut -d \: -f 2` # FileToExclude1.cs,FileToExclude2.cs
29 if test "$wc" = "$qexc"; then
30 # no quick excludes - just expand the wildcard
31 ls $wildc >> $2
32 else
33 wcdir=`echo $wildc | cut -d \* -f 1` # ../../../MyDir/
34 # Enumerate files from 'FileToExclude1.cs,FileToExclude2.cs'
35 # and save to $outfile.exc
36 oldIFS=$IFS
37 IFS=,
38 for i in $qexc; do
39 echo "$wcdir$i" >> $outfile.exc
40 done
41 IFS=$oldIFS
42 ls $wc >> $2
44 done
48 process_includes() {
49 i=$1; o=$2; t=${2}.tmp
50 while process_includes_1 $i $o; do
51 mv $o $t
52 i=$t
53 done
54 rm -f $t
57 check_newline_eof() {
58 file=$1
59 if ! test -f "$file"; then return; fi
60 if ! test -z "$(tail -c 1 "$file")"; then echo "$file: missing newline at end of file."; exit 1; fi
63 check_newline_eof $incfile
64 check_newline_eof $excfile
65 check_newline_eof $extfile
66 check_newline_eof $extexcfile
68 rm -f $outfile.makefrag
70 process_includes $incfile $outfile.inc
72 if test x$extfile != x -a -f "$extfile"; then
73 process_includes $extfile $outfile.ext.inc
74 cat $outfile.ext.inc >> $outfile.inc
75 rm -f $outfile.ext.inc
78 sort -u $outfile.inc > $outfile.inc_s
79 rm -f $outfile.inc
82 if test -n "$excfile" -a -f "$excfile"; then
83 process_includes $excfile $outfile.exc
86 if test -n "$extexcfile"; then
87 process_includes $extexcfile $outfile.ext_exc
88 cat $outfile.ext_exc >> $outfile.exc
89 rm -f $outfile.ext_exc
92 if test -f $outfile.exc; then
93 # So what we're doing below with uniq -u is that we take
94 # lines that have not been duplicated. This computes the
95 # symmetric difference between the files. This is not
96 # what we want. If a file is in the excludes but not in
97 # the sources, we want that file not to show up. By duplicating the
98 # excludes, we ensure that we won't end up in this failure state.
99 sort -u $outfile.exc > $outfile.exc_s
101 # Duplicate excludes
102 cat $outfile.exc_s >> $outfile.exc_s_dup
103 cat $outfile.exc_s >> $outfile.exc_s_dup
105 rm -f $outfile.exc $outfile.exc_s
107 cat $outfile.inc_s $outfile.exc_s_dup | sort | uniq -u > $outfile
108 rm -f $outfile.inc_s $outfile.exc_s_dup
109 else
110 mv $outfile.inc_s $outfile