2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / tools / gensources.sh
1 #!/usr/bin/env bash
2
3 includefile=$1
4 excludefile=$2
5
6 ## input variables:
7 ##      $filelist:
8 ##              A colon (':') separated list of files already read.
9 ##              Must be initialized to ":".
10 ##      $excludelist:
11 ##              A newline separated of element (support Shell Patterns) to exclude.
12 ##      $separator:
13 ##              The separator used in list for the output
14 ##      
15 ## output variables:
16 ##      $list:
17 ##              A list of elements separated by the separator given in $separator.
18 ##              The new elements will be appended to the list.
19 readlist () {
20         local onelist
21         local onelistcontent
22         onelist=$1
23
24         if [ ":$onelist:" = "::" ] ; then return ; fi
25         if [ ! -f $onelist ] ; then return ; fi
26         if [ ":${filelist##*:$onelist:*}:" = "::" ]  ; then return ; fi
27         filelist=":$onelist$filelist"
28
29         onelistcontent=`cat $onelist | sed "s=[ \t]*$==g" | while read line ; do echo -n $line ; echo -n ":" ; done`
30
31         OFS="$IFS"
32         IFS=":"
33         for line in $onelistcontent ; do
34                 line2=${line##\#}
35                 if [ ":$line:" = ":$line2:" ] ; then
36                         for linex in $excludelist ; do
37                                 if [ ":${line##$linex}:" = "::" ] ; then line="" ; fi
38                         done
39                         if [ ":$line:" != "::" ] ; then
40                                 if [ ":$list:" = "::" ] ; then
41                                         list="$line"
42                                 else
43                                         list="$list$separator$line"
44                                 fi
45                         fi
46                 else
47                         line3=${line2##include }
48                         if [ ":$line3:" != ":$line2:" -a ":$line3:" != "::" ] ; then
49                                 readlist "$line3"
50                         fi
51                 fi
52         done
53         IFS="$OFS"
54 }
55
56 list=""
57 filelist=":"
58 excludelist=""
59 separator=":"
60 readlist "$excludefile"
61
62 excludelist="$list"
63 list=""
64 filelist=":"
65 separator="
66 "
67 readlist "$includefile"
68 echo "$list" | sort | uniq