[runtime] Build stripper and use with mkbundle
[mono.git] / mcs / build / gensources.sh
1 #! /bin/sh
2
3 outfile=$1
4 incfile=$2
5 excfile=$3
6 extfile=$4
7 extexcfile=$5
8
9 process_includes_1() {
10     sed -e '/^[ \t]*$/d' -e '/^[ \t]*#/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
20     fi
21 }
22
23 process_includes() {
24     i=$1; o=$2; t=${2}.tmp
25     while process_includes_1 $i $o; do
26         mv $o $t
27         i=$t
28     done
29     rm -f $t
30 }
31
32 check_newline_eof() {
33         file=$1
34         if ! test -f "$file"; then return; fi
35         if ! test -z "$(tail -c 1 "$file")"; then echo "$file: missing newline at end of file."; exit 1; fi
36 }
37
38 check_newline_eof $incfile
39 check_newline_eof $excfile
40 check_newline_eof $extfile
41 check_newline_eof $extexcfile
42
43 rm -f $outfile.makefrag
44
45 process_includes $incfile $outfile.inc
46
47 if test x$extfile != x -a -f "$extfile"; then
48         process_includes $extfile $outfile.ext.inc
49         cat $outfile.ext.inc >> $outfile.inc
50         rm -f $outfile.ext.inc
51 fi
52
53 sort -u $outfile.inc > $outfile.inc_s
54 rm -f $outfile.inc
55
56
57 if test -n "$excfile" -a -f "$excfile"; then
58     process_includes $excfile $outfile.exc
59 fi
60
61 if test -n "$extexcfile"; then
62     process_includes $extexcfile $outfile.ext_exc
63         cat $outfile.ext_exc >> $outfile.exc
64         rm -f $outfile.ext_exc
65 fi
66
67 if test -f $outfile.exc; then
68         # So what we're doing below with uniq -u is that we take 
69         # lines that have not been duplicated. This computes the 
70         # symmetric difference between the files. This is not
71         # what we want. If a file is in the excludes but not in
72         # the sources, we want that file not to show up. By duplicating the
73         # excludes, we ensure that we won't end up in this failure state.
74         sort -u $outfile.exc > $outfile.exc_s
75
76         # Duplicate excludes
77         cat $outfile.exc_s >> $outfile.exc_s_dup
78         cat $outfile.exc_s >> $outfile.exc_s_dup
79
80         rm -f $outfile.exc $outfile.exc_s
81
82         cat $outfile.inc_s $outfile.exc_s_dup | sort | uniq -u > $outfile
83         rm -f $outfile.inc_s $outfile.exc_s_dup
84 else
85         mv $outfile.inc_s $outfile
86 fi
87
88